Detailed explanation of Java backend to realize unified code scanning payment: wechat

Recently I finished a project and just had nothing to do. The product manager arranged a task for me.

Make a function like collecting money, which can uniformly scan code and collect money.

At the beginning, I didn't know how to achieve it. I consulted several friends before I knew the general business process: first, I opened a web page to judge whether the payment platform was WeChat or Alipay. After that, I decided to copy the official documents of WeChat payment and Alipay directly. However, the wechat documents feel a little pit, so you have to pay more attention.

Now let's talk about how to pay WeChat's payment, that is, the official account payment.

1. Judge the payment platform. When judging the wechat platform, you must use window Location to open the web page. The web page cannot be opened in the IOS version of wechat by other methods, at least the current version of wechat cannot be opened. The corresponding connection is the link requesting code. Step 2 will talk about.

2. Here is to get the code. The callback address must use the UTF-8 code of urlencoder. Finally, only the openid is obtained. You need to get the user info and other information for self-test. You only need to modify the parameters of the scope,

3. There is a codeid parameter in it. Don't worry about it. It is used for testing. Here, you only need openid. The following is to use the get method to obtain the returned result of JSON. After obtaining openid, you can redirect to the payment page.

4. Enter the amount to be paid on the front-end payment page and submit it to the background

5. the amount of the backend gets the sum and then the order is placed at the back end. The official account number is paid differently in two places. First, the payment type should be changed to JSAPI, and the two is to get openid.

6. Examples of results returned after a unified order is successfully placed:

7. The returned parameters need to be re signed and returned to the front end. The signature method is the same as the signature when placing a unified order! When signing, you must bring wechat merchants to the front end in JSON format.

8. The front end needs to parse JSON, get the corresponding value and wake up wechat payment

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>