I am developing Chinese eCommerce website by PHP. And I have completed QR code generation of weixin pay url. And it is working correctly on PC.
Now in case of tablet or mobile website version how can i open wechat application from a webpage and send QR code data to wechat application.
Each time you're generating the URL you put inside the QRCode you're creating a Wechat Order calling the
unifiedorder
Url provided by WechatPay, right? Usingtrade_type = NATIVE
.What you need is make the same call to that URL but with
trade_type = JSAPI
, also adding the parameteropenid = wechatUserOpenId
.Then, using the returned data
$orderResult
you need to generate an string in json format, with the following data, like in this code:Once you have that string, inside the page you're showing in the Wechat WebBrowser you need to make an ajax call to get it and use it in a code like this:
Execute
callpay()
in an onClick event:The
parameters
is the formatted result of theunifiedorder
WechatPay API call. Thefunction(res)
is called after the user get out the WechatPay Gateway with those possibles results.I hope this is helpful for you.
UPDATE:
I realized you don't need the file jweixin-1.0.0.js, the Wechat Web Browser it's gonna recognize the JS call.
Another comment, only Wechat version 5.0 and greater supports the payment feature, so users with versions prior to 5.0 can't access Wechat Payment. But you can check the version in the user agent, it should say something like this:
Mozilla/5.0(iphone;CPU iphone OS 5_1_1 like Mac OS X) AppleWebKit/534.46(KHTML,like Gecko) Mobile/9B206 MicroMessenger/5.0