微信小程序API 微信支付

wx.requestPayment(OBJECT)

发起微信支付。

Object参数说明:

参数 类型 必填 说明
timeStamp String 时间戳从1970年1月1日00:00:00至今的秒数,即当前的时间
nonceStr String 随机字符串,长度为32个字符以下。
package String 统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=*
signType String 签名算法,暂支持 MD5
paySign String 签名
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

回调结果:

回调类型 errMsg 说明
success requestPayment:ok 调用支付成功
fail requestPayment:fail cancel 用户取消支付
fail requestPayment:fail (detail message) 调用支付失败,其中 detail message 为后台返回的详细失败原因

示例代码:

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

Bug & Tip

bug: 6.5.2 及之前版本中,用户取消支付不会触发 fail 回调,只会触发 complete 回调,回调 errMsg 为 'requestPayment:cancel'

如果开发者已做过JSAPI或JSSDK调起微信支付,接入小程序支付非常相似,以下是三种接入方式的对比:

对比栏目
JSAPI JSSDK 小程序
统一下单 都需要先获取到Openid,调用相同的API
调起数据签名 五个字段参与签名(区分大小写):appId,nonceStr,package,signType,timeStamp
调起支付页面协议 HTTP或HTTPS HTTP或HTTPS HTTPS
支付目录
授权域名
回调函数 success回调 complete、fail、success回调函数
  1. 程序访问商户服务都是通过HTTPS,开发部署的时候需要安装HTTPS服务器

你可能感兴趣的:(微信小程序API 微信支付)