From 9e72ccd8e8bf0362dde6e6df9410fedbf79115be Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期二, 25 二月 2025 16:53:07 +0800 Subject: [PATCH] fix: 对接 --- apps/taro/src/hooks/user.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 48 insertions(+), 2 deletions(-) diff --git a/apps/taro/src/hooks/user.ts b/apps/taro/src/hooks/user.ts index f1308ee..3dd00bb 100644 --- a/apps/taro/src/hooks/user.ts +++ b/apps/taro/src/hooks/user.ts @@ -7,12 +7,20 @@ import { useRefeshDidShow } from './infiniteLoading'; import { LoginFormTabs } from '@/subpackages/login/constants'; import { useLoginedJump } from './login'; +import { useLifeRechargeContext, APIgetLifePayWxIndentityParams } from '@life-payment/core-vue'; export function useUser() { const userStore = useUserStore(); - const { userDetail, userInfo, locationCity, virtualUserId, virtualPhoneNumber } = - storeToRefs(userStore); + const { + userDetail, + userInfo, + locationCity, + virtualUserId, + virtualPhoneNumber, + wxCode, + wxOpenId, + } = storeToRefs(userStore); function updateUserInfo() { return userStore.getCurrentUserInfo(); @@ -25,6 +33,8 @@ locationCity, virtualUserId, virtualPhoneNumber, + wxCode, + wxOpenId, }; } @@ -62,6 +72,42 @@ return { isAuth }; } +export function useInitWeixinJSBridge() { + const { wxCode } = useUser(); + + const userStore = useUserStore(); + const router = Taro.useRouter(); + + const code = router.params.code ?? ''; + + 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 { + 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) {} + } + }); +} + export function useGoLogin() { const router = Taro.useRouter(); const { redirectParams } = useLoginedJump(); -- Gitblit v1.9.1