JSAPI调起支付分小程序-订单详情

更新时间:2023.12.05

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

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

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

# 接口说明

支持商户: 【普通商户】

接口名称: 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)
    固定配置:wxpayScoreDetail。
  • 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: 'wxpayScoreDetail',
25 queryString
26: 'mch_id=1230000109&service_id=88888888000011&out_order_no=1234323JKHDFE1243252&
27 timestamp=1530097563&nonce_str=zyx53Nkey8o4bHpxTQvd8m7e92nG5mG2&
28 sign_type=HMAC-SHA256&sign=029B52F67573D7E3BE74904BF9AEA'
29 },
30
31 function (res) {
32 // 从支付分返回时会执行这个回调函数
33 if (parseint(res.err_code) === 0) {
34 // 返回成功
35 } else {
36 // 返回失败
37 }
38 });
39 }
40 }
41 });
42 }
43
44 /**
45 * 版本号比较
46 * @param {string
47} v1
48 * @param {string
49} v2
50 */
51function compareVersion(v1, v2) {
52 v1 = v1.split('.')
53 v2 = v2.split('.')
54 const len = Math.max(v1.length, v2.length)
55
56 while (v1.length < len) {
57 v1.push('0')
58 }
59 while (v2.length < len) {
60 v2.push('0')
61 }
62
63 for (let i = 0; i < len; i++) {
64 const num1 = parseint(v1[i])
65 const num2 = parseint(v2[i])
66
67 if (num1 > num2) {
68 return 1
69 } else if (num1 < num2) {
70 return -1
71 }
72 }
73
74 return 0
75 }
更多技术问题
技术咨询
反馈
咨询
目录