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

在JSAPI调起支付分相关接口前,需详细阅读JS-SDK说明文档并进行相应配置。

JS-SDK配置为链接:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html (opens new window)

# 接口参数

# Object

  • businessType 必填 string(16)
    固定配置:wxpayScoreEnable。
  • 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/
9 common_page__upgrade&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: 'wxpayScoreEnable',
25 queryString: 'apply_permissions_token=zyx53Nkey8o4bHpxTQvd8m7e92nG5mG2'
26 },
27 function (res) {
28 // 从微信侧小程序返回时会执行这个回调函数
29 if (parseint(res.err_code) === 0) {
30 // 返回成功
31 } else {
32 // 返回失败
33 }
34 });
35 }
36 }
37 });
38 }
39
40 /**
41 * 版本号比较
42 * @param {string} v1
43 * @param {string} v2
44 */
45function compareVersion(v1, v2) {
46 v1 = v1.split('.')
47 v2 = v2.split('.')
48 const len = Math.max(v1.length, v2.length)
49
50 while (v1.length < len) {
51 v1.push('0')
52 }
53 while (v2.length < len) {
54 v2.push('0')
55 }
56
57 for (let i = 0; i < len; i++) {
58 const num1 = parseint(v1[i])
59 const num2 = parseint(v2[i])
60
61 if (num1 > num2) {
62 return 1
63 } else if (num1 < num2) {
64 return -1
65 }
66 }
67
68 return 0
69 }
更多技术问题
技术咨询
反馈
咨询
目录