September 2018

doubt

If you have done wechat jssdk before, you will find that there is nothing more than a back-end signature and return it to the front-end

However, after careful consideration, there is no value information of the configuration items, and the signature is only returned on the H5 page of the public number

Look back at the request parameters and see what's going on

 Wechat order ID

Let's start by looking at the sample values, which I understand as a random string of numbers prepay_ id by Unified single interface Returns the parameters in the result

Start writing logic again

Here we use H5 payment, and the return result is https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_ id=wx151809054027204613d0ca330422xxxxxx&package=287231xxxx

Only by intercepting the URL prepay_ id by wx151809054027204613d0ca330422xxxxxx

take prepay_ id Send back to the back end for signature and return

 {
 "code": 1, 
 "MSG": "obtained wechat browser payment signature successfully", 
 "data": {appid ":" wx54c4e3c9a7xxxxx ", 
" timestamp ":" 1537007685 ", 
" noncestr ":" 5b9ce0458db30 ", 
" package ":" prepay "_ id=wx151809054027204613d0ca330422xxxxxx",
    "signType": "MD5",
    "paySign": "A819D6551E9E3FE62BE612FA96000000"
  }
}

Now the front end can be used happily WeixinJSBridge and JSSDK Yes


Related links:

Transfer payment from H5 in wechat
Wechat unified order

appear invalid signature The wrong situation is really fascinating

  1. At the beginning, the document said no need to escape. Later, I saw the error related and said it needed encodeURIComponent(location.href.split('#')[0])
  2. wx.config() Medium nonceStr When signing with the back end noncestr dissimilarity
  3. When the URL is launched, it is not clear that the front-end URL is used to obtain the dynamic signature

In a word, to use ajax Signature, front end needs encodeURIComponent(location.href.split('#')[0]) Take the current URL as a parameter and pass it into the backend signature interface. If the backend is PHP, you need to urldecode($_ GET['url']) And get it again jsapi_ ticket Sign and return parameters