|
|
@@ -1,11 +1,11 @@
|
|
|
-import Taro from "@tarojs/taro";
|
|
|
+import Taro from '@tarojs/taro';
|
|
|
|
|
|
// 支付宝小程序全局 API
|
|
|
declare const my: {
|
|
|
- navigateToMiniProgram: (options: { appId: string; path: string }) => void;
|
|
|
- ap: {
|
|
|
- openURL: (options: { url: string }) => void;
|
|
|
- };
|
|
|
+ navigateToMiniProgram: (options: { appId: string; path: string }) => void;
|
|
|
+ ap: {
|
|
|
+ openURL: (options: { url: string }) => void;
|
|
|
+ };
|
|
|
};
|
|
|
|
|
|
// ====== 配置常量 ======
|
|
|
@@ -16,31 +16,31 @@ const BIZ_CODE = '';
|
|
|
|
|
|
// ====== 类型定义 ======
|
|
|
interface AlipayScanExternalThrough {
|
|
|
- pdSubBizScene: 'enterprisePay';
|
|
|
- /** JSON 字符串 */
|
|
|
- specifiedEnableChannelInfo: string;
|
|
|
- assignJointAccountId: string;
|
|
|
- /** JSON 字符串 */
|
|
|
- identityPayBizInfo: string;
|
|
|
- /** JSON 字符串数组 */
|
|
|
- CHANNEL_INDEX: string;
|
|
|
- /** JSON 字符串 */
|
|
|
- sourcePlatformInfo: string;
|
|
|
+ pdSubBizScene: 'enterprisePay';
|
|
|
+ /** JSON 字符串 */
|
|
|
+ specifiedEnableChannelInfo: string;
|
|
|
+ assignJointAccountId: string;
|
|
|
+ /** JSON 字符串 */
|
|
|
+ identityPayBizInfo: string;
|
|
|
+ /** JSON 字符串数组 */
|
|
|
+ CHANNEL_INDEX: string;
|
|
|
+ /** JSON 字符串 */
|
|
|
+ sourcePlatformInfo: string;
|
|
|
}
|
|
|
|
|
|
interface PaymentCodeParams {
|
|
|
- pdSubBizScene: 'enterprisePay';
|
|
|
- CHANNEL_INDEX: string;
|
|
|
- channelMode: string;
|
|
|
- specifiedEnableChannelInfo: string;
|
|
|
- assignJointAccountId: string;
|
|
|
- identityPayBizInfo: string;
|
|
|
- enterprise_pay_info: string;
|
|
|
+ pdSubBizScene: 'enterprisePay';
|
|
|
+ CHANNEL_INDEX: string;
|
|
|
+ channelMode: string;
|
|
|
+ specifiedEnableChannelInfo: string;
|
|
|
+ assignJointAccountId: string;
|
|
|
+ identityPayBizInfo: string;
|
|
|
+ enterprise_pay_info: string;
|
|
|
}
|
|
|
|
|
|
// ====== 工具函数 ======
|
|
|
export const isAlipayEnv = () => {
|
|
|
- return Taro.getEnv() === Taro.ENV_TYPE.ALIPAY;
|
|
|
+ return Taro.getEnv() === Taro.ENV_TYPE.ALIPAY;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
@@ -52,54 +52,54 @@ export const isAlipayEnv = () => {
|
|
|
* @param options - 可选:费控规则ID、付款事由ID
|
|
|
*/
|
|
|
export const scanWithAlipay = (
|
|
|
- enterpriseId: string,
|
|
|
- accountId: string,
|
|
|
- options?: { standardId?: string; paymentId?: string },
|
|
|
+ enterpriseId: string,
|
|
|
+ accountId: string,
|
|
|
+ options?: { standardId?: string; paymentId?: string },
|
|
|
) => {
|
|
|
- if (!isAlipayEnv()) {
|
|
|
- throw new Error('非支付宝环境,无法使用企业码扫码付');
|
|
|
- }
|
|
|
-
|
|
|
- console.log('[scanWithAlipay] enterpriseId:', enterpriseId);
|
|
|
- console.log('[scanWithAlipay] accountId:', accountId);
|
|
|
-
|
|
|
- if (!enterpriseId || !accountId) {
|
|
|
- throw new Error('企业ID或账户ID为空,请确认登录信息');
|
|
|
- }
|
|
|
-
|
|
|
- const externalThrough: AlipayScanExternalThrough = {
|
|
|
- pdSubBizScene: 'enterprisePay',
|
|
|
- specifiedEnableChannelInfo: JSON.stringify({
|
|
|
- enableScene: "agreementpay",
|
|
|
- assetInfo: {
|
|
|
- instId: "INST_ALIPAY",
|
|
|
- assetId: accountId,
|
|
|
- assetTypeCode: "ENTERPRISEPAY",
|
|
|
- assetType: "ENTERPRISEPAYASSET",
|
|
|
- },
|
|
|
- }),
|
|
|
- assignJointAccountId: accountId,
|
|
|
- identityPayBizInfo: JSON.stringify({
|
|
|
- identityPayBizScene: 'ENTERPRISE_CODE',
|
|
|
- identityPaySubBizScene: 'ISV_PAY',
|
|
|
- groupId: accountId,
|
|
|
- bizGroupId: accountId,
|
|
|
- expenseGroupId: options && options.standardId,
|
|
|
- }),
|
|
|
- CHANNEL_INDEX: JSON.stringify(['ENTERPRISEPAYASSET_DC_ENTERPRISEPAY_DEFAULT']),
|
|
|
- sourcePlatformInfo: JSON.stringify({
|
|
|
- ruleGroupId: options && options.standardId,
|
|
|
- paymentId: options && options.paymentId,
|
|
|
- isvAppId: ISV_APP_ID,
|
|
|
- }),
|
|
|
- };
|
|
|
-
|
|
|
- const externalThroughStr = JSON.stringify(externalThrough);
|
|
|
-
|
|
|
- my.navigateToMiniProgram({
|
|
|
- appId: '2021002128690179',
|
|
|
- path: `/pages/open/proxy/index?enterpriseId=${enterpriseId}&pageType=scan&externalThrough=${externalThroughStr}`,
|
|
|
- });
|
|
|
+ if (!isAlipayEnv()) {
|
|
|
+ throw new Error('非支付宝环境,无法使用企业码扫码付');
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('[scanWithAlipay] enterpriseId:', enterpriseId);
|
|
|
+ console.log('[scanWithAlipay] accountId:', accountId);
|
|
|
+
|
|
|
+ if (!enterpriseId || !accountId) {
|
|
|
+ throw new Error('企业ID或账户ID为空,请确认登录信息');
|
|
|
+ }
|
|
|
+
|
|
|
+ const externalThrough: AlipayScanExternalThrough = {
|
|
|
+ pdSubBizScene: 'enterprisePay',
|
|
|
+ specifiedEnableChannelInfo: JSON.stringify({
|
|
|
+ enableScene: 'agreementpay',
|
|
|
+ assetInfo: {
|
|
|
+ instId: 'INST_ALIPAY',
|
|
|
+ assetId: accountId,
|
|
|
+ assetTypeCode: 'ENTERPRISEPAY',
|
|
|
+ assetType: 'ENTERPRISEPAYASSET',
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ assignJointAccountId: accountId,
|
|
|
+ identityPayBizInfo: JSON.stringify({
|
|
|
+ identityPayBizScene: 'ENTERPRISE_CODE',
|
|
|
+ identityPaySubBizScene: 'ISV_PAY',
|
|
|
+ groupId: accountId,
|
|
|
+ bizGroupId: accountId,
|
|
|
+ expenseGroupId: options && options.standardId,
|
|
|
+ }),
|
|
|
+ CHANNEL_INDEX: JSON.stringify(['ENTERPRISEPAYASSET_DC_ENTERPRISEPAY_DEFAULT']),
|
|
|
+ sourcePlatformInfo: JSON.stringify({
|
|
|
+ ruleGroupId: options && options.standardId,
|
|
|
+ paymentId: options && options.paymentId,
|
|
|
+ isvAppId: ISV_APP_ID,
|
|
|
+ }),
|
|
|
+ };
|
|
|
+
|
|
|
+ const externalThroughStr = JSON.stringify(externalThrough);
|
|
|
+
|
|
|
+ my.navigateToMiniProgram({
|
|
|
+ appId: '2021002128690179',
|
|
|
+ path: `/pages/open/proxy/index?enterpriseId=${enterpriseId}&pageType=scan&externalThrough=${externalThroughStr}`,
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
@@ -110,55 +110,55 @@ export const scanWithAlipay = (
|
|
|
* @param options - 可选:费控规则ID、付款事由ID
|
|
|
*/
|
|
|
export const codeWithAlipay = (
|
|
|
- accountId: string,
|
|
|
- options?: { enterpriseId?: string; standardId?: string; paymentId?: string },
|
|
|
+ accountId: string,
|
|
|
+ options?: { enterpriseId?: string; standardId?: string; paymentId?: string },
|
|
|
) => {
|
|
|
- if (!isAlipayEnv()) {
|
|
|
- throw new Error('非支付宝环境,无法使用企业码付款码');
|
|
|
- }
|
|
|
-
|
|
|
- // 如果 BIZ_CODE 未配置,先用 navigateToMiniProgram 方式(测试用)
|
|
|
- if (!BIZ_CODE) {
|
|
|
- const eid = (options && options.enterpriseId) || '';
|
|
|
- if (!eid) {
|
|
|
- throw new Error('enterpriseId 为空,请先确认 /payment/employee/info 接口能正常返回企业数据');
|
|
|
- }
|
|
|
- my.navigateToMiniProgram({
|
|
|
- appId: '2021002128690179',
|
|
|
- path: `/pages/open/proxy/index?enterpriseId=${eid}&pageType=payment-code`,
|
|
|
- });
|
|
|
- return;
|
|
|
+ if (!isAlipayEnv()) {
|
|
|
+ throw new Error('非支付宝环境,无法使用企业码付款码');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果 BIZ_CODE 未配置,先用 navigateToMiniProgram 方式(测试用)
|
|
|
+ if (!BIZ_CODE) {
|
|
|
+ const eid = (options && options.enterpriseId) || '';
|
|
|
+ if (!eid) {
|
|
|
+ throw new Error('enterpriseId 为空,请先确认 /payment/employee/info 接口能正常返回企业数据');
|
|
|
}
|
|
|
-
|
|
|
- const params: PaymentCodeParams = {
|
|
|
- pdSubBizScene: 'enterprisePay',
|
|
|
- CHANNEL_INDEX: JSON.stringify(['ENTERPRISEPAYASSET_DC_ENTERPRISEPAY_DEFAULT']),
|
|
|
- channelMode: 'NONE_CHANNEL_MODE',
|
|
|
- specifiedEnableChannelInfo: JSON.stringify({
|
|
|
- enableScene: 'agreementpay',
|
|
|
- assetInfo: {
|
|
|
- instId: 'INST_ALIPAY',
|
|
|
- assetId: accountId,
|
|
|
- assetTypeCode: 'ENTERPRISEPAY',
|
|
|
- assetType: 'ENTERPRISEPAYASSET',
|
|
|
- },
|
|
|
- }),
|
|
|
- assignJointAccountId: accountId,
|
|
|
- identityPayBizInfo: JSON.stringify({
|
|
|
- identityPaySubBizScene: 'ISV_PAY',
|
|
|
- bizGroupId: accountId,
|
|
|
- groupId: accountId,
|
|
|
- identityPayBizScene: 'ENTERPRISE_CODE',
|
|
|
- }),
|
|
|
- enterprise_pay_info: JSON.stringify({
|
|
|
- paymentId: options && options.paymentId,
|
|
|
- ruleGroupId: options && options.standardId,
|
|
|
- isvAppId: ISV_APP_ID,
|
|
|
- }),
|
|
|
- };
|
|
|
-
|
|
|
- const encodedParams = encodeURIComponent(JSON.stringify(params));
|
|
|
- const schemeUrl = `alipays://platformapi/startapp?appId=20000056&customBizCode=${BIZ_CODE}&customBizParams=${encodedParams}`;
|
|
|
-
|
|
|
- my.ap.openURL({ url: schemeUrl });
|
|
|
+ my.navigateToMiniProgram({
|
|
|
+ appId: '2021002128690179',
|
|
|
+ path: `/pages/open/proxy/index?enterpriseId=${eid}&pageType=payment-code`,
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const params: PaymentCodeParams = {
|
|
|
+ pdSubBizScene: 'enterprisePay',
|
|
|
+ CHANNEL_INDEX: JSON.stringify(['ENTERPRISEPAYASSET_DC_ENTERPRISEPAY_DEFAULT']),
|
|
|
+ channelMode: 'NONE_CHANNEL_MODE',
|
|
|
+ specifiedEnableChannelInfo: JSON.stringify({
|
|
|
+ enableScene: 'agreementpay',
|
|
|
+ assetInfo: {
|
|
|
+ instId: 'INST_ALIPAY',
|
|
|
+ assetId: accountId,
|
|
|
+ assetTypeCode: 'ENTERPRISEPAY',
|
|
|
+ assetType: 'ENTERPRISEPAYASSET',
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ assignJointAccountId: accountId,
|
|
|
+ identityPayBizInfo: JSON.stringify({
|
|
|
+ identityPaySubBizScene: 'ISV_PAY',
|
|
|
+ bizGroupId: accountId,
|
|
|
+ groupId: accountId,
|
|
|
+ identityPayBizScene: 'ENTERPRISE_CODE',
|
|
|
+ }),
|
|
|
+ enterprise_pay_info: JSON.stringify({
|
|
|
+ paymentId: options && options.paymentId,
|
|
|
+ ruleGroupId: options && options.standardId,
|
|
|
+ isvAppId: ISV_APP_ID,
|
|
|
+ }),
|
|
|
+ };
|
|
|
+
|
|
|
+ const encodedParams = encodeURIComponent(JSON.stringify(params));
|
|
|
+ const schemeUrl = `alipays://platformapi/startapp?appId=20000056&customBizCode=${BIZ_CODE}&customBizParams=${encodedParams}`;
|
|
|
+
|
|
|
+ my.ap.openURL({ url: schemeUrl });
|
|
|
};
|