This commit is contained in:
@@ -127,6 +127,7 @@
|
|||||||
const handleScanLogin = async () => {
|
const handleScanLogin = async () => {
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
const ready = await initWxSdk();
|
const ready = await initWxSdk();
|
||||||
|
console.log(ready);
|
||||||
if (!ready) {
|
if (!ready) {
|
||||||
uni.showToast({ title: '扫一扫功能暂不可用', icon: 'none' });
|
uni.showToast({ title: '扫一扫功能暂不可用', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import { APP_ID } from './env.js';
|
|
||||||
import { wechatApi } from '@/api/index.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 data = await wechatApi.getJssdkConfig(window.location.href);
|
const currentUrl = window.location.href.split('#')[0];
|
||||||
|
console.log('JSSDK URL:', currentUrl);
|
||||||
|
const data = await wechatApi.getJssdkConfig(currentUrl);
|
||||||
|
console.log('JSSDK Config:', data);
|
||||||
|
|
||||||
wx.config({
|
wx.config({
|
||||||
debug: false,
|
debug: true,
|
||||||
appId: APP_ID,
|
appId: data.app_id,
|
||||||
timestamp: data.timestamp,
|
timestamp: data.timestamp,
|
||||||
nonceStr: data.nonce_str,
|
nonceStr: data.nonce_str,
|
||||||
signature: data.signature,
|
signature: data.signature,
|
||||||
@@ -18,7 +20,10 @@ export const initWxSdk = async () => {
|
|||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
wx.ready(() => resolve(true));
|
wx.ready(() => resolve(true));
|
||||||
wx.error(() => resolve(false));
|
wx.error((err) => {
|
||||||
|
console.error('wx.config error:', err);
|
||||||
|
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