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/index.html | 1 packages/services/api/Test.ts | 15 ++ apps/taro/src/stores/modules/user.ts | 15 ++ apps/taro/config/dev.js | 1 apps/taro/config/staging.js | 1 apps/taro/config/prod.js | 1 packages/services/api/Account.ts | 15 ++ apps/taro/src/constants/enum.ts | 2 packages/services/api/typings.d.ts | 64 ++++++++++ apps/taro/src/hooks/user.ts | 50 ++++++++ apps/taro/types/global.d.ts | 4 apps/taro/src/pages/home/index.vue | 4 packages/components/src/views/SelectPayTypeView/SelectPayTypeView.vue | 53 ++++++++ apps/taro/src/subpackages/recharge/selectPayType/InnerPage.vue | 10 + packages/core/src/lifeRechargeServices.ts | 59 +++++++++ packages/services/api/LifePay.ts | 23 +++ 16 files changed, 311 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 cba3e8f..19fd7f9 100644 --- a/packages/core/src/lifeRechargeServices.ts +++ b/packages/core/src/lifeRechargeServices.ts @@ -135,6 +135,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 { @@ -308,3 +335,35 @@ /** 閫�娆炬椂闂� */ refundTime?: 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; +} diff --git a/packages/services/api/Account.ts b/packages/services/api/Account.ts index d6cc617..cafe3a1 100644 --- a/packages/services/api/Account.ts +++ b/packages/services/api/Account.ts @@ -161,6 +161,21 @@ }); } +/** 鑾峰彇鐢熸椿缂磋垂鐢ㄦ埛韬唤浼氳瘽淇℃伅 GET /api/Account/GetLifePayWxIndentity */ +export async function getLifePayWxIndentity( + // 鍙犲姞鐢熸垚鐨凱aram绫诲瀷 (闈瀊ody鍙傛暟swagger榛樿娌℃湁鐢熸垚瀵硅薄) + params: API.APIgetLifePayWxIndentityParams, + options?: API.RequestConfig +) { + return request<API.WxMiniAppIndentityInfo>('/api/Account/GetLifePayWxIndentity', { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }); +} + /** 姝ゅ鍚庣娌℃湁鎻愪緵娉ㄩ噴 POST /api/Account/GetOssSTS */ export async function getOssSTS(options?: API.RequestConfig) { return request<API.OssSTSReponse>('/api/Account/GetOssSTS', { diff --git a/packages/services/api/LifePay.ts b/packages/services/api/LifePay.ts index 7abf054..0808f78 100644 --- a/packages/services/api/LifePay.ts +++ b/packages/services/api/LifePay.ts @@ -40,6 +40,14 @@ }); } +/** 鑾峰彇鐢佃垂鍏呭�煎尯鍩� GET /api/LifePay/GetElectricSupportArea */ +export async function getElectricSupportArea(options?: API.RequestConfig) { + return request<API.ElectricSupportAreaResponse>('/api/LifePay/GetElectricSupportArea', { + method: 'GET', + ...(options || {}), + }); +} + /** 鑾峰彇璁㈠崟鍒嗛〉鏁版嵁 POST /api/LifePay/GetLifePayOrderPage */ export async function getLifePayOrderPage( body: API.QueryLifePayOrderListInput, @@ -55,6 +63,21 @@ }); } +/** 鑾峰彇寰俊鏀粯鐨凧SAPI POST /api/LifePay/GetPayOrderForJsAPI */ +export async function getPayOrderForJsAPI( + body: API.GetPayOrderForJsAPIInput, + options?: API.RequestConfig +) { + return request<API.ModelPaymentMiniPay>('/api/LifePay/GetPayOrderForJsAPI', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }); +} + /** 鏍规嵁璁㈠崟鍙疯幏鍙栨敮浠樼姸鎬� GET /api/LifePay/GetPayStatusByOrderNo */ export async function getPayStatusByOrderNo( // 鍙犲姞鐢熸垚鐨凱aram绫诲瀷 (闈瀊ody鍙傛暟swagger榛樿娌℃湁鐢熸垚瀵硅薄) diff --git a/packages/services/api/Test.ts b/packages/services/api/Test.ts index 2fd5623..5e6ed93 100644 --- a/packages/services/api/Test.ts +++ b/packages/services/api/Test.ts @@ -137,6 +137,21 @@ }); } +/** 姝ゅ鍚庣娌℃湁鎻愪緵娉ㄩ噴 GET /api/Test/TestH5Pay */ +export async function testH5Pay( + // 鍙犲姞鐢熸垚鐨凱aram绫诲瀷 (闈瀊ody鍙傛暟swagger榛樿娌℃湁鐢熸垚瀵硅薄) + params: API.APItestH5PayParams, + options?: API.RequestConfig +) { + return request<string>('/api/Test/TestH5Pay', { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }); +} + /** 姝ゅ鍚庣娌℃湁鎻愪緵娉ㄩ噴 GET /api/Test/TestQRCodePay */ export async function testQRCodePay( // 鍙犲姞鐢熸垚鐨凱aram绫诲瀷 (闈瀊ody鍙傛暟swagger榛樿娌℃湁鐢熸垚瀵硅薄) diff --git a/packages/services/api/typings.d.ts b/packages/services/api/typings.d.ts index bc3cbf5..0dcdab1 100644 --- a/packages/services/api/typings.d.ts +++ b/packages/services/api/typings.d.ts @@ -1466,6 +1466,11 @@ id?: string; } + interface APIgetLifePayWxIndentityParams { + /** 鐢ㄦ埛鐧诲綍鍑瘉 */ + code?: string; + } + interface APIgetListParams { filter?: string; clientId?: string; @@ -1899,6 +1904,14 @@ interface APItestGetPlatformServicePayParams { id?: string; + } + + interface APItestH5PayParams { + payType?: LifePayTypeEnum; + outTradeNo?: string; + description?: string; + amount?: number; + h5Type?: string; } interface APItestPayNotifyParams { @@ -5488,6 +5501,37 @@ electricParValue?: ElectricParValueOutput[]; } + interface ElectricSupportAreaChildCityListOutput { + cityName?: string; + cityParentId?: string; + cityId?: string; + } + + interface ElectricSupportAreaListOutput { + childCityList?: ElectricSupportAreaChildCityListOutput[]; + cityName?: string; + cityParentId?: string; + cityId?: string; + electricType?: string; + parValue?: string[]; + rate?: number; + } + + interface ElectricSupportAreaResponse { + success?: boolean; + requestNo?: string; + partnerId?: string; + service?: string; + version?: string; + protocol?: string; + context?: string; + ext?: any; + code?: string; + message?: string; + detail?: string; + electricAreaList?: ElectricSupportAreaListOutput[]; + } + interface EnableSearchSettingInput { id: string; status: boolean; @@ -7743,6 +7787,13 @@ status?: ParkRewardStatusEnum; /** 濂栧姳鍚嶇О */ rewardName?: string; + } + + interface GetPayOrderForJsAPIInput { + orderNo: string; + lifePayType?: LifePayTypeEnum; + openId?: string; + attach?: string; } interface GetPermissionListResultDto { @@ -12649,6 +12700,16 @@ defaultValue?: any; } + interface ModelPaymentMiniPay { + nonceStr?: string; + package?: string; + signType?: string; + paySign?: string; + timestamp?: string; + timeExpire?: string; + message?: string; + } + interface ModuleApiDescriptionModel { rootPath?: string; remoteServiceName?: string; @@ -17415,6 +17476,9 @@ interface SetLifePayOrderPayTypeInput { orderNo: string; lifePayType?: LifePayTypeEnum; + h5Type?: string; + openId?: string; + attach?: string; } interface SetManyContractTemplateHandSignKeyInput { -- Gitblit v1.9.1