fix: app_id
This commit is contained in:
@@ -1,6 +1,13 @@
|
|||||||
import request from '@/utils/request.js';
|
import request from '@/utils/request.js';
|
||||||
|
|
||||||
export const wechatApi = {
|
export const wechatApi = {
|
||||||
|
getAppId() {
|
||||||
|
return request({
|
||||||
|
url: '/api/c/v1/wechat/appid',
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
getJssdkConfig(url) {
|
getJssdkConfig(url) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/c/v1/wechat/jssdk-config',
|
url: '/api/c/v1/wechat/jssdk-config',
|
||||||
@@ -8,4 +15,4 @@ export const wechatApi = {
|
|||||||
data: { url }
|
data: { url }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -66,9 +66,8 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue';
|
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 { useUserStore } from '@/store/index.js';
|
||||||
import { APP_ID } from '@/utils/env.js';
|
|
||||||
import { initWxConfig, wxScan, isInWechat } from '@/utils/wxsdk.js';
|
import { initWxConfig, wxScan, isInWechat } from '@/utils/wxsdk.js';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
@@ -99,6 +98,7 @@
|
|||||||
const agreed = ref(true);
|
const agreed = ref(true);
|
||||||
const inputFocus = ref(false);
|
const inputFocus = ref(false);
|
||||||
const showError = ref(false);
|
const showError = ref(false);
|
||||||
|
const wechatAppId = ref('');
|
||||||
|
|
||||||
const getCode = () => {
|
const getCode = () => {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
@@ -109,10 +109,26 @@
|
|||||||
window.history.replaceState({}, '', window.location.pathname);
|
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);
|
sessionStorage.setItem('assetToken', assetToken);
|
||||||
|
const appId = await getWechatAppId();
|
||||||
const redirectUri = encodeURIComponent(window.location.origin + window.location.pathname);
|
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;
|
window.location.href = url;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -194,7 +210,7 @@ const handleScanLogin = async () => {
|
|||||||
userStore.setAssetToken(verifyData.asset_token);
|
userStore.setAssetToken(verifyData.asset_token);
|
||||||
userStore.setIdentifier(identifier.value);
|
userStore.setIdentifier(identifier.value);
|
||||||
|
|
||||||
redirectToWxAuth(verifyData.asset_token);
|
await redirectToWxAuth(verifyData.asset_token);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('登录失败', e);
|
console.error('登录失败', e);
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@@ -446,4 +462,4 @@ const handleScanLogin = async () => {
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
export const BASE_URL = 'https://cmp-api.boss160.cn';
|
export const BASE_URL = 'https://cmp-api.boss160.cn';
|
||||||
|
|
||||||
export const APP_TYPE = 'official_account';
|
export const APP_TYPE = 'official_account';
|
||||||
|
|
||||||
export const APP_ID = 'wx404dc822ce15c5f0';
|
|
||||||
|
|||||||
Reference in New Issue
Block a user