For businesses with online payment needs, integrating WeChat Pay is an important step. How to integrate WeChat Pay from scratch? Here is a detailed guide.
Main types of WeChat Pay
JSAPI payment:Trigger WeChat payment within the WeChat browser. Suitable for websites associated with WeChat official accounts.
Scan code payment:Generate payment QR code, user scan WeChat to complete payment. Suitable for PC websites.
H5 payment:Initiate payment in a browser outside of WeChat, and call up the WeChat client. Suitable for mobile websites.
Preparation before connection
- Register on the WeChat merchant platform (pay.weixin.qq.com)
- Complete corporate certification
- Enable payment capability
- Obtain merchant number (mch_id) and API key
- Configure payment authorization directory
Technical implementation steps
Step 1: Backend SDK IntegrationRecommend using the official WeChat Pay SDK, supporting languages such as Go, PHP, Java, etc. Anqie CMS uses Go language, wechatpay-go library can be used.
Step 2: Unified Order InterfaceCall the WeChat unified order API and pass the order information (amount, product description, user openid, etc.).
Step 3: Generate payment parametersAfter processing the parameters returned by the order, generate payment parameters that can be used by the front-end.
Step 4: Trigger payment on the front-end.Invoke the WeChat JSAPI to trigger the payment panel, and the user confirms the payment.
Step 5: Handle callbackWeChat asynchronous notification of payment result, backend verifies signature and updates order status.
Payment integration of Anqi CMS
The AnQi CMS itself is a CMS system and does not integrate payment functions directly. However, it can be done through: - Installing third-party payment plugins (such as mini-program mall plugins) - Embedding payment QR codes in the content - Connecting to external e-commerce systems
Security measures
- Use HTTPS to ensure communication security
- Verify the WeChat callback signature
- Order amount is calculated by the backend, do not trust the input from the front-end
- Daily reconciliation of merchant platform transaction data
Summary
WeChat payment integration has a moderate technical threshold, the key is to correctly understand the payment process and perform security verification.