JSAPI调起支付分小程序-确认订单

更新时间:2023.12.05

商户通过调用确认订单接口打开微信支付分小程序,引导用户确认订单(Web端)

# 接口说明

支持商户: 【普通商户】

接口名称: openBusinessView

# 接口兼容

此接口引用 JSAPI版本1.5.0,引用地址:https://res.wx.qq.com/open/js/jweixin-1.5.0.js (opens new window)

要求用户微信版本>=7.0.5

# 接口参数

# Object

  • businessType 必填 string(16)
    固定配置:wxpayScoreUse。
  • queryString 必填 string(2048)
    使用URL的query string方式传递参数,格式为key=value&key2=value2,其中value,value2需要进行UrlEncode处理。
    • 属性

请求示例

1let wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i);
2let wechatVersion = wechatInfo[1];
3
4if (compareVersion(wechatVersion, '7.0.5') >= 0) {
5 goToWXScore();
6} else {
7 // 提示用户升级微信客户端版本
8 window.href = 'https://support.weixin.qq.com/cgi-bin/readtemplate?t=page/common_page__upgrade&
9 text=text005&btn_text=btn_text_0'
10}
11
12/**
13 * 跳转微信支付分
14 */
15function goToWXScore() {
16 wx.checkJsApi({
17 jsApiList: ['openBusinessView'], // 需要检测的JS接口列表
18 success: function (res) {
19 // 以键值对的形式返回,可用的api值true,不可用为false
20 // 如:{"checkResult":{"openBusinessView":true},"errMsg":"checkJsApi:ok"}
21 if (res.checkResult.openBusinessView) {
22 wx.invoke(
23 'openBusinessView', {
24 businessType: 'wxpayScoreUse',
25 queryString
26: 'mch_id=1230000109&package=xxxxx&
27 timestamp=1530097563&nonce_str=zyx53Nkey8o4bHpxTQvd8m7e92nG5mG2&sign_type=HMAC-SHA256&
28 sign=029B52F67573D7E3BE74904BF9AEA'
29 },
30 function (res) {
31 // 从支付分返回时会执行这个回调函数
32 if (parseint(res.err_code) === 0) {
33 // 返回成功
34 } else {
35 // 返回失败
36 }
37 });
38 }
39 }
40 });
41 }
42
43 /**
44 * 版本号比较
45 * @param {string
46} v1
47 * @param {string
48} v2
49 */
50function compareVersion(v1, v2) {
51 v1 = v1.split('.')
52 v2 = v2.split('.')
53 const len = Math.max(v1.length, v2.length)
54
55 while (v1.length < len) {
56 v1.push('0')
57 }
58 while (v2.length < len) {
59 v2.push('0')
60 }
61
62 for (let i = 0; i < len; i++) {
63 const num1 = parseint(v1[i])
64 const num2 = parseint(v2[i])
65
66 if (num1 > num2) {
67 return 1
68 } else if (num1 < num2) {
69 return -1
70 }
71 }
72
73 return 0
74 }

# 返回参数

# Object res

  • err_code 必填 Number/string(32)
    返回码,由于iOS和Android实现的差异,err_code类型可能为Number或string
  • err_msg 必填 string(128)
    返回信息。
  • extraData 选填 Object
    当err_code为0时,extraData才返回;反之,则不返回。
    • 属性

注意

只有用户点支付分页面内返回按钮时,才会带上返回参数;如果用户左滑返回或者点击页面左上角的返回图标返回,则不会带上返回参数。所以推荐在查询支付分订单接口使用out_order_no作为入参。另外商户侧后台在创建支付分订单时需向前端返回out_order_no,同时前端需缓存out_order_no,以便在接口回调中查询订单状态。

反馈
咨询
目录