From 73ac6d02a2223f19201426f3c366661d4a8e41bf Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期二, 25 二月 2025 17:14:37 +0800
Subject: [PATCH] Merge branch 'master' of http://120.26.58.240:8888/r/LifePaymentFront

---
 apps/taro/src/index.html                                              |    1 
 apps/taro/src/constants/enum.ts                                       |    2 
 apps/taro/src/hooks/user.ts                                           |   50 ++++++++++++
 apps/taro/types/global.d.ts                                           |    4 +
 apps/taro/src/pages/home/index.vue                                    |    4 +
 apps/taro/src/stores/modules/user.ts                                  |   15 +++
 packages/components/src/views/SelectPayTypeView/SelectPayTypeView.vue |   53 ++++++++++++-
 apps/taro/config/dev.js                                               |    1 
 apps/taro/src/subpackages/recharge/selectPayType/InnerPage.vue        |   10 ++
 packages/core/src/lifeRechargeServices.ts                             |   58 ++++++++++++++
 apps/taro/config/staging.js                                           |    1 
 apps/taro/config/prod.js                                              |    1 
 12 files changed, 193 insertions(+), 7 deletions(-)

diff --git a/apps/taro/config/dev.js b/apps/taro/config/dev.js
index 92c0394..172be07 100644
--- a/apps/taro/config/dev.js
+++ b/apps/taro/config/dev.js
@@ -7,6 +7,7 @@
 
     OSS_URL: '"https://waterdroptest2.oss-cn-hangzhou.aliyuncs.com/"',
     WEMAP_KEY: 'T2UBZ-N563J-ZCHFF-XDOXN-VCH7S-CJB2T',
+    WXPayAppId: 'wxf940ff1d35a98493',
   },
   defineConstants: {},
   mini: {},
diff --git a/apps/taro/config/prod.js b/apps/taro/config/prod.js
index 3099e80..11beb0c 100644
--- a/apps/taro/config/prod.js
+++ b/apps/taro/config/prod.js
@@ -10,6 +10,7 @@
     OSS_URL: '"https://parkmanagement.oss-cn-hangzhou.aliyuncs.com"',
 
     WEMAP_KEY: 'DYRBZ-ZGPCF-X3OJN-N2AA3-JWUCE-HEBXJ',
+    WXPayAppId: 'wxf940ff1d35a98493',
   },
   defineConstants: {},
   mini: {},
diff --git a/apps/taro/config/staging.js b/apps/taro/config/staging.js
index 37ffd64..7b1cd87 100644
--- a/apps/taro/config/staging.js
+++ b/apps/taro/config/staging.js
@@ -12,6 +12,7 @@
     APP_ENV: '"staging"',
 
     WEMAP_KEY: 'T2UBZ-N563J-ZCHFF-XDOXN-VCH7S-CJB2T',
+    WXPayAppId: 'wxf940ff1d35a98493',
   },
   h5: {
     output: {
diff --git a/apps/taro/src/constants/enum.ts b/apps/taro/src/constants/enum.ts
index 6d77347..109f31d 100644
--- a/apps/taro/src/constants/enum.ts
+++ b/apps/taro/src/constants/enum.ts
@@ -2,3 +2,5 @@
   toDetail = 'toDetail',
   back = 'back',
 }
+
+export const WXPayAppId = process.env.WXPayAppId;
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();
diff --git a/apps/taro/src/index.html b/apps/taro/src/index.html
index 49a37be..f4a4633 100644
--- a/apps/taro/src/index.html
+++ b/apps/taro/src/index.html
@@ -12,6 +12,7 @@
     <script>
       <%= htmlWebpackPlugin.options.script %>
     </script>
+    <script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
   </head>
   <body>
     <div id="app"></div>
diff --git a/apps/taro/src/pages/home/index.vue b/apps/taro/src/pages/home/index.vue
index aba6441..23f4464 100644
--- a/apps/taro/src/pages/home/index.vue
+++ b/apps/taro/src/pages/home/index.vue
@@ -17,6 +17,10 @@
 import { OrderInputType } from '@life-payment/constants';
 import { RechargeGrid } from '@life-payment/components';
 
+const userStore = useUserStore();
+
+const router = Taro.useRouter();
+
 const goPhoneBillRecharge = useAccessLogin(() => {
   Taro.navigateTo({
     url: `${RouterPath.phoneBillRecharge}`,
diff --git a/apps/taro/src/stores/modules/user.ts b/apps/taro/src/stores/modules/user.ts
index cab0747..f6d8ac5 100644
--- a/apps/taro/src/stores/modules/user.ts
+++ b/apps/taro/src/stores/modules/user.ts
@@ -36,6 +36,9 @@
 
   virtualUserId?: string;
   virtualPhoneNumber?: string;
+
+  wxCode?: string;
+  wxOpenId?: string;
 }
 
 const goAuthorization = debounce(
@@ -73,6 +76,9 @@
 
       virtualUserId: storageVirtualUser?.virtualUserId ?? '',
       virtualPhoneNumber: storageVirtualUser?.virtualPhoneNumber ?? '',
+
+      wxCode: '',
+      wxOpenId: '',
     };
   },
   getters: {
@@ -235,6 +241,13 @@
       setUserDetail(detail);
     },
 
+    setWxCode(code: string) {
+      this.wxCode = code;
+    },
+    setWxOpenId(openId: string) {
+      this.wxOpenId = openId;
+    },
+
     resetState() {
       this.userInfo = null;
       this.token = '';
@@ -242,6 +255,8 @@
       this.userDetail = null;
       this.virtualUserId = '';
       this.virtualPhoneNumber = '';
+      this.wxCode = '';
+      this.wxOpenId = '';
       removeUserInfo();
       removeUserDetail();
       removeStorageVirtualUserId();
diff --git a/apps/taro/src/subpackages/recharge/selectPayType/InnerPage.vue b/apps/taro/src/subpackages/recharge/selectPayType/InnerPage.vue
index 2d6676d..e214be7 100644
--- a/apps/taro/src/subpackages/recharge/selectPayType/InnerPage.vue
+++ b/apps/taro/src/subpackages/recharge/selectPayType/InnerPage.vue
@@ -7,6 +7,10 @@
       @paySuccess="handePaySuccess"
       :showAliPay="!isInWeChat"
       :showWeixinPay="!isInAlipay"
+      :openId="wxOpenId"
+      :isInWeChat="isInWeChat"
+      :isH5="isH5"
+      :appId="WXPayAppId"
     />
   </ContentScrollView>
 </template>
@@ -15,7 +19,9 @@
 import { SelectPayTypeView } from '@life-payment/components';
 import { LifeRechargeConstants } from '@life-payment/core-vue';
 import Taro from '@tarojs/taro';
-import { isInAlipay, isInWeChat } from '@/utils/env';
+import { isInAlipay, isInWeChat, isH5 } from '@/utils/env';
+import { useUser } from '@/hooks';
+import { WXPayAppId } from '@/constants';
 
 defineOptions({
   name: 'selectPayType',
@@ -25,6 +31,8 @@
 const orderNo = router.params?.orderNo ?? '';
 const lifePayOrderType = Number(router.params?.lifePayOrderType ?? '');
 
+const { wxOpenId } = useUser();
+
 function handePaySuccess(
   orderNo: string,
   lifePayOrderType: LifeRechargeConstants.LifePayOrderTypeEnum
diff --git a/apps/taro/types/global.d.ts b/apps/taro/types/global.d.ts
index 95c11a5..6c54fae 100644
--- a/apps/taro/types/global.d.ts
+++ b/apps/taro/types/global.d.ts
@@ -32,6 +32,9 @@
     }
   }
 
+  interface Window {
+    WeixinJSBridge: any
+  }
 }
 
 declare namespace NodeJS {
@@ -47,6 +50,7 @@
     OSS_URL: string;
     TEST_OSS_URL: string;
     WEMAP_KEY: string;
+    WXPayAppId: string;
   }
 }
 
diff --git a/packages/components/src/views/SelectPayTypeView/SelectPayTypeView.vue b/packages/components/src/views/SelectPayTypeView/SelectPayTypeView.vue
index 93705f7..4309f0c 100644
--- a/packages/components/src/views/SelectPayTypeView/SelectPayTypeView.vue
+++ b/packages/components/src/views/SelectPayTypeView/SelectPayTypeView.vue
@@ -4,7 +4,7 @@
       <img class="select-pay-type-view-item-icon" :src="IconAliPay" />
       <div class="select-pay-type-view-item-text">鏀粯瀹濇敮浠�</div>
     </div>
-    <div class="select-pay-type-view-item" v-if="showWeixinPay" @click="handleWeixinPay">
+    <div class="select-pay-type-view-item" v-if="showWeixinPay" @click="handleWeixinPayByJsApi">
       <img class="select-pay-type-view-item-icon" :src="IconWeixin" />
       <div class="select-pay-type-view-item-text">寰俊鏀粯</div>
     </div>
@@ -18,6 +18,7 @@
   useLifeRechargeContext,
   SetLifePayOrderPayTypeInput,
   LifeRechargeConstants,
+  GetPayOrderForJsAPIInput,
 } from '@life-payment/core-vue';
 import { useQuery } from '@tanstack/vue-query';
 
@@ -30,6 +31,10 @@
   lifePayOrderType?: LifeRechargeConstants.LifePayOrderTypeEnum;
   showAliPay?: boolean;
   showWeixinPay?: boolean;
+  openId?: string;
+  isInWeChat?: boolean;
+  isH5?: boolean;
+  appId?: string;
 };
 
 const props = withDefaults(defineProps<Props>(), {
@@ -43,6 +48,7 @@
     orderNo: string,
     lifePayOrderType: LifeRechargeConstants.LifePayOrderTypeEnum
   ): void;
+  (e: 'payOrderForJsAPISuccess'): void;
 }>();
 
 const { blLifeRecharge } = useLifeRechargeContext();
@@ -57,10 +63,49 @@
 }
 
 async function handleWeixinPay() {
+  if (props.isH5) {
+    if (props.isInWeChat) {
+      handleWeixinPayByJsApi();
+    } else {
+      try {
+        let res = await setLifePayOrderPayType(blLifeRecharge.constants.LifePayTypeEnum.WxPay);
+        if (res) {
+          location.href = res;
+        }
+      } catch (error) {}
+    }
+  }
+}
+
+async function handleWeixinPayByJsApi() {
   try {
-    let res = await setLifePayOrderPayType(blLifeRecharge.constants.LifePayTypeEnum.WxPay);
-    if (res) {
-      location.href = res;
+    let params: GetPayOrderForJsAPIInput = {
+      orderNo: props.orderNo,
+      lifePayType: blLifeRecharge.constants.LifePayTypeEnum.WxPay,
+      openId: props.openId,
+      attach: Date.now().toString(),
+    };
+    let res = await blLifeRecharge.services.getPayOrderForJsAPI(params);
+    //@ts-ignore
+    if (res && WeixinJSBridge) {
+      //@ts-ignore
+      WeixinJSBridge.invoke(
+        'getBrandWCPayRequest',
+        {
+          appId: props.appId, //鍏紬鍙稩D锛岀敱鍟嗘埛浼犲叆
+          timeStamp: res.timestamp, //鏃堕棿鎴筹紝鑷�1970骞翠互鏉ョ殑绉掓暟
+          nonceStr: res.nonceStr, //闅忔満涓�
+          package: res.package,
+          signType: res.signType, //寰俊绛惧悕鏂瑰紡锛�
+          paySign: res.paySign, //寰俊绛惧悕
+        },
+        function (res) {
+          if (res.err_msg == 'get_brand_wcpay_request:ok') {
+            // 浣跨敤浠ヤ笂鏂瑰紡鍒ゆ柇鍓嶇杩斿洖,寰俊鍥㈤槦閮戦噸鎻愮ず锛�
+            //res.err_msg灏嗗湪鐢ㄦ埛鏀粯鎴愬姛鍚庤繑鍥瀘k锛屼絾骞朵笉淇濊瘉瀹冪粷瀵瑰彲闈狅紝鍟嗘埛闇�杩涗竴姝ヨ皟鐢ㄥ悗绔煡鍗曠‘璁ゆ敮浠樼粨鏋溿��
+          }
+        }
+      );
     }
   } catch (error) {}
 }
diff --git a/packages/core/src/lifeRechargeServices.ts b/packages/core/src/lifeRechargeServices.ts
index 3a52b29..4127822 100644
--- a/packages/core/src/lifeRechargeServices.ts
+++ b/packages/core/src/lifeRechargeServices.ts
@@ -143,6 +143,33 @@
       ...(options || {}),
     });
   }
+
+  /** 鑾峰彇鐢熸椿缂磋垂鐢ㄦ埛韬唤浼氳瘽淇℃伅 GET /api/Account/GetLifePayWxIndentity */
+  async getLifePayWxIndentity(
+    // 鍙犲姞鐢熸垚鐨凱aram绫诲瀷 (闈瀊ody鍙傛暟swagger榛樿娌℃湁鐢熸垚瀵硅薄)
+    params: APIgetLifePayWxIndentityParams,
+    options?: RequestConfig
+  ) {
+    return this.request<WxMiniAppIndentityInfo>('/api/Account/GetLifePayWxIndentity', {
+      method: 'GET',
+      params: {
+        ...params,
+      },
+      ...(options || {}),
+    });
+  }
+
+  /** 鑾峰彇寰俊鏀粯鐨凧SAPI POST /api/LifePay/GetPayOrderForJsAPI */
+  async getPayOrderForJsAPI(body: GetPayOrderForJsAPIInput, options?: RequestConfig) {
+    return this.request<ModelPaymentMiniPay>('/api/LifePay/GetPayOrderForJsAPI', {
+      method: 'POST',
+      headers: {
+        'Content-Type': 'application/json',
+      },
+      data: body,
+      ...(options || {}),
+    });
+  }
 }
 
 export interface PhoneMesssageCodeLoginInput {
@@ -347,3 +374,34 @@
   cityParentId?: string;
   ciytId?: string;
 }
+export interface APIgetLifePayWxIndentityParams {
+  /** 鐢ㄦ埛鐧诲綍鍑瘉 */
+  code?: string;
+}
+
+export interface WxMiniAppIndentityInfo {
+  /** 浼氳瘽瀵嗛挜 */
+  sessionKey?: string;
+  /** 灏忕▼搴廜penId */
+  openId?: string;
+  /** 鐢ㄦ埛鍚嶏紙璇ュ�间负绌哄垯闇�鎵嬫満鎺堟潈鐧诲綍锛屼笉涓虹┖鍒欏凡鏈夎灏忕▼搴忕敤鎴凤級 */
+  userName?: string;
+  unionId?: string;
+}
+
+export interface GetPayOrderForJsAPIInput {
+  orderNo: string;
+  lifePayType?: LifeRechargeConstants.LifePayTypeEnum;
+  openId?: string;
+  attach?: string;
+}
+
+export interface ModelPaymentMiniPay {
+  nonceStr?: string;
+  package?: string;
+  signType?: string;
+  paySign?: string;
+  timestamp?: string;
+  timeExpire?: string;
+  message?: string;
+}

--
Gitblit v1.9.1