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

Methods and steps of connecting with WeChat Pay

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

Share

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

This article mainly introduces "the methods and steps of accessing WeChat Pay". In the daily operation, I believe that many people have doubts about the methods and steps of accessing WeChat Pay. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about the methods and steps of accessing WeChat Pay! Next, please follow the editor to study!

First, the prerequisite of WeChat Pay is 1.1 official account.

In general, Wechat official account can be divided into service number and Subscription account. The specific difference between Subscription account and service number is introduced in a previous article Spring Boot development Wechat official account, so I won't repeat it here. Generally speaking, the service number provides more advanced functions.

WeChat Pay needs a service number that has completed Wechat verification. If it is Mini Program, you also need to complete Wechat certification.

The official account can be associated with 10 Mini Program of the same subject and 3 Mini Program of different subjects. If it is the Mini Program of the same subject as the official account and the official account has completed authentication, it can be quickly registered and verified in the Mini Program management at the backend of the official account, so that there is no need to repeatedly pay for the 300RMB required for Wechat verification.

1.2 Wechat Merchant platform

After Wechat authentication is completed, WeChat Pay function will be activated in WeChat Pay in the backstage of the official account. After submitting WeChat Pay's application, a review will be conducted within 3-5 working days. After the examination and approval, an email containing the merchant number information will be sent to the mailbox you filled in, and a remittance of a few cents will be transferred to the public account you filled in. You need to check the specific amount and verify it in the merchant platform.

Merchants are divided into ordinary merchants and service providers, so don't make a mistake.

Ordinary merchants can trade, but they cannot expand them.

Service providers can expand merchants, but they cannot trade.

The service provider is to provide a unified payment entry, which needs to be bound to a specific ordinary merchant. WeChat Pay will carry ordinary merchant parameters in the payment interface, and after successful payment, the amount will be directly to the specific ordinary merchant account.

When you apply, you can apply directly to ordinary merchants.

1.3 bind merchants

WeChat Pay's initiative relies on the binding relationship between official accounts, Mini Program and other applications and merchant numbers. Therefore, before the development, the merchant needs to be bound with the specific application.

If the merchant and the AppID to be bound are the same principal, you only need the following steps to complete the binding.

Associate AppID in merchant platform-Product Center-AppID account management, and enter AppId to apply for binding.

Confirm in the official account or Mini Program backstage WeChat Pay-merchant account management.

If the merchant and the AppID to be bound are different principals, the steps are the same as above. Besides entering AppId, you also need to enter the authentication information of AppId.

Second, WeChat Pay related configuration 2.1 payment product types

1. Payment code payment

The user opens the Wechat wallet-payment code interface, and the merchant scans the code and submits to complete the payment.

2. JSAPI payment

Users scan the code on Wechat, follow the official account and other ways to enter the merchant H5 page, and call JSSDK in Wechat to complete the payment.

3. Native payment

Users open Wechat to scan, scan the merchant's QR code and complete the payment.

4. APP payment

Wechat SDK is integrated into the merchant APP. Users click and jump to Wechat to complete the payment.

5. H5 payment

The scene of users requesting WeChat Pay in a mobile browser other than Wechat evokes WeChat Pay.

6. Mini Program payment

Users use the scene of WeChat Pay in WeChat Mini Programs.

7. Facial scan payment

No need to pull out the phone, facial scanning to complete the payment, suitable for all kinds of offline scenes.

Apply for payment products in merchant platform-product center-my product.

2.2 payment Authorization Directory configuration

Configure the payment authorization directory in the merchant platform-product center-development configuration (that is, the address of the order issuing interface you developed). It should be noted that a maximum of five authorization directories can be configured. Please define the payment interface reasonably during the development process.

2.3 configure Merchant key

Set the API key in merchant platform-account center-API security.

The first time to set up, need to install the operation certificate, stupid installation, follow the prompts to operate step by step.

The API key requires a 32-bit random string, so remember not to change the API key at will.

In the Wechat APIv3 version, in addition to configuring the API key, you also need to configure the APIv3 key and apply for an API certificate issued by CA.

API v3 key is mainly used for decryption of platform certificate and callback information.

API certificate is used to call a higher-level api API, including refund, red packet and other APIs.

If you are using the open source Wechat package, please know if v3 is supported.

2.4 configure the server

Enable and fill in the server information in the official account backend-Development-basic configuration-Server configuration.

2.5 whitelist configuration

Configure the developer key in the official account backend-Development-basic configuration-official account development information, and fill in the IP whitelist.

2.6 JS interface security domain name

Set the JS API security domain name in the official account backend-official account Settings-function Settings.

The above configuration is based on the official account payment configuration, Mini Program pay is not so troublesome, Mini Program pay does not need to configure payment authorization directory and authorized domain name.

JSAPI Mini Program payment Protocol HTTP/HTTPSHTTPS payment directory with or without authorized domain name 3. WeChat Pay process

Because Wechat has upgraded the API API, you need to load the applied API certificate in API API v3. Wechat has encapsulated the relevant jar package and provided a loading example. For more information, please see "https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_3.shtml"". Let's take API v2 as an example to learn in detail the main process of Wechat access (because some interfaces of API v3 are still being upgraded, and the v2 interface is relatively complete).

The above picture is from the Wechat development document, let's analyze the payment process in detail.

3.1API for Wechat to place an order

The user initiates the payment through the Wechat client, generates the order at the merchant's backend, and then calls the Wechat API to issue the order to generate a prepaid order and return the order number!

The main parameters involved in the API for placing an order. Only a few important parameters are listed:

Whether the request parameter is required type description appid is String official number appidmch_id is String merchant number nonce_str is String random string, within 32 bits sign is String signature, default encryption out_trade_no is String system internal order number total_fee is the total amount of Int order, unit is notify_url is String payment result notification API

The signature of sign is also universal, which involves a nonce_str that guarantees the unpredictability of the signature.

All sent non-null parameters are sorted using a dictionary to generate key-value pairs (key1=value1&key2=value2)

Concatenate the merchant platform key at the end of the above string ("String" + & key= key)

Encrypt the above string with MD5

3.2 payment

Pull up WeChat Pay, enter the password, and complete the payment. This step requires JS to call up the payment in the H5 web page.

The following parameters are required, so when the prepaid order is returned, the following parameters need to be encapsulated and responded to the page to complete the payment.

Whether the parameter name is required type description appId is String official account idtimeStamp is String current timestamp nonceStr is String random string package is String prepaid order, format is prepay_id=***signType is String signature type, default MD5paySign is String signature

Signing is the same as signing the interface to place an order.

The JS pseudo code is as follows:

Function onBridgeReady () {WeixinJSBridge.invoke ('getBrandWCPayRequest', {/ / official account ID, passed "appId": "wx2421b1c4370ec43b", / / timestamp by merchant Seconds since 1970: "timeStamp": "1395712654", / / Random string "nonceStr": "e61463f8efa94090b1f366cccfbbb444", "package": "prepay_id=u802345jgfjsdfgsdg888", / / Wechat signature method "signType": package MD5Mao, / / Wechat signature "paySign": "70EA570631E4BB79628FBCA90534C63FF7FADD89"} Function (res) {if (res.err_msg = = "get_brand_wcpay_request:ok") {/ / use the above method to determine the return of the frontend. Wechat team solemnly reminds: / / res.err_msg will return ok after the user pays successfully. But there is no guarantee that it is absolutely reliable. });} if (typeof WeixinJSBridge = = "undefined") {if (document.addEventListener) {document.addEventListener ('WeixinJSBridgeReady', onBridgeReady, false);} else if (document.attachEvent) {document.attachEvent (' WeixinJSBridgeReady', onBridgeReady); document.attachEvent ('onWeixinJSBridgeReady', onBridgeReady);}} else {onBridgeReady ();}

Note that the sentence / / res.err_msg in the pseudo code will return ok after the user's payment is successful, but there is no guarantee that it is absolutely reliable. Why do you say that? I should understand it by giving an example. If you go shopping in the supermarket, do you say that if the payment is successful, you can take it with you? Certainly not, it is only when the merchant receives the money that you pay successfully, and you can take the things away. That is to say, the success of the hint here does not necessarily mean that the payment is successful. Whether it is successful or not, Wechat platform will notify you asynchronously.

3.3 Asynchronous Notification

Asynchronous notification is an important step, where you can deal with your business logic according to the notification result. However, the notification may not be received due to network fluctuations and other reasons, or the response received by Wechat does not meet the requirements of API. Wechat will continue to initiate multiple notifications (please handle them reasonably in the callback notification API to avoid repeated business processing caused by repeated notifications), until successful, the notification frequency is 15s/15s/30s/3m/10m/20m/30m/30m/30m/60m/3h/3h/3h/6h/6h-total 24h5m). But Wechat does not guarantee that the notice will be successful in the end.

The asynchronous notification response parameters are as follows:

Whether the parameter name is required type description return_code is the String return status code, SUCCESS/FAILreturn_msg No String returns information

What if Wechat keeps telling me that it doesn't succeed? Or the example just now, you obviously paid successfully, but the merchant kept saying that she did not receive the money, what should you do at this time? Must have gone to see if her phone really didn't get the money! It's the same here.

3.4 payment status query

When the merchant APP or the front-end page receives the payment, the merchant needs to call the merchant order checking API to confirm the order status and display the query result to the user.

The merchant backstage needs to process the asynchronous payment result notification sent by WeChat Pay accurately and efficiently, and return the processing result to WeChat Pay according to the interface specification.

When the merchant backend does not receive the notification of asynchronous payment result, the merchant should take the initiative to call WeChat Pay's order checking API to synchronize the order status.

The merchant gets the transaction bill of T day from WeChat Pay on T + 1 and checks with the order in the merchant system. If the order is successful on the WeChat Pay side, but not successful on the merchant side, the merchant needs to reship or refund the goods to the user.

At this point, the study of "methods and steps to access WeChat Pay" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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