-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from notadd/develop
chore(release): v0.3.2
- Loading branch information
Showing
10 changed files
with
98 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const WeChatCertificateAgentProvider = 'WeChatCertificateAgentProvider'; | ||
export const WeChatPayCertificateAgentProvider = 'WeChatPayCertificateAgentProvider'; | ||
export const WeChatPayConfigProvider = 'WeChatPayConfigProvider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,11 @@ | ||
import { DynamicModule, Global, HttpModule, Module } from '@nestjs/common'; | ||
import * as https from 'https'; | ||
import { HttpModule, Module } from '@nestjs/common'; | ||
|
||
import { PayAddonConfig, PayAddonConfigProvider } from '../common'; | ||
import { WeChatCertificateAgentProvider } from '../modules/wechat/constants/wechat.constant'; | ||
import { RandomUtil } from './utils/random.util'; | ||
import { XmlUtil } from './utils/xml.util'; | ||
|
||
@Global() | ||
@Module({}) | ||
export class SharedModule { | ||
static forFeature(config: PayAddonConfig): DynamicModule { | ||
const pfx = this.createCertificateAgent(config.wechatConfig.pfx, config.wechatConfig.mch_id); | ||
return { | ||
module: SharedModule, | ||
imports: [HttpModule], | ||
providers: [ | ||
XmlUtil, | ||
RandomUtil, | ||
{ provide: PayAddonConfigProvider, useValue: config }, | ||
{ provide: WeChatCertificateAgentProvider, useValue: pfx } | ||
], | ||
exports: [HttpModule, RandomUtil, XmlUtil, PayAddonConfigProvider, WeChatCertificateAgentProvider] | ||
}; | ||
} | ||
|
||
/** | ||
* 创建请求证书代理 | ||
* | ||
* 此 agent 仅用于微信支付的申请退款、撤销订单和下载资金账单接口 | ||
*/ | ||
private static createCertificateAgent(pfx: Buffer, mchId: string): https.Agent { | ||
if (!pfx) throw Error('读取商户证书失败'); | ||
return new https.Agent({ | ||
pfx, | ||
passphrase: mchId | ||
}); | ||
} | ||
} | ||
@Module({ | ||
imports: [HttpModule], | ||
providers: [XmlUtil, RandomUtil], | ||
exports: [HttpModule, RandomUtil, XmlUtil] | ||
}) | ||
export class SharedModule { } |