其他分享
首页 > 其他分享> > 第四方 fast快捷支付封装

第四方 fast快捷支付封装

作者:互联网

 1 class Fastpay {
 2     protected $conf = [
 3         'appkey'=>'',//appkey
 4         'key'=>'',//秘钥
 5     ];
 6     protected $http_type='http';
 7 
 8     public function __construct($payInfo=[]){
 9         if($payInfo)
10         {
11            foreach ($payInfo as $field => $val) {
12                 $this->config[$field]=$val['val'];
13             } 
14         }
15     }
16     public function index($data)
17     {
18         $data = array(
19             'appkey'=>$this->config['appkey'],//你的appkey
20             'uid'=>$data['attach'],//你的用户id
21             'total_fee'=>$data['total'],//你的金额
22             'order_no'=>$data['pay_sn'],//你的订单号
23             'pay_title'=>$data['subject'],//你的订单号
24             'me_param'=>$data['attach'],//其他参数,可返回回调里面
25             'notify_url'=>$data['notify_url'],//异步回调地址
26             'me_back_url'=>$data['return_url'],//支付成功后返回
27             'me_eshop_openid'=>'',//付款用户openid
28             'me_party'=>'',//根据其他支付插件,异步回调返回同样参数,比如填写codepay,码支付,我们异步回调的时候就按码支付的回调参数返回
29             'sign'=>''//签名
30         );
31         $checkRes=$this->checkData($data);
32         if($checkRes['code']==0)
33         {
34             return $checkRes;
35         }
36         $data=$checkRes['data'];
37         $url_quer=http_build_query($data);
38         $url=($this->http_type=='https') ? "/fastpay/fpay/pays.php?{$url_quer}" : "/fastpay/fpay/pay.php?{$url_quer}" ;
39         return ['code'=>1,'msg'=>'success','data'=>['payurl'=>$url]];
40     }
41 
42     // 检测数据
43     public function checkData($data)
44     {
45         extract($data);
46         if (empty($appkey)) {
47             return ['code'=>0,'msg'=>'appkey没有填写'];
48         }
49         if (empty($total_fee)) {
50             return ['code'=>0,'msg'=>'金额不能为空'];
51         }
52         if (empty($uid)) {
53             return ['code'=>0,'msg'=>'付款用户id不能为空'];
54         }
55         if (empty($order_no)) {
56             return ['code'=>0,'msg'=>'请输入支付编号'];
57         }
58         if (!empty($me_back_url)) {
59             $data['me_back_url']=urlencode($me_back_url);
60         }
61         if (!empty($notify_url)) {
62             $data['notify_url']=urlencode($notify_url);
63         }
64 
65         // 直接将金额精确到两位数
66         $data['total_fee']=bcadd($total_fee, 0, 2);
67         if (empty($sign)) {
68             $data['sign']=$this->pay_sign($data);
69         }
70 
71         return ['code'=>1,'msg'=>'success','data'=>$data];
72     }
73 
74     //支付下单计算签名
75     public function pay_sign($paydata)
76     {
77         $str_sign="appkey={$paydata['appkey']}&order_no={$paydata['order_no']}&secretkey=".$this->config['key']."&total_fee={$paydata['total_fee']}&uid={$paydata['uid']}&";
78         $sign=md5($str_sign);
79         return $sign;
80     }
81 
82     function notify_sign($paydata)
83     {
84         $str_sign="appkey={$paydata['appkey']}&order_no={$paydata['order_no']}&secretkey=".SECRET_KEY."&me_pri={$paydata['me_pri']}&uid={$paydata['uid']}&";
85         $sign=md5($str_sign);
86         return $sign;
87     }
88     
89 }

 

标签:appkey,封装,第四方,url,paydata,fast,sign,return,data
来源: https://www.cnblogs.com/exo5/p/13572641.html