How the Pre-Request Script works
masterThe script is a JavaScript snippet executed by Postman before every request. It automates the following lifecycle:
- Loads dependencies: Uses
forge.min.js(for PKI/RSA/ASN.1) andsm2.js(for Tencent SM2 signatures) stored in Collection Variables to avoid network latency. - Reads Environment: Retrieves merchant parameters (mchid, keys, etc.) from the active Postman Environment.
- Constructs Signature: Based on the HTTP method, URL, parameters, and Body, it generates the signature string and calculates the signature.
- Sets Headers: Automatically populates the
Authorizationheader required by WeChat Pay APIv3.