In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
The knowledge points of this article "how Mini Program unifies single interface document" are not quite understood by most people, so the editor summarizes the following contents for you. The content is detailed, the steps are clear, and it has certain reference value. I hope you can get something after reading this article. Let's take a look at this "Mini Program how to unify single interface document" article.
When doing Mini Program payment, I hope you have been familiar with Wechat documents WeChat Pay-Mini Program-mobile and WeChat Pay-Mini Program-background. And you already have it.
AppID: "wx*", / / Mini Program ID Secret: "* *", / / Mini Program Secret Mch_id: "*" / / merchant number Mch_key: "*", / / merchant key
For the acquisition of the above four data, please obtain and set them in your own account. And you already have the user's openid. WeChat Mini Programs Development (4) access to user openid.
Mini Program API wx.requestPayment ({'timeStamp':', 'nonceStr':', 'package':', 'signType':' MD5', 'paySign':'', 'success':function (res) {},' fail':function (res) {}})
The Mini Program interface exposes this method. This method has four parameters that need to be obtained in the background.
In fact, most of the work is done backstage.
Back-end implementation
The backend is mainly the API https://api.mch.weixin.qq.com/pay/unifiedorder for issuing orders uniformly.
Here are several signature algorithms:
Unified order signature / / generate signature function paysignjsapi (appid,body,mch_id,nonce_str,notify_url,openid,out_trade_no,spbill_create_ip,total_fee) {var ret = {appid: appid,body: body,mch_id: mch_id,nonce_str: nonce_str,notify_url: notify_url,openid: openid Out_trade_no:out_trade_no, spbill_create_ip:spbill_create_ip, total_fee:total_fee, trade_type: 'JSAPI'} Var str = raw (ret); str = str +'& key='+key; var md5Str = cryptoMO.createHash ('md5') .update (str) .digest (' hex'); md5Str = md5Str.toUpperCase (); return md5Str;}; function raw (args) {var keys = Object.keys (args); keys = keys.sort (); var newArgs = {}; keys.forEach (function (key) {newArgs [key.toLowerCase ()] = args [key] }); var str =''; for (var k in newArgs) {str + ='&'+ k +'='+ newArgs [k];} str = str.substr (1); return str;} Mini Program paySignfunction paysignjs (appid, nonceStr, package, signType, timeStamp) {var ret = {appId: appid, nonceStr: nonceStr, package: package, signType: signType, timeStamp: timeStamp}; var str = raw1 (ret); str = str +'& key='+key; return cryptoMO.createHash ('md5') .update (str) .digest (' hex');} Function raw1 (args) {var keys = Object.keys (args); keys = keys.sort () var newArgs = {}; keys.forEach (function (key) {newArgs [key] = args [key];}); var str ='; for (var k in newArgs) {str + ='&'+ k +'='+ newArgs [k];} str = str.substr (1); return str;} Implement var wxConfig = require ('.. / wx_pay/wx_x_config'); var cryptoMO = require ('crypto'); / / MD5 algorithm var parseString = require (' xml2js'). ParseString; / / xml to js object var key = wxConfig.Mch_key;/* * launch WeChat Pay * / router.all ('/ api/wxpay/unifiedorder', function (req, res, next) {var param = req.query | | req.params) according to openid Var openid = param.openid; var spbill_create_ip = req.ip.replace (/:: ffff:/,''); / / get client ip var body = 'test payment'; / / Product description var notify_url = 'https://www.hgdqdev.cn/api/wxpay' / / callback address with successful payment can be accessed without parameter var nonce_str = getNonceStr () / / Random string var out_trade_no = wxConfig.getWxPayOrdrID (); / / merchant order number var total_fee = '1commodity; / / order price unit is var timestamp = Math.round (new Date (). GetTime () / 1000); / / current time var bodyData =''; bodyData + =''+ wxConfig.AppID +''; / / Mini Program ID bodyData + =''+ body +'' / / Product description bodyData + =''+ wxConfig.Mch_id +''; / / merchant number bodyData + =''+ nonce_str +''; / / Random string bodyData + =''+ notify_url +''; / / callback address bodyData + =''+ openid +''; / / user ID bodyData + =''+ out_trade_no +'' / / merchant order number bodyData + =''+ spbill_create_ip +''; / Terminal IP bodyData + =''+ total_fee +''; / / the total amount is in sub-bodyData + = 'JSAPI' / / Mini Program values for transaction types are as follows: JSAPI / / signature var sign = paysignjsapi (wxConfig.AppID, body, wxConfig.Mch_id, nonce_str, notify_url, openid, out_trade_no, spbill_create_ip, total_fee); bodyData + =''+ sign +''; bodyData + ='' / / WeChat Mini Programs Unified order issuing API var urlStr = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; request ({url: urlStr, method:' POST', body: bodyData}, function (error, response, body) {if (! error & & response.statusCode = = 200) {var returnValue = {} ParseString (body, function (err, result) {if (result.xml.return_code [0] = = 'SUCCESS') {returnValue.msg =' successful operation'; returnValue.status = '100 successful; returnValue.out_trade_no = out_trade_no / / merchant order number / / Mini Program client payment requires the four parameters nonceStr,timestamp,package,paySign returnValue.nonceStr = result.xml.nonce_str [0]; / / random string returnValue.timestamp = timestamp.toString () / / timestamp returnValue.package = 'prepay_id=' + result.xml.prepay_id [0]; / the prepay_id parameter value returned by the unified order issuing API returnValue.paySign = paysignjs (wxConfig.AppID, returnValue.nonceStr, returnValue.package,' MD5',timestamp); / / signature res.end (JSON.stringify (returnValue)) } else {returnValue.msg = result.xml.return_msg [0]; returnValue.status = '102; res.end (JSON.stringify (returnValue));});})})
WxConfig Code:
/ * Wechat parameters AppID and Secret * / var wxConfig = {AppID: "wx*", / / Mini Program ID Secret: "* *", / / Mini Program Secret Mch_id: "*" / / merchant number Mch_key: "*", / / merchant key / / generate merchant order number getWxPayOrdrID: function () {var myDate = new Date () Var year = myDate.getFullYear (); var mouth = myDate.getMonth () + 1; var day = myDate.getDate (); var hour = myDate.getHours (); var minute = myDate.getMinutes (); var second = myDate.getSeconds (); var msecond = myDate.getMilliseconds (); / / get current milliseconds (0,999) if (mouth
< 10){ /*月份小于10 就在前面加个0*/ mouth = String(String(0) + String(mouth)); } if(day < 10){ /*日期小于10 就在前面加个0*/ day = String(String(0) + String(day)); } if(hour < 10){ /*时小于10 就在前面加个0*/ hour = String(String(0) + String(hour)); } if(minute < 10){ /*分小于10 就在前面加个0*/ minute = String(String(0) + String(minute)); } if(second < 10){ /*秒小于10 就在前面加个0*/ second = String(String(0) + String(second)); } if (msecond < 10) { msecond = String(String(00) + String(second)); } else if(msecond >= 10 & & msecond < 100) {msecond = String (String (0) + String (second));} var currentDate = String (year) + String (mouth) + String (day) + String (hour) + String (minute) + String (second) + String (msecond); return currentDate;}; module.exports = wxConfig; instance / payment button Click event payTap: function () {var self = this Wx.request ({url: 'https://www.hgdqdev.cn/api/wxpay/unifiedorder', data: {openid: self.data.openid / / here normal projects will not have only one parameter openid}, success: function (res) {if (res.data.status = = 100) {var payModel = res.data Wx.requestPayment ({'timeStamp': payModel.timestamp,' nonceStr': payModel.nonceStr, 'package': payModel.package,' signType': 'MD5',' paySign': payModel.paySign, 'success': function (res) {wx.showToast ({title:' payment successful') Icon: 'success', duration: 2000})},' fail': function (res) {}})}, fail: function () {}})}, these are the contents of this article on how to unify Mini Program's single interface document. 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 the relevant knowledge, please pay attention to 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.