Quickly connect to payjq's personal WeChat payment interface (cashier mode)
payjq
payjq 2019-07-28 14:02:04
0
0
963

I am learning about the personal payment interface recently, hoping to solve my payment problem on WeChat. After comparing many platforms, I feel that [payjq](https://payjq.cn) is more professional. It supports both Alipay and WeChat. Since I have not yet activated Alipay (it requires a certain amount of traffic to activate it), this article focuses on the integration of WeChat cashier mode. Record it.

The docking of the cashier mode is actually very simple. There is an official development kit that can be used directly, or it is relatively simple to develop it yourself.

1. Individual implementation through code

1. Configure merchant number and communication key

$mchid = '**************'; // PAYJQ 商户号 $key = '**************'; // 通信密钥

2. Construct order

// 构造订单参数 $data = [ 'mchid' => $mchid, 'body' => '我是一个测试订单标题', 'total_fee' => 1, 'out_trade_no' => 'payjq_jspay_demo_' . time(), ];

3. Signature algorithm

// 获取签名 function sign($data, $key) { array_filter($data); ksort($data); return strtoupper(md5(urldecode(http_build_query($data) . '&key=' . $key))); }


4. Order data signature

// 添加数据签名 $data['sign'] = sign($data, $key);

5. Browser jump

// 浏览器跳转到收银台 $url = 'https://payjq.cn/api/cashier?' . http_build_query($data); header('Location: ' . $url);

6 , all steps have been completed. Payment can be initiated normally

7. It is important to remind that the last step of browser jump needs to be initiated through the browser and cannot be initiated after obtaining the back-end code

2. Processing of asynchronous notifications

For example, my domain name is http://www.xxx.cn, and the url for receiving asynchronous notifications is http://www.xxx.cn/payjq/notify. PHP only needs to add the following fields when constructing the order

// 构造订单参数 $data = [ 'mchid' => $mchid, 'body' => '我是一个测试订单标题', 'total_fee' => 1, 'out_trade_no' => 'payjq_jspay_demo_' . time(), 'notify_url' => 'http://www.xxx.cn/payjq/notify.php', ];

In this way, after the user's payment is completed, my server can receive an asynchronous notification. After testing, the arrival time of the asynchronous notification is generally received within 1 second, and no delay is felt. It’s just that when I’m polling on the front end, the frequency of polling once every three seconds is relatively low.

The whole process is still very simple. If you have any questions, you can ask them at any time.

The next article will introduce the jsapi mode payment, which is more perfect to use and suitable for students with development capabilities

payjq
payjq

reply all (0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!