1 first, the effect drawing

How fast is the payment function implemented? No need to build your own server, no need to buy a domain name, no need to register a domain name, no need to support HTTPS. Only need a simple cloud function, you can easily realize wechat small program payment function

2 Preparations

1. Non-personal applets, personal applets cannot use payment (applets appId)

2. Merchant number (merchant ID, merchant secret key) that has applied for wechat Payment.

3. Associate your merchant number in the applet (bind the applet to the merchant number)

4. Wechat small program opened cloud development

3 a dry

(1) Initialize the cloud development environment

(2) Create cloud function pay

(3) Introduce third-party payment to rely on TenPay

Pay folder right click open in Terminal, installation depends on NPM I tenpay

Once installed, our Pay cloud function will have an additional package.json file

(4) Write cloud functions

(5) Simply write a page to call the cloud function

Friends with problems can add my QQ:392716797

Abnormal problem

  1. Error: errCode: -404011 Cloud function execution Error

  2. Signature error wechat Pay signature error

The source code