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 JS API payment developed by WeChat Pay

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is to share with you about how to achieve JS API payment developed by WeChat Pay. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. JS API payment Interface (getBrandWCPayRequest)

Wechat JS API can only be used in Wechat's built-in browser. Calls from other browsers are invalid. Wechat provides getBrandWCPayRequest interface for merchant front-end web pages to call. Wechat will identify the merchant's payment permission before the call. If the merchant has the permission to adjust the payment, the payment process will begin. This article mainly introduces the rules of API call before payment. Please refer to the following for the notification mechanism of payment status message. Note that all incoming parameters are of string type!

The getBrandWCPayRequest parameters are shown in Table 6-5.

Parameters.

Name

Required

Format

Description

AppId

Official account id

Yes

String type

Merchants can get it after successfully registering an official account with payment authority.

TimeStamp

Time stamp

Yes

String type, less than 32 bytes

The number of seconds generated by the merchant since 00:00:00 on January 1, 1970, that is, the current time, and eventually need to be converted to string form

NonceStr

Random string

Yes

String type, less than 32 bytes

Random strings generated by merchants

Package

Order details extension string

Yes

String type, less than 4096 bytes

The merchant forms the order information into the string. For more information, please see the package package in the API usage instructions. It is passed in by the merchant after splicing according to the specification.

SignType

Signature mode

Yes

String type. The parameter is "SHA1".

Fill in as shown in the document. Currently only SHA1 is supported.

PaySign

Signature

Yes

String type

The merchant signs the parameters in the interface list according to the specified method, and the signature method uses the signature method indicated in signType. For the specific signature scheme, please see the instructions for the use of the API. The signature is passed by the merchant after signing in accordance with the specification.

Table 6-5 getBrandWCPayRequest parameters

The return value of getBrandWCPayRequest is shown in Table 6-6.

Return value

Description

Err_msg

Get_brand_wcpay_request:ok payment succeeded

User cancels during get_brand_wcpay_request:cancel payment

Get_brand_wcpay_request:fail payment failed

Table 6-6 getBrandWCPayRequest return values

The returned result get_brand_wcpay_request:ok of JS API is returned only when the user successfully completes the payment. Due to the complexity of the front-end interaction, get_brand_wcpay_request:cancel or get_brand_wcpay_request:fail can be handled uniformly for the user to encounter an error or give up actively, and there is no need to refine the distinction.

II. Implementation of JS API payment

The following code is the JS API payment demo officially provided by Wechat.

Function callpay () {WeixinJSBridge.invoke ('getBrandWCPayRequest',function (res) {WeixinJSBridge.log (res.err_msg); alert (res.err_code+res.err_desc+res.err_msg);});}

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