JSAPI调起支付分-签约计划

更新时间:2025.02.20

商户通过调用签约计划接口打开微信支付分小程序,引导用户签约计划(Web端)。

简介

接口名称: openBusinessView

接口兼容

接口参数

businessType 必填 string(16)

【跳转类型】 固定配置:wxpayScorePlan


queryString 必填 string(2048)

【业务参数】 使用URL的query string方式传递参数,格式为key=value&key2=value2,其中value,value2需要进行UrlEncode处理。

属性

query示例

1package=AARupJoAAAABAAAAAADSh9ra0Xzx

示例

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

 

 

更多技术问题
技术咨询
反馈
咨询
目录
置顶