站长论坛

标题: 分享给大家网银支付封装类! [打印本页]

作者: webptr    时间: 2007-10-5 11:30
标题: 分享给大家网银支付封装类!
  1. <?php
  2. /*
  3. +-----------------------------------------------------------------------+
  4. | 作者: 一天空一
  5. | Q Q: 31769416,[url=http://www.176k.cn]www.176k.cn[/url]
  6. | 时间:2006-12-16
  7. | 功能:网银在线支付接口封装类(2.0)                                             
  8. +-----------------------------------------------------------------------+
  9. */
  10. class Chinabank
  11. {
  12.         //发送参数
  13.         private $v_mid;                  // 商户号
  14.         private $v_url;                 //返回url
  15.         private $key;                   //密钥
  16.         public  $v_amount;             //支付金额
  17.         private $v_m;  //支付币种
  18.         private $v_md5info;           //md5加密后的字符串
  19.         public  $remark1;             //备注字段1
  20.         public  $remark2;            //备注字段2
  21.         public  $v_oid;              //定单号
  22.         //接收参数
  23.         private $v_pmode;           // 支付方式(字符串)
  24.         private $v_pstatus;        // 支付状态 :20(支付成功);30(支付失败)
  25.         private $v_pstring;       // 支付结果信息
  26.         private $v_md5str;       //返回后的md5
  27.         
  28.         function __construct($v_mid,$v_url,$key)
  29.         {
  30.                  $this->v_mid = $v_mid;
  31.                  $this->v_url = $v_url;
  32.                  $this->key   = $key;
  33.         }
  34.         
  35.         /*设置支付金额*/
  36.         public function  amount($amount=0)
  37.         {
  38.                 $this->v_amount=floatval($amount);
  39.         }
  40.         
  41.         /*设置备注*/
  42.         public function  memol($memo1="",$memo2="")
  43.         {
  44.                 $this->remark1=$memo1;
  45.                 $this->remark2=$memo2;
  46.         }
  47.         
  48.         /*生成发送校验码*/
  49.         private  function send_verify()
  50.         {
  51.                  $this->v_oid=date('Ymd',time())."-".$this->v_mid."-".date('His',time());
  52.                  $text=$this->v_amount.$this->v_moneytype.$this->v_oid.$this->v_mid.$this->v_url.$this->key;
  53.                 $this->v_md5info=strtoupper(trim(md5($text)));
  54.                 $this->v_md5info=strtoupper(trim(md5($text)));        
  55.         }
  56.         
  57.         /*生成接收校验码*/
  58.         private function incept_verify()
  59.         {
  60.                 $text=$this->v_oid.$this->v_pstatus.$this->v_amount.$this->v_moneytype.$this->key;
  61.                 return strtoupper(trim(md5($text)));
  62.         }
  63.         
  64.         /*提交支付请求*/
  65.         public function pay_send()        
  66.         {
  67.                 $this->send_verify();
  68.                 $result="
  69.                                 
  70.                                 v_md5info}'>
  71.                                 v_mid}'>
  72.                                 v_oid}'>
  73.                                 v_amount}'>
  74.                                 v_moneytype}'>
  75.                                 v_url}'>
  76.                                 remark1}'>
  77.                                 remark2}'>
  78.                                 
  79.                                 re.submit();
  80.                                 ";
  81.                 $result=trim($result);
  82.                 echo $result;
  83.         }
  84.         
  85.         /*提交返回处理*/
  86.         public function pay_receive()
  87.         {
  88.                 $this->v_oid = trim($_POST['v_oid']);
  89.                 $this->v_pmode = trim($_POST['v_pmode']);
  90.                 $this->v_pstatus = trim($_POST['v_pstatus']);
  91.                 $this->v_pstring = trim($_POST['v_pstring']);
  92.                 $this->v_amount = trim($_POST['v_amount']);
  93.                 $this->v_moneytype = trim($_POST['v_moneytype']);
  94.                 $this->remark1 = trim($_POST['remark1']);
  95.                 $this->remark2 = trim($_POST['remark2']);
  96.                 $this->v_md5str = trim($_POST['v_md5str']);
  97.         }
  98.         
  99.         /*判断返回是否有效信息*/
  100.         public function check_pay_receive()        
  101.         {
  102.                 if ($this->v_md5str==$this->incept_verify()) {
  103.                         return true;
  104.                 } else         {
  105.                         return false;
  106.                 }
  107.         }
  108.         
  109.         /*判断返回是否提交成功*/
  110.         public function check_pay()        
  111.         {
  112.                 if($this->v_pstatus=='20'){
  113.                         return true;
  114.                 } else {
  115.                         return false;
  116.                 }
  117.         }
  118.         
  119. }
  120. ?>
复制代码
  1. 调用:
  2. 发送:
  3.                   $pay_num =0.01;
  4.                   $v_mid = 1234578995 ;
  5.                   $v_url = "http://59.57.64.168/zl/index.php/Block/disposal";
  6.                   $key  = '#$%%45454235243&*';
  7.                   $pay = new Chinabank($v_mid,$v_url,$key);
  8.                   $pay->amount($pay_num);
  9.                   $pay->pay_send();
复制代码
  1. 返回处理
  2.                   $v_mid = 1234578995 ;
  3.                   $v_url = "http://59.57.64.168/zl/index.php/Block/disposal";
  4.                   $key  = '#$%%45454235243&*';
  5.                   $pay = new Chinabank($v_mid,$v_url,$key);
  6.                   $pay->pay_receive();
  7.                               if ($pay->check_pay_receive()) {
  8.                                         if ($pay->check_pay()) {
  9.                                              //成功处理..
  10.                                            } esle {
  11.                                               echo "支付流程出现问题";
  12.                                            }
  13.                                  
  14.                                   }else {
  15.                   echo  'Md5校验码错误";
  16.                   }
复制代码





欢迎光临 站长论坛 (https://tzlink.com/bbs/) Powered by Discuz! X3.2