第三方四方支付接口对接开发教程API集成服务通用方法 - QQ4770851

时间:2024-02-17 17:58:15

第三方四方支付接口对接开发教程API集成服务通用方法

支付接口对接技术做多了以后你会发现,基本上所有的第三方第四方支付接口的基本方法流程就是这样,至于有些签名方式不一样,配制参数不一样等等按照其提供的技术文档要求修改一下即可,有不懂的可以联系。

 1 //配制类,填写在支付平台获取的相关信息Q4770851
 2 class Constant {
 3     const USER= "QQ4770851";
 4     const MERCHNO = "ff8080816586cbd434358a66b0bc1525";
 5     const CREATE_URL = "https://xxx.com/order/create";
 6     const QUERY_URL = "https://xxx.com/order/query";
 7     const KEY = "C66604323DFA42B4864299246E04FD1B";
 8 
 9 }
10 //签名类,按照支付平台的规则对参数进行签名
11 class SignUtils {
12     /** = */
13     const QSTRING_EQUAL = "=";
14     /** & */
15     const QSTRING_SPLIT = "&";
16     public static function signMD5($param, $merKey = \'\') {
17         ksort($param);
18 
19         $arr = [];
20         foreach ($param as $key => $value) {
21             $arr[] = $key . self::QSTRING_EQUAL . $value;
22         }
23         $str = implode(self::QSTRING_SPLIT, $arr);
24         return strtoupper(md5($str . self::QSTRING_SPLIT . $merKey));
25     }
26 }
27 
28 //请求类,发起支付请求
29 class HttpUtils {
30     /**
31      * [post description]
32      * @param  [type] $url  [description]
33      * @param  array  $post [description]
34      * @return [type]       [description]
35      */
36     public static function post($url, $post = []) {
37         $headers = [ "Content-type: application/json;charset=\'utf-8\'", "Accept: application/json", "Cache-Control: no-cache", "Pragma: no-cache" ];
38         $ch = curl_init($url);
39         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
40         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
41         curl_setopt($ch, CURLOPT_TIMEOUT, 60);
42         curl_setopt($ch, CURLOPT_POST, TRUE);
43         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
44         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
45         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
46 
47         $data = curl_exec($ch);//CURLOPT_RETURNTRANSFER 不设置  curl_exec返回TRUE 设置  curl_exec返回json(此处) 失败都返回FALSE
48         curl_close($ch);
49 
50         return $data;
51     }
52 }
53 
54 // 支付正文开始,配制参数,发起请求
55 $param = [];
56 $param[\'merchno\'] = Constant::MERCHNO;
57 $param[\'out_trade_no\'] = $_POST[\'rechargeId\'];
58 $param[\'subject\'] = $_POST[\'username\'];
59 $param[\'total_amount\'] = $_POST[\'amount\'];
60 $param[\'redirect_url\'] = \'http://\'.$_SERVER[\'HTTP_HOST\'].\'/return.php\';
61 $param[\'notify_url\'] = \'http://\'.$_SERVER[\'HTTP_HOST\'].\'/notify.php\';
62 $param[\'sign\'] = SignUtils::signMD5($param, Constant::KEY);
63 $response = HttpUtils::post(Constant::CREATE_URL, $param);
64 $arr = json_decode($response,TRUE);
65 header("location:".$arr[\'pay_url\']);
66 --------------------- 
67 作者:jeesr 
68 来源:CSDN 
69 原文:https://blog.csdn.net/jeesr/article/details/90639283 
70 版权声明:本文为博主原创文章,转载请附上博文链接!