fix: app_id
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import request from '@/utils/request.js';
|
||||
|
||||
export const wechatApi = {
|
||||
getAppId() {
|
||||
return request({
|
||||
url: '/api/c/v1/wechat/appid',
|
||||
method: 'GET'
|
||||
});
|
||||
},
|
||||
|
||||
getJssdkConfig(url) {
|
||||
return request({
|
||||
url: '/api/c/v1/wechat/jssdk-config',
|
||||
@@ -8,4 +15,4 @@ export const wechatApi = {
|
||||
data: { url }
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -66,9 +66,8 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { authApi } from '@/api/index.js';
|
||||
import { authApi, wechatApi } from '@/api/index.js';
|
||||
import { useUserStore } from '@/store/index.js';
|
||||
import { APP_ID } from '@/utils/env.js';
|
||||
import { initWxConfig, wxScan, isInWechat } from '@/utils/wxsdk.js';
|
||||
|
||||
const userStore = useUserStore();
|
||||
@@ -99,6 +98,7 @@
|
||||
const agreed = ref(true);
|
||||
const inputFocus = ref(false);
|
||||
const showError = ref(false);
|
||||
const wechatAppId = ref('');
|
||||
|
||||
const getCode = () => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
@@ -109,10 +109,26 @@
|
||||
window.history.replaceState({}, '', window.location.pathname);
|
||||
};
|
||||
|
||||
const redirectToWxAuth = (assetToken) => {
|
||||
const getWechatAppId = async () => {
|
||||
if (wechatAppId.value) {
|
||||
return wechatAppId.value;
|
||||
}
|
||||
|
||||
const data = await wechatApi.getAppId();
|
||||
if (!data || !data.app_id) {
|
||||
uni.showToast({ title: '微信公众号配置缺失', icon: 'none' });
|
||||
throw new Error('wechat app_id is empty');
|
||||
}
|
||||
|
||||
wechatAppId.value = data.app_id;
|
||||
return wechatAppId.value;
|
||||
};
|
||||
|
||||
const redirectToWxAuth = async (assetToken) => {
|
||||
sessionStorage.setItem('assetToken', assetToken);
|
||||
const appId = await getWechatAppId();
|
||||
const redirectUri = encodeURIComponent(window.location.origin + window.location.pathname);
|
||||
const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APP_ID}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_userinfo&state=wechat_auth#wechat_redirect`;
|
||||
const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_userinfo&state=wechat_auth#wechat_redirect`;
|
||||
window.location.href = url;
|
||||
};
|
||||
|
||||
@@ -194,7 +210,7 @@ const handleScanLogin = async () => {
|
||||
userStore.setAssetToken(verifyData.asset_token);
|
||||
userStore.setIdentifier(identifier.value);
|
||||
|
||||
redirectToWxAuth(verifyData.asset_token);
|
||||
await redirectToWxAuth(verifyData.asset_token);
|
||||
} catch (e) {
|
||||
console.error('登录失败', e);
|
||||
loading.value = false;
|
||||
@@ -446,4 +462,4 @@ const handleScanLogin = async () => {
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
export const BASE_URL = 'https://cmp-api.boss160.cn';
|
||||
|
||||
export const APP_TYPE = 'official_account';
|
||||
|
||||
export const APP_ID = 'wx404dc822ce15c5f0';
|
||||
|
||||
Reference in New Issue
Block a user