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 Mini Programs's top-up page and Mini Program callback after payment

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

Share

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

This article mainly explains "WeChat Mini Programs recharge page and Mini Program post-payment callback how to achieve", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "WeChat Mini Programs top-up page and Mini Program callback after payment how to achieve" it!

When users initiate a top-up request in Mini Program, they will first request their own server to send the top-up parameters to the backend, and then the back-end will request Wechat to recharge, get the unified order parameters returned by Wechat and return them to the front end. The frontend calls wx.requestPayment API to evoke WeChat Mini Programs's payment page, and the user can enter the correct payment password to pay successfully. The specific process is as follows:

1. For example, there is a recharge button on the page, and the parameters requested by the user can be obtained when you click the recharge button. Wx.request ({url: "backend recharge API", method: "POST", dataType: "json", header: {'content-type':' application/x-www-form-urlencoded'}, data: {amount: amount, / / recharge amount token: token, openId: openId} Success: function (res) {if (res.data.code = ='1') {that.setData ({payParams: res.data.data / / parameters for unified ordering obtained from Wechat at backend}) that.xcxPay () / / evoke WeChat Pay page} after getting the parameters of unified order. 2. Call wx.requestPayment to evoke the WeChat Pay interface. Wx.requestPayment ({'timeStamp': that.data.payParams.timestamp.toString (), / / timestamp must be a string, otherwise the error' nonceStr': that.data.payParams.str, 'package':' prepay_id=' + that.data.payParams.prepay_id, / / the value here must be in the format of prepay_id=XXXXXXXXX Otherwise, there will be an error of 'signType':' MD5', 'paySign': that.data.payParams.sign,' success': function (res) {/ / this should be res.errMsg, which is different from the parameter returned by the official account's payment. The official account is err_msg because you didn't notice this. After messing with if (res.errMsg = = "requestPayment:ok") for a long time, {/ / call wx.redirectTo ({url:'.. / chargelist/chargelist' / /) after successful recharge, you can jump. You can also do other processing according to your needs})} else if (res.errMsg = = 'requestPayment:cancel') {/ / the user cancels payment}},' fail': function (res) {return false }, 'complete': function (res) {}}) at this point, I believe you have a deeper understanding of "WeChat Mini Programs's top-up page and how to realize the callback after Mini Program payment". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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