Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API WeChat payment


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.requestPayment(OBJECT)

Start WeChat payment.

Object parameter description:

Parameters Type Required Description
timeStamp String Is The number of seconds from 00:00:00 on January 1, 1970 to the present time
nonceStr String Is Random string with a length of less than 32 characters.
package String Is Unified order interface returned by the prepay_id parameter value, the submission format is prepay_id *
signType String Is Signature algorithm, MD5 is temporarily supported
paySign String Is Signature, see the small program payment interface document for specific signature schemes ;
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

For more information, check out the WeChat payment interface documentation

Callback results:

The type of callback errMsg Description
success requestPayment:ok The call was successful
fail requestPayment:fail cancel The user cancels the payment
fail requestPayment:fail (detail message) The call payment failed, where the detail message is the detailed reason for the failure returned in the background


Example code:

wx.requestPayment({
   "timeStamp": "",
   "nonceStr": "",
   "package": "",
   "signType": "MD5",
   "paySign": "",
   "success":function(res){
   },
   "fail":function(res){
   }
})


Bug & Tip

  1. bug : 6.5.2 and previous versions, user cancellation does not trigger a fail callback, only a complete callback, callback errMsg is 'requestPayment:cancel'