aims:
Implement the WeChat payment function in the WeChat webpage to achieve the purpose of placing an order;
Implementation environment:
White code low code platform:https://www.bnocode.com/product.html
enables the API provided by the platform to implement the WeChat payment function, which can be directly called, reducing a lot of debugging time
Platform language:
node.js
Ready to work:
- A WeChat official account administrator account
- A WeChat payment account
- Prepare product and order data tables in the system
Implementation steps:
1. Build a simple custom page, mainly used for order
placement ; 2. Create an API and a webhook to initiate payment and callback payment; (According to the official instructions, the API that initiates WeChat payment will return a configuration JSON , Used for the front-end to initiate payment)
3. Build an order function, the function will call the API to initiate the payment, the front-end page will call the function, set the function return value to the parameter returned by the API, and the front-end uses the return value to initiate the payment ;
4. Go back to the custom page created earlier and write the code for the order function. The idea is to get the openid of the current WeChat user (parameters required to initiate payment), call the order creation function to initiate WeChat payment, and get the function return value , Use the return value to call the payment;
5. After the payment is initiated, the webhook will always be touched. The webhook request body contains the order number and payment result of the payment. You need to update the status of the corresponding order according to the order number and result, return to the webhook, and continue to write and update The code of the order status;
6. To test the effect, I obtained a link with a specific format by asking the customer service. After WeChat enters the link, the front end can obtain the openid, and the WeChat payment can be made;