This commit is contained in:
@@ -4,4 +4,5 @@ export { deviceApi } from './modules/device.js';
|
|||||||
export { exchangeApi } from './modules/exchange.js';
|
export { exchangeApi } from './modules/exchange.js';
|
||||||
export { orderApi } from './modules/order.js';
|
export { orderApi } from './modules/order.js';
|
||||||
export { realnameApi } from './modules/realname.js';
|
export { realnameApi } from './modules/realname.js';
|
||||||
export { walletApi } from './modules/wallet.js';
|
export { walletApi } from './modules/wallet.js';
|
||||||
|
export { wechatApi } from './modules/wechat.js';
|
||||||
11
api/modules/wechat.js
Normal file
11
api/modules/wechat.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import request from '@/utils/request.js';
|
||||||
|
|
||||||
|
export const wechatApi = {
|
||||||
|
getJssdkConfig(url) {
|
||||||
|
return request({
|
||||||
|
url: '/api/c/v1/wechat/jssdk-config',
|
||||||
|
method: 'GET',
|
||||||
|
data: { url }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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 () => {
|
export const initWxSdk = async () => {
|
||||||
if (typeof wx === 'undefined') return false;
|
if (typeof wx === 'undefined') return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${BASE_URL}/api/c/v1/wx/signature?url=${encodeURIComponent(window.location.href)}`);
|
const data = await wechatApi.getJssdkConfig(window.location.href);
|
||||||
const data = await res.json();
|
|
||||||
|
|
||||||
if (data.code === 200 || data.code === 0) {
|
wx.config({
|
||||||
wx.config({
|
debug: false,
|
||||||
debug: false,
|
appId: APP_ID,
|
||||||
appId: APP_ID,
|
timestamp: data.timestamp,
|
||||||
timestamp: data.data.timestamp,
|
nonceStr: data.nonce_str,
|
||||||
nonceStr: data.data.nonceStr,
|
signature: data.signature,
|
||||||
signature: data.data.signature,
|
jsApiList: ['scanQRCode']
|
||||||
jsApiList: ['scanQRCode']
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
wx.ready(() => resolve(true));
|
wx.ready(() => resolve(true));
|
||||||
wx.error(() => resolve(false));
|
wx.error(() => resolve(false));
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('WX SDK init failed', e);
|
console.error('WX SDK init failed', e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user