This article shares the front-end WeChat payment js code for your reference. The specific content is as follows
$('.Save_Patient_Msg').click(function(){ $('.Save_Patient_Msg').off('click'); var hrdfId = getOrderId(); var txnAmt = $('.sum_pay.font-red').html(); var data = {orderId: hrdfId, txnAmt: "0.01", prodDesc: "Remote Diagnostic Service", callType: "JSAPI", access_token: getUrlParam("access_token") }; $.ajax({ type: 'POST', url: '/hims/api/commonPay/queryTransNo?access_token='+getUrlParam('access_token'), dataType:'json', contentType:'application/json', data: JSON.stringify(data), success: function(Wxres){ if(!Wxres){ $.alert('Server is congested, please visit later') }else{ console.log(Wxres); if(Wxres.data.respCode == 'fail'){ $.alert(Wxres.data.respMsg); }else{ //10 WeChat Payment Interface// 10.1 Initiate a payment request // Note: This demo is implemented using the 2.7 version of the payment interface. It is recommended to refer to the latest WeChat payment document when using this interface. var param = Wxres.data; wx.config({ debug: false, // Turn on debug mode, the return values of all APIs called will be alerted on the client. To view the incoming parameters, you can open it on the PC side. The parameter information will be printed through the log and will only be printed on the PC side. appId: 'wx403ead26691402fb', // Required, the unique identifier of the official account timestamp: param.timestamp, // Required, the timestamp generated by the signature nonceStr: param.noncestr, // Required, the random string generated by the signature signature signature: param.signJs, // Required, call js signature, jsApiList: ['chooseWXPay'] // Required, the list of JS interfaces to be used, only the payment is written here }); wx.chooseWXPay({ timestamp: param.timestamp, // Payment signature timestamp, note that all timestamp fields used in WeChat jssdk are lowercase. However, the name of the timeStamp field used to generate signatures in the latest version of the payment background must be uppercased in the S character nonceStr: param.noncestr, // Payment signature random string, not longer than 32 digit package: "prepay_id="+param.transNo, // The prepay_id parameter value returned by the unified payment interface, the submission format is as follows: prepay_id=***) signType: "MD5", // Signature method, default is 'SHA1', use the new version of payment to pass in 'MD5' paySign: param.sign, // Payment signature success: function (res) { if(res.errMsg == "chooseWXPay:ok"){ //alert("Pay success"); window.location.href = "/hims/weixin/pages/Order_ok.html?access_token="+getUrlParam("access_token"); }else{ alert(res.errMsg); } }, cancel: function(res){ //alert('cancel payment'); } }); } } }, error:function(data){ var msg = data.message || data.status; $.alert('server error'+msg); } }); return false; }); function getUrlParam(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //Construct a regular expression object with target parameters var r = window.location.search.substr(1).match(reg); //Match the target parameter if (r!=null) return unescape(r[2]); return null; //Return parameter value} })This article has been compiled into "Summary of JavaScript WeChat Development Skills", and everyone is welcome to learn and read.
I would like to recommend a tutorial on WeChat mini program that is highly concerned: "WeChat Mini Program Development Tutorial" has been carefully compiled by the editor of everyone, I hope you like it.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.