The PC website is realized through the WeChat scan code payment server

Reference for payment application instructions: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=3_1

 

WeChat scan code payment can be divided into two modes. In this example, the second mode is selected. For the specific process and API documentation, please refer to:

https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5

 

The following only describes the implementation of the server, which mainly includes two parts:

1. Generate internal order information according to the client's request, and then call the WeChat unified order API to get the prepaid transaction link (QR code picture address) and return it to the client

 

Please refer to the previous article: Wechat Web Development - Official Account Payment

 

1. The front-end H5 page requests the server to generate a unique order number (including user information, payment amount, product information, etc.), and the server creates a new record in the database

2. The front-end H5 page requests the server-side Perl CGI script for payment: For example, https:/xxxx/cgi-bin/pay.pl?do=qrcodepay&order_id=xxxxxxx&openid=xxxxxx

 

////Script processing

if ($cgi->param('do') eq "qrcodepay") {

}

 

3. The CGI script calls the interface to access the database, obtain payment record information, and call the WeChat unified order interface

https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1

 

Several parameters that differ from H5 official account payment are as follows:

if ($qrcode) {#PC scan code payment

    $PayInfo->{service}= "pay.weixin.native";

 

} else {#The payment in the official account must pass the sub_openid

    $PayInfo->{sub_openid} = $openid;

    $PayInfo->{service}= "pay.weixin.jspay";

}

 

4. After the server gets the QR code link code_url and code_img_url, the CGI redirects to the page specified by H5, and the client displays the QR code to the user

my $redirect_url = "http://xxxx/recharge_pay.html?order_id=$order_id&RMB=$order_info->{rmb}&code_url=$code_url&code_img_url=$code_img_url";

print $cgi->redirect($redirect_url);

 

2. After the user scans the code to pay, the WeChat server notifies the payment result to the callback address specified by notify_url

 

*3. How to notify the front-end (PC-side) page to refresh after the payment is successful?

Method 1: You can access a certain interface of the server regularly, and obtain the payment status according to the order number

 

Method 2. If the communication protocol between the client and the server supports a long connection, such as websocket, then after the server receives the notify notification from the WeChat server, it can push the message to the client to let the client refresh the page.

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326163624&siteId=291194637