|
@@ -32,3 +32,80 @@ export function getRedirectURL (force, code) {
|
32
|
32
|
return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd3bab568bc42d1de&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`
|
33
|
33
|
}
|
34
|
34
|
}
|
|
35
|
+/**
|
|
36
|
+ * 初始化微信 SDK
|
|
37
|
+ * @param {*} params
|
|
38
|
+ * @returns
|
|
39
|
+ */
|
|
40
|
+export function initWxSDK(params) {
|
|
41
|
+ return new Promise((resolve, reject) => {
|
|
42
|
+ wx.config({
|
|
43
|
+ beta: true, // 获取微信抬头必须这个
|
|
44
|
+ debug: import.meta.env.DEV, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
45
|
+ appId: params.appId, // 必填,公众号的唯一标识
|
|
46
|
+ timestamp: params.timestamp, // 必填,生成签名的时间戳
|
|
47
|
+ nonceStr: params.nonceStr, // 必填,生成签名的随机串
|
|
48
|
+ signature: params.signature,// 必填,签名
|
|
49
|
+ jsApiList: ['chooseInvoiceTitle'] // 必填,需要使用的JS接口列表
|
|
50
|
+ });
|
|
51
|
+
|
|
52
|
+ wx.ready(() => {
|
|
53
|
+ console.log('---微信SDK初始化成功---')
|
|
54
|
+ resolve();
|
|
55
|
+ window.__initwx = true;
|
|
56
|
+ });
|
|
57
|
+ wx.error(function(res){
|
|
58
|
+ console.log('---微信SDK初始化失败---')
|
|
59
|
+ console.error(res);
|
|
60
|
+ window.__initwx = false;
|
|
61
|
+ reject();
|
|
62
|
+ });
|
|
63
|
+ });
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+/**
|
|
67
|
+ * 获取微信抬头
|
|
68
|
+ * @param {*} scene
|
|
69
|
+ * @returns
|
|
70
|
+ */
|
|
71
|
+export function chooseInvoiceTitle(scene) {
|
|
72
|
+ return new Promise((resolve, reject) => {
|
|
73
|
+ if (!window.__initwx) {
|
|
74
|
+ reject('微信SDK未成功初始化');
|
|
75
|
+ return;
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ wx.invoke('chooseInvoiceTitle', { scene }, function (res) {
|
|
79
|
+ console.log('----------chooseInvoiceTitle------', res);
|
|
80
|
+ if (res.err_msg == 'chooseInvoiceTitle:ok') {
|
|
81
|
+ // choose_invoice_title_info 结构如下:
|
|
82
|
+ // {
|
|
83
|
+ // "type":"0",
|
|
84
|
+ // "title":"腾讯科技(深圳)有限公司",
|
|
85
|
+ // "taxNumber":"123466789987646131",
|
|
86
|
+ // "companyAddress":"深圳市南山区某某路腾讯大厦",
|
|
87
|
+ // "telephone":"123456789",
|
|
88
|
+ // "bankName":"某某银行",
|
|
89
|
+ // "bankAccount":"621111111111290"
|
|
90
|
+ // }
|
|
91
|
+ resolve(typeof res.choose_invoice_title_info == 'string' ? JSON.parse(res.choose_invoice_title_info) : res.choose_invoice_title_info);
|
|
92
|
+ } else {
|
|
93
|
+ console.error(res.err_msg);
|
|
94
|
+ console.debug(res);
|
|
95
|
+ reject(res.err_msg);
|
|
96
|
+ }
|
|
97
|
+ });
|
|
98
|
+ });
|
|
99
|
+}
|
|
100
|
+
|
|
101
|
+// 本系统的特殊情况,使用外部服务初始化微信SDK
|
|
102
|
+export function initWxSDK2() {
|
|
103
|
+ const link = window.location.origin + window.location.pathname + window.location.search;
|
|
104
|
+ const servAPI = '//api.h5.njyunzhi.com/mp/jssdk?url=' + encodeURIComponent(link);
|
|
105
|
+
|
|
106
|
+ fetch(servAPI).then(res => res.json()).then(res => {
|
|
107
|
+ console.log('----------', res.data);
|
|
108
|
+ initWxSDK(res.data);
|
|
109
|
+ });
|
|
110
|
+
|
|
111
|
+}
|