mirror of
https://github.com/certd/certd.git
synced 2026-07-13 00:37:36 +08:00
refactor(certd-server): 移除非运行时依赖到动态导入
将alipay-sdk、openid-client、otplib、wechatpay-node-v3改为动态导入,从dependencies移到devDependencies?不,是改为通过importRuntime动态加载,移除顶层静态引入,优化启动时依赖加载,减少初始包体积和启动耗时
This commit is contained in:
@@ -105,7 +105,7 @@ export class PaymentAlipay implements IPaymentProvider {
|
||||
}
|
||||
|
||||
private async createAlipaySdk() {
|
||||
const AlipaySdk = await import("alipay-sdk");
|
||||
const AlipaySdk = await this.access.importRuntime("alipay-sdk");
|
||||
|
||||
const alipaySdk = new AlipaySdk.AlipaySdk({
|
||||
appId: this.access.appId,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { IPaymentProvider, TradeEntity, UpdateTrade, UpdateTradeInfo } from "@certd/commercial-core";
|
||||
import WxPay from "wechatpay-node-v3";
|
||||
import dayjs from "dayjs";
|
||||
import { logger } from "@certd/basic"; // 支持使用require
|
||||
import { logger } from "@certd/basic";
|
||||
import { WxpayAccess } from "../../../plugins/plugin-plus/wxpay/access.js";
|
||||
export class PaymentWxpay implements IPaymentProvider {
|
||||
access: WxpayAccess;
|
||||
@@ -26,7 +25,7 @@ export class PaymentWxpay implements IPaymentProvider {
|
||||
* }
|
||||
*/
|
||||
|
||||
const pay = this.createSdk();
|
||||
const pay = await this.createSdk();
|
||||
|
||||
const result: any = await pay.query({ out_trade_no: tradeNo });
|
||||
logger.info(`微信支付查询订单返回:${JSON.stringify(result)}`);
|
||||
@@ -58,7 +57,7 @@ export class PaymentWxpay implements IPaymentProvider {
|
||||
async createOrder(trade: TradeEntity, opts: { bindUrl: string; clientIp: string }) {
|
||||
const notify_url = `${opts.bindUrl}/api/payment/notify/wxpay`;
|
||||
|
||||
const pay = this.createSdk();
|
||||
const pay = await this.createSdk();
|
||||
|
||||
const params = {
|
||||
description: trade.title,
|
||||
@@ -83,7 +82,9 @@ export class PaymentWxpay implements IPaymentProvider {
|
||||
};
|
||||
}
|
||||
|
||||
private createSdk() {
|
||||
private async createSdk() {
|
||||
const WxPayLib = await this.access.importRuntime("wechatpay-node-v3");
|
||||
const WxPay = WxPayLib.default;
|
||||
const pay = new WxPay({
|
||||
appid: this.access.appId,
|
||||
mchid: this.access.mchid,
|
||||
@@ -94,7 +95,7 @@ export class PaymentWxpay implements IPaymentProvider {
|
||||
}
|
||||
|
||||
async onNotify(notifyData: any, updateTrade: UpdateTrade) {
|
||||
const pay = this.createSdk();
|
||||
const pay = await this.createSdk();
|
||||
const { ciphertext, associated_data, nonce } = notifyData.resource;
|
||||
logger.info(`微信支付notify:${JSON.stringify(notifyData)}`);
|
||||
const key = this.access.key;
|
||||
|
||||
Reference in New Issue
Block a user