Antecedent
Originally our small program with good, the result suddenly one day, the small program of the iOS end of the virtual pay off ... Hang Daddy! Android can pay, iOS can't pay. So I find a solution on the Internet.
One said through the app jump payment, can not for an iOS to pay to go to the entire app bar ... ( ̄▽ ̄) "
Second, the virtual payment into a physical goods, offline delivery. I can't afford to be a shoestring. ε=ε=ε= (~ ̄▽ ̄) ~
Three is free. Wqndy ... (o=^ ェ) O┏━┓
Four is paid through the public number. (o?v?) Dentetsu
That must have been four. But this is the first article, no code! (。 ^▽^ is still being tested.
Ideas
To pay in the public number, what we think about is to use the H5 of the public number to pay. Then how to pass the small program to the public number of H5 is a problem. Directly with the small program WebView is obviously not possible, is really not, tried (Lll¬ω¬). We certainly want to go through the small program to jump directly to the public to achieve payment, so the experience is slightly, I mean a little bit better. All right, no nonsense, just say our plan.
Template message
Right, the applet endpoint purchase, and then send a template message to the public, through the template message into the payment interface, to achieve the purchase, after the successful purchase, click the template message and then back to the small program. Emmm ... Well, I admit that this circle is not about the size of the general. Do not know if you have a better way (really ask Ah!!!) ), anyway I'm not ... It almost didn't kill me to make this thing go around.
Small program to the public number template message
According to public official documents can be seen, https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277, (self-view, lazy) like a lot of parameters can be determined, not how to change , such as Access_token Ah, template_id ah, url ah, the only one is Touser (the recipient of OpenID) that is to say we want to get the public number of OpenID on the applet. How to get it?
Public number Silent Authorization
Yes, through the silent authorization of the public number. I'm not doing it for a beautiful format! (ˇ∀ˇ), why is not the snsapi_userinfo for the scope of the Web page authorization, because the user experience Ah, you in the small program inside you try also let the user click agree to log on XX public number test ... Ah hum, how quiet, through the webview Ah, and then the silent authorization after the end can be directly back to the first page of the small program, it will suddenly white screen ( ̄▽ ̄) ", then you authorize the page over there add something good, we are added to pay the Guide page, reluctantly will not feel too pit. Oh, yes, authorization, you have to set up the public domain license! Otherwise, nothing is useless. Oh, and the small program's webview automatically return, can refer to the official document Https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html The Wx.miniProgram.getEnv and Wx.miniProgram.navigateBack methods, a detection environment is not a small program, a fallback. OK, through the silent authorization, we get the OpenID, we can send the template message, OK, suppose we send out ... ( ̄︶ ̄), and then you will find that actually does not. Why? Oh, the user didn't pay attention to the public number. haha haha ヾ (≧▽≦ *) o cool uncomfortable ~ that did not pay attention to the public number you must not go out ah, then save it, first save to the database, and then guide the user concerned, through the user's attention to the event push message, you get the user's OpenID, and then go to the database to check, it is clear that Must be to take the latest message as a template to send the parameters of the message again, after all, you have only one OpenID parameter is not ~ Good, this time really sent out!
Public number
First of all your public number to apply for developers, you have to configure the server domain name, since to pay, you have to configure the public number JS security domain name, by the way the business domain name is also configured Bai.?, ready!
Then you write to accept the event push, or focus on the event push, then check the library, and then drop the Send template message interface.
Then, click on the template message, the URL parameter of the template message corresponds to the page must be in the JS security domain corresponding to the site. Through the URL of the ancestors of the parameters, you can bring some information about the order, and then you get JSAPI permissions, but also to get JSAPI payment interface parameters. Look at the document https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115 the line. Payment parameters There is a need to adjust the public number of unified order of the interface, or to see the document HTTPS://PAY.WEIXIN.QQ.COM/WIKI/DOC/API/JSAPI.PHP?CHAPTER=9_1, ah, finally can pay. After the payment is successful, turn off the page, then the public number pushes a template message, and then you go back to the applet (the address of the document that says the file above the parameter) when you click the template message.
Summarize
This is probably the whole idea. Of course, the middle of the process for us is still quite tortuous, to the public to do the developer certification, certification to do the payment page, to do accept event push interface, to apply for the public number of payment, then need to have merchant number, and then a lot of certification, in order to obtain the Merchant ID and API key and so on. Fortunately, we are now in the test phase.
Well, I also drew a special picture.
Applet cancels iOS virtual payment solution