Home WeChat Applet Mini Program Development Detailed explanation of WeChat applet payment function development error summary

Detailed explanation of WeChat applet payment function development error summary

Mar 27, 2017 pm 02:06 PM
WeChat applet

This article mainly introduces relevant information on the summary of errors in the development of the payment function of WeChat Mini Program. Friends in need can refer to the following

Summary of errors in the development of payment function of WeChat Mini Program

WeChat Mini Program I finally got through the pitfalls in payment, and found that there are quite a lot of pitfalls inside. I’m posting a post now, hoping that students who will fall into the trap in the future can take a look at it:

https://pay.weixin.qq.com/ wiki/doc/api/wxa/wxa_api.php?chapter=7_4&index=2

The business process can be seen here when you read the document. The first pitfall is to obtain the user's openid. The parameters must be spelled in the url connection, otherwise an error of {"errcode":40013,"errmsg":"invalid appid, hints: [ req_id: iil1ba0504ns86 ]"} will be reported

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

 onLoad: function () {

  var that = this

  wx.login({

   success: function (res) {

    if (res.code) {

     //发起网络请求

     wx.request({

      url: 'https://api.weixin.qq.com/sns/jscode2session?appid=wxaacf22345345cfc7162fe3&secret=83ebd41c3e6f34a49b3a34578063434548ff3f71&js_code=' + res.code + '&grant_type=authorization_code',

      method: "POST",

      success: function (res) {

       that.setData({

        openid: res.data.openid

       })

      }

     })

    else {

     console.log('获取用户登录态失败!' + res.errMsg)

    }

   }

  });

 }

Copy after login

The second pitfall is the unified payment ordering interface. Signature pitfall is a pitfall that many people encounter. This is because MD5 encryption is often different from the encrypted signature in the signature tool.

Signature Encryption tool address: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=20_1

When signing and encrypting, it must be converted to utf-8 and encrypted I use my own interface to encrypt digest.update(data.getBytes("utf-8"));

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

 // 统一下单接口获取sign(签名)

 paysignjsapi: function (appid, attach, body, mch_id, nonce_str, notify_url, openid, out_trade_no, spbill_create_ip, total_fee, trade_type, key) {

  var self = this;

  //加密签名

  wx.request({

   url: 'http://localhost:8080/XinXingWXApi/wxXcxApi/Md5Encrypt.do',

   method: 'GET',

   data: {

    appid: appid,

    attach: attach,

    body: body,

    mch_id: mch_id,

    nonce_str: nonce_str,

    notify_url: notify_url,

    openid: openid,

    out_trade_no: out_trade_no,

    spbill_create_ip: spbill_create_ip,

    total_fee: total_fee,

    trade_type: trade_type,

    key: key

   },

   //统一下单

   success: function (res) {

    var sign = res.data.strMd5

    var formData = "<xml>"

    formData += "<appid>" + appid + "</appid>" //appid 

    formData += "<attach>" + attach + "</attach>" //附加数据 

    formData += "<body>" + body + "</body>"    //标题

    formData += "<mch_id>" + mch_id + "</mch_id>" //商户号 

    formData += "<nonce_str>" + nonce_str + "</nonce_str>" //随机字符串,不长于32位。 

    formData += "<notify_url>" + notify_url + "</notify_url>" //异步接收微信支付结果通知的回调地址

    formData += "<openid>" + openid + "</openid>"  //用户Id

    formData += "<out_trade_no>" + out_trade_no + "</out_trade_no>" //商户订单号

    formData += "<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip>"

    formData += "<total_fee>" + total_fee + "</total_fee>" //金额

    formData += "<trade_type>" + trade_type + "</trade_type>"  //公共号支付

    formData += "<sign>" + sign + "</sign>"//签名

    formData += "</xml>"

Copy after login

Return data analysis xml

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

 //请求统一下单接口

    wx.request({

     url: "https://api.mch.weixin.qq.com/pay/unifiedorder",

     method: 'POST',

     data: formData,

     success: function (data) {

      wx.request({

       url: "http://localhost:8080/XinXingWXApi/wxXcxApi/xmlAnalyze.do?strXml=" + data.data,

       method: 'POST',

       success: function (res) {

        var pk = 'prepay_id=' + res.data.prepayId;

        var timeStamp = self.createTimeStamp();

        //获取支付签名,并支付

        self.getsignType(appid, timeStamp, nonce_str, pk, "MD5", key);

       }

      })

     }

    })

   }

  });

 }

Copy after login

The third is to call payment, here There are also a few pitfalls. The first is that many appIds cannot be written as appid. The second is that the parameter format of preoatid must be written correctly prepay_id=wx2017011711060194dccf725232155886323. The third is that a payment signature error is reported when calling payment, and you also need to check the signature interface. Check whether the signatures are consistent and check whether the parameters are correct. When calling WeChat payment, you must add the appId

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

getsignType: function (appid, timeStamp, nonce_str, pk, signType, key) {

  var that = this;

  wx.request({

   url: "http://localhost:8080/XinXingWXApi/wxXcxApi/getSignType.hn",

   method: 'GET',

   data: {

    appId: appid,

    timeStamp: timeStamp,

    nonceStr: nonce_str,

    pk: pk,

    signType: signType,

    key: key

   },

   success: function (res) {

    console.log(res.data.paySign)

    var paySign = res.data.paySign

    //调用微信支付

    wx.requestPayment({

     'appId': appid,

     'timeStamp': timeStamp,

     'nonceStr': nonce_str,

     'package': pk,

     'signType''MD5',

     'paySign': paySign,

     'success'function (res) {

      console.log(res);

      console.log('success');

     },

     'fail'function (res) {

      console.log(res);

      console.log('fail');

     },

     'complete'function (res) {

      // console.log(res);

      console.log('complete');

     }

    });

   }

  })

 }

Copy after login

Thank you for reading, I hope it can help everyone, thank you for your support of this site!

The above is the detailed content of Detailed explanation of WeChat applet payment function development error summary. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xianyu WeChat mini program officially launched Xianyu WeChat mini program officially launched Feb 10, 2024 pm 10:39 PM

Xianyu WeChat mini program officially launched

What is the name of Xianyu WeChat applet? What is the name of Xianyu WeChat applet? Feb 27, 2024 pm 01:11 PM

What is the name of Xianyu WeChat applet?

WeChat applet implements image upload function WeChat applet implements image upload function Nov 21, 2023 am 09:08 AM

WeChat applet implements image upload function

Implement the drop-down menu effect in WeChat applet Implement the drop-down menu effect in WeChat applet Nov 21, 2023 pm 03:03 PM

Implement the drop-down menu effect in WeChat applet

Use WeChat applet to achieve carousel switching effect Use WeChat applet to achieve carousel switching effect Nov 21, 2023 pm 05:59 PM

Use WeChat applet to achieve carousel switching effect

How to use PHP to develop the second-hand transaction function of WeChat applet? How to use PHP to develop the second-hand transaction function of WeChat applet? Oct 27, 2023 pm 05:15 PM

How to use PHP to develop the second-hand transaction function of WeChat applet?

Implement image filter effects in WeChat mini programs Implement image filter effects in WeChat mini programs Nov 21, 2023 pm 06:22 PM

Implement image filter effects in WeChat mini programs

Implement image rotation effect in WeChat applet Implement image rotation effect in WeChat applet Nov 21, 2023 am 08:26 AM

Implement image rotation effect in WeChat applet

See all articles