In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
The knowledge of this article "how Mini Program achieves WeChat Pay's function through Mini Program Cloud" is not quite understood by most people, so the editor summarizes the following, with detailed contents and clear steps, which can be used for reference. I hope you can get something after reading this article. Let's take a look at this "how Mini Program realizes WeChat Pay's function through Mini Program Cloud" article.
First, open WeChat Pay 1.1 related merchant number
Wechat official account platform function WeChat Pay merchant account management related merchant number
1.2 add a merchant number
Cloud development platform settings other settings WeChat Pay configuration add merchant number
1.3 Administrator Authorization
1.2 on that picture, click Authorization. The administrator's Wechat will pop up and click OK to authorize it.
Otherwise, when using it, there will be an error that sub_mch_id does not match sub_appid!
2. Cloud function Development 2.1 New Cloud function
2.2 Cloud function code
Payindex.js
Const cloud = require ("wx-server-sdk") cloud.init ({env: cloud.DYNAMIC_CURRENT_ENV}) exports.main = async (event, context) = > {const res = await cloud.cloudPay.unifiedOrder ({"body": event.body, "outTradeNo": event.outTradeNo, "spbillCreateIp": "127.0.0.1", "subMchId": "0000000000", / / Note here: although key is a sub-merchant id In fact, it is the ordinary merchant id "totalFee": parseInt (event.totalFee), / / the second pit: note that it must be a number, if not a number. The error will be unifiedOrder:fail wx api error:-202 "envId": "ooo-xxxxxxxxxxxxxxxx", / / this is the cloud environment id "functionName": "payCallBack" to which the callback function belongs, / / this is the callback function name "nonceStr": event.nonceStr, / / the third pit: there is no nonceStr or tradeType in the relevant cloud function code in the official document, and an error that does not exist in nonceStr will be reported during testing. If you look through the document, you will find that this is required. After gluing it directly, you need to add these two parameters: "tradeType": "JSAPI"}) return res} 2.3. Upload and deploy the cloud function.
Third, Mini Program calls 3.1 to issue orders.
The data obtained by Wechat after issuing an order had better be saved to the database and kept at the bottom.
Then adjust the interface of WeChat Pay.
/ / call cloud function Wechat unified order cloudPay () {var _ this = this this.setData ({body: "bill payment-xxxxx", outTradeNo: this.data.id+ "-" + util.uuid (16), totalFee: this.data.totalCost*100 / / payment unit: minute}) app.showLoading (true) wx.cloud.callFunction ({name: "pay", data: {body: _ this.data.body OutTradeNo: _ this.data.outTradeNo, totalFee: _ this.data.totalFee, nonceStr:util.uuid (32) / / call your own uuid function}, success (res) {/ / errCode: 0 / / errMsg: "cloudPay.unifiedOrder:ok" / / returnCode: "FAIL" / / returnMsg: "total_fee is empty. " Console.log ("submitted successfully", res.result) if (res.result.uplonCodewords = "SUCCESS") {app.showToast (res.result.returnMsg) return} _ this.unifiedOrder (res.result) / / _ this.requestPayment (res.result)}, fail (res) {console.log ("submission failed", res)}
3.2 adjust the interface of WeChat Pay
/ / official standard payment method. Call the payment interface requestPayment (payData) {var _ this = this; const payment = payData.payment//. Note that the parameters to be used here are directly integrated in the result of the previous function, and you can use wx.requestPayment ({. Payment, / /. Is the syntax of the expanded variable success (res) {console.log ("payment success", res) _ this.paySuccess ()}, fail (res) {console.log ("payment failure", res)})}, 3.2 payment success callback
It is not recommended to perform successful payment operations directly in the success callback function of requestPayment.
It is best to build another cloud function payCallBack.
This cloud function payCallBack calls the interface of our self-built server to perform successful payment operations.
This involves how to call the http interface in the cloud function and sell it, which will be discussed later.
The above is about the content of this article on "how Mini Program achieves WeChat Pay's function through Mini Program Cloud". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.