Share front-end WeChat payment js code

Source: Internet
Author: User
This article mainly introduces the front-end payment js code in detail, which has some reference value. interested friends can refer to the examples in this article to share with you the front-end 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 diagnosis service", callType: "JSAPI", access_token: getUrlParam ("access_token") };$. ajax ({type: 'post', url: '/hims/api/commonPay/queryTransNo? Access_token = '+ getUrlParam ('Access _ token'), Ype: 'json', contentType: 'application/json', data: json. stringify (data), success: function (Wxres) {if (! Wxres) {$. alert ('server congested, please visit later ')} else {console. log (Wxres); if (Wxres. data. respCode = 'fail ') {$. alert (Wxres. data. respMsg);} else {// 10 payment interface // 10.1 initiates a payment request // Note: This Demo is implemented using the 2.7 payment interface, we recommend that you use this interface by referring to the latest payment documents. Var param = Wxres. data; wx. config ({debug: false, // enable the debugging mode. The Returned values of all called APIs are displayed in the client alert. to view the input parameters, you can open them on the pc, the parameter information is output through log and printed only on the pc end. AppId: 'wx403ead26691402fb ', // required. the unique timestamp: param. timestamp, // required. the signature timestamp nonceStr: param. noncestr, // required. the random string signature: param. signJs, // required, call js signature, jsApiList: ['choosewxpay'] // required, List of JS interfaces to be used, only paid); wx. chooseWXPay ({timestamp: param. timestamp, // payment signature timestamp. Note that all timestamp fields in jssdk are in lower case. However, the timeStamp field name used to generate a signature in the payment background of the latest version must be capitalized with the S character nonceStr: param. noncestr, // random string of the payment signature, no longer than 32-bit package: "prepay_id =" + param. transNo, // The value of the prepay_id parameter returned by the Unified Payment Interface. the submission format is: prepay_id = ***) signType: "MD5", // The signature method. the default value is 'sha1 ', to use the new payment, you need to input 'md5' paySign: param. sign, // payment signature success: function (res) {if (res. errMsg = "chooseWXPay: OK") {// alert ("payment successful"); window. location. href = "/hims/weixin/pages/Order_ OK .html? Access_token = "+ getUrlParam (" access_token ");} else {alert (res. errMsg) ;}}, cancel: function (res) {// alert ('payment canceled ') ;}}}}, error: function (data) {var msg = data. message | data. status; $. alert ('server error' + msg) ;}}); return false ;}); function getUrlParam (name) {var reg = new RegExp ("(^ | &) "+ name +" = ([^ &] *) (& | $) "); // constructs a regular expression object var r = window containing the target parameter. location. search. substr (1 ). match (reg); // match the target parameter I F (r! = Null) return unescape (r [2]); return null; // return parameter value }})

The above is the details of the front-end payment js code. For more information, see other related articles on php Chinese network!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.