Bookmark and Share

Lee's 程序人生

HTML CSS Javascript XML AJAX ATLAS C# C++ 数据结构 软件工程 设计模式 asp.net Java 数字图象处理 Sql 数据库
  博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

分享给大家网银支付封装类!

Posted on 2008-07-21 22:24  analyzer  阅读(453)  评论(0编辑  收藏  举报
  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*/
 10class 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                                <FORM  name=re METHOD=post ACTION='https://pay.chinabank.com.cn/select_bank'>
 70                                <input type='hidden' name='v_md5info' value='{$this->v_md5info}'>
 71                                <input type='hidden' name='v_mid' value='{$this->v_mid}'>
 72                                <input type='hidden' name='v_oid' value='{$this->v_oid}'>
 73                                <input type='hidden' name='v_amount' value='{$this->v_amount}'>
 74                                <input type='hidden' name='v_moneytype'  value='{$this->v_moneytype}'>
 75                                <input type='hidden' name='v_url' value='{$this->v_url}'>
 76                                <input type='hidden' name='remark1' value='{$this->remark1}'>
 77                                <input type='hidden' name='remark2' value='{$this->remark2}'>
 78                                </FORM>
 79                                <SCRIPT>re.submit();</SCRIPT>
 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                  }
我要啦免费统计