Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize WeChat Pay in the Development of Wechat

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to realize WeChat Pay in the development of Wechat. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Wechat backend settings

1. Add test authorization directory and test whitelist:

In the Wechat background, set up the test authorization directory, such as adding your WeChat account to the whitelist of xxx.sinaapp.com/example/, test.

Note that the "personal WeChat account" here is neither a qq account nor a personal nickname. It's the string in the WeChat account field in the "I" interface after logging in to Wechat.

It doesn't matter whether the payment authorization directory is set or not, because we are just testing.

two。 List content

Set the web page authorization domain name:

Set it in "developer Center / Interface permission Table / Web account / Web Authorization to obtain basic user Information". The authorized domain name of the web page is set to the domain name of the test server, such as xxx.sinaapp.com, and http:// is not required.

Second, merchant platform setting

1. Download certificate

Download it in account Settings / API Security / API Certificate. Need to use the administrator's cell phone verification code. After downloading and decompressing, we need to use apiclient_key.pem and apiclient_cert.pem.

two。 Generate payment key

Set it in account Settings / API Security / API key. The payment key will be used when paying, and this value is the KEY constant in the source code configuration file.

Third, use the sample code of official V3.7

1. Modify the configuration in Wxpay.pub.config.php, mainly as follows:

The AppID const MCHID / / WeChat Pay merchant information seen by the "developer Center" in the official account const APPID / / the merchant number const KEY / / the payment key const APPSECRET / / seen by the "developer Center" in the official account you set up on the merchant platform _ CALL_URL / / set this url You can get the user's openid on this page. / / Certificate path. Note that you should enter the absolute path const SSLCERT_PATH / / apiclient_cert.pem file url const SSLKEY_PATH / / apiclient_key.pem file url, such as'/ cert/ apiclient_key.pem' const NOTIFY_URL / / Asynchronous Notification url. You can use notify_url.php in demo.

2. Modify the bug in the official code:

If the "curl_setopt () expects parameter 2 to be long" error occurs, it is because there are several places in the WxPayPubHelper.php where the word "curl_setopt" is misspelled into "curl_setop" and can be modified. If "curl_close (): 11 is not a valid" appears, it is because a closed curl session has been closed incorrectly, so you can add the following judgment to the curl_close () code:

If (gettype ($ch) = = 'resource') curl_close ($ch)

3. The official demo can't get through directly, so we need to take care of it ourselves. First, add a link to index.php:

Get openid

3. Then write a pay.php page to obtain the user's openid and initiate payment:

Wechat secure payment / / call Wechat JS api pay function jsApiCall () {WeixinJSBridge.invoke ('getBrandWCPayRequest', function (res) {WeixinJSBridge.log (res.err_msg); / / alert (res.err_code+res.err_desc+res.err_msg);});} function callpay () {if (typeof WeixinJSBridge = = "undefined") {if (document.addEventListener) {document.addEventListener (' WeixinJSBridgeReady', jsApiCall, false) } else if (document.attachEvent) {document.attachEvent ('WeixinJSBridgeReady', jsApiCall); document.attachEvent (' onWeixinJSBridgeReady', jsApiCall);}} else {jsApiCall ();}}

OpenID Product name order No. Prepay_id Price

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report