From 8aff873d24cec76d21a33222a5f8d41c14e8445c Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期二, 25 二月 2025 17:28:57 +0800 Subject: [PATCH] fix: 对接 --- apps/taro/src/hooks/user.ts | 42 +++++++++++++++++++++++------------------- apps/taro/config/dev.js | 2 +- apps/taro/config/staging.js | 2 +- apps/taro/config/prod.js | 2 +- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/apps/taro/config/dev.js b/apps/taro/config/dev.js index 172be07..46d0db9 100644 --- a/apps/taro/config/dev.js +++ b/apps/taro/config/dev.js @@ -7,7 +7,7 @@ OSS_URL: '"https://waterdroptest2.oss-cn-hangzhou.aliyuncs.com/"', WEMAP_KEY: 'T2UBZ-N563J-ZCHFF-XDOXN-VCH7S-CJB2T', - WXPayAppId: 'wxf940ff1d35a98493', + WXPayAppId: '"wxf940ff1d35a98493"', }, defineConstants: {}, mini: {}, diff --git a/apps/taro/config/prod.js b/apps/taro/config/prod.js index 11beb0c..bd2e8a3 100644 --- a/apps/taro/config/prod.js +++ b/apps/taro/config/prod.js @@ -10,7 +10,7 @@ OSS_URL: '"https://parkmanagement.oss-cn-hangzhou.aliyuncs.com"', WEMAP_KEY: 'DYRBZ-ZGPCF-X3OJN-N2AA3-JWUCE-HEBXJ', - WXPayAppId: 'wxf940ff1d35a98493', + WXPayAppId: '"wxf940ff1d35a98493"', }, defineConstants: {}, mini: {}, diff --git a/apps/taro/config/staging.js b/apps/taro/config/staging.js index 7b1cd87..b11a7da 100644 --- a/apps/taro/config/staging.js +++ b/apps/taro/config/staging.js @@ -12,7 +12,7 @@ APP_ENV: '"staging"', WEMAP_KEY: 'T2UBZ-N563J-ZCHFF-XDOXN-VCH7S-CJB2T', - WXPayAppId: 'wxf940ff1d35a98493', + WXPayAppId: '"wxf940ff1d35a98493"', }, h5: { output: { diff --git a/apps/taro/src/hooks/user.ts b/apps/taro/src/hooks/user.ts index 3dd00bb..e651456 100644 --- a/apps/taro/src/hooks/user.ts +++ b/apps/taro/src/hooks/user.ts @@ -8,6 +8,7 @@ import { LoginFormTabs } from '@/subpackages/login/constants'; import { useLoginedJump } from './login'; import { useLifeRechargeContext, APIgetLifePayWxIndentityParams } from '@life-payment/core-vue'; +import { isInWeChat } from '@/utils/env'; export function useUser() { const userStore = useUserStore(); @@ -57,6 +58,8 @@ const isAuth = computed(() => !needAuth || isLogin.value); const router = Taro.useRouter(); + console.log('222', 222); + useInitWeixinJSBridge(); Taro.useReady(async () => { if (isLogin.value && userStore.firstGetUserDetail) { @@ -83,29 +86,30 @@ const { blLifeRecharge } = useLifeRechargeContext(); Taro.useReady(async () => { - if (!code && !!WeixinJSBridge && !wxCode) { - location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf940ff1d35a98493&redirect_uri=${location.href}&response_type=code&scope=snsapi_base#wechat_redirect`; - } - if (!!code && !wxCode) { - try { + try { + //@ts-ignore + if (!code && isInWeChat && !wxCode.value) { + location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf940ff1d35a98493&redirect_uri=${location.href}&response_type=code&scope=snsapi_base#wechat_redirect`; + } + if (!!code && !wxCode.value) { userStore.setWxCode(router.params.code ?? ''); let res = await getLifePayWxIndentity(); userStore.setWxOpenId(res.openId); - } catch (error) {} - } - - async function getLifePayWxIndentity() { - try { - let params: APIgetLifePayWxIndentityParams = { - code: code, - }; - let res = await blLifeRecharge.services.getLifePayWxIndentity(params, { - showLoading: false, - }); - return res; - } catch (error) {} - } + } + } catch (error) {} }); + + async function getLifePayWxIndentity() { + try { + let params: APIgetLifePayWxIndentityParams = { + code: code, + }; + let res = await blLifeRecharge.services.getLifePayWxIndentity(params, { + showLoading: false, + }); + return res; + } catch (error) {} + } } export function useGoLogin() { -- Gitblit v1.9.1