This commit is contained in:
@@ -1,27 +1,25 @@
|
||||
import { BASE_URL, APP_ID } from './env.js';
|
||||
import { APP_ID } from './env.js';
|
||||
import { wechatApi } from '@/api/index.js';
|
||||
|
||||
export const initWxSdk = async () => {
|
||||
if (typeof wx === 'undefined') return false;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${BASE_URL}/api/c/v1/wx/signature?url=${encodeURIComponent(window.location.href)}`);
|
||||
const data = await res.json();
|
||||
const data = await wechatApi.getJssdkConfig(window.location.href);
|
||||
|
||||
if (data.code === 200 || data.code === 0) {
|
||||
wx.config({
|
||||
debug: false,
|
||||
appId: APP_ID,
|
||||
timestamp: data.data.timestamp,
|
||||
nonceStr: data.data.nonceStr,
|
||||
signature: data.data.signature,
|
||||
jsApiList: ['scanQRCode']
|
||||
});
|
||||
wx.config({
|
||||
debug: false,
|
||||
appId: APP_ID,
|
||||
timestamp: data.timestamp,
|
||||
nonceStr: data.nonce_str,
|
||||
signature: data.signature,
|
||||
jsApiList: ['scanQRCode']
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
wx.ready(() => resolve(true));
|
||||
wx.error(() => resolve(false));
|
||||
});
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
wx.ready(() => resolve(true));
|
||||
wx.error(() => resolve(false));
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('WX SDK init failed', e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user