This example for you to share the front-end micro-letter payment JS code for your reference, the specific contents are 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 Diagnostics Service", CallType: "Jsapi", Access_token:geturlparam ("access_t
Oken ")}; $.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 congestion, please visit later ')}else{Console.log (wxres);
if (Wxres.data.respCode = = ' fail ') {$.alert (WXRES.DATA.RESPMSG);
}else{//10 Micro-Credit Payment interface//10.1 Initiate a payment request//NOTE: This Demo uses the 2.7 version of the payment interface to implement, it is recommended to use this interface to refer to the micro-letter payment related to the latest documents.
var param = wxres.data;
Wx.config ({debug:false,//Open debug mode, the return value of all invoked APIs will be on the client alert, to view incoming parameters, can be opened on the PC side, the parameter information will be typed through the log, only on the PC side will print.) AppId: ' WX403EAD26691402FB ',//required, public number unique identification Timestamp:param.timestamp,//required, generate signature timestamp nonceStr:param.noncestr,//Required GeneratedSigned random string signature:param.signjs,//must fill, call JS signature, jsapilist: [' choosewxpay ']//required, need to use the JS interface list, here only write payment}); Wx.choosewxpay ({timestamp:param.timestamp,//payment signature Timestamp, note that all use timestamp fields in the micro-letter jssdk are lowercase. But the latest version of the payment background generation signature uses the timestamp field name to capitalize the S character nonceStr:param.noncestr,//payment signature random string, no longer than 32-bit package: "Prepay_id=" +param.transn O,//Unified Payment Interface return PREPAY_ID parameter value, submit format such as: prepay_id=***) Signtype: "MD5",//Signature way, default to ' SHA1 ', use new version payment to be passed into ' MD5 ' paySign:param.sign
,//Payment signature Success:function (res) {if (res.errmsg = = "Choosewxpay:ok") {//alert ("paid successfully");
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 containing the target parameter Var r = WINDOW.LOCATION.SEARCH.SUBSTR (1). Match (REG); Matching target parameter if (r!=null) return unescape (r[2]); return null; return parameter Value}})
This article has been organized into the "JavaScript micro-Credit Development Skills Summary", welcome to learn to read.
For everyone to recommend now more attention than the micro-letter Program Tutorial: "Micro-letter Small Program Development tutorial" Small series for everyone carefully organized, hope like.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.