/
Bank.ts
137 lines (131 loc) · 3.79 KB
/
Bank.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { fetch } from "../fetch";
import * as types from "../types";
import Base from "./core/Base";
const PAY_BANK_BASE = "/mmpaysptrans/pay_bank";
const QUERY_BANK_BASE = "/mmpaysptrans/query_bank";
const GET_PUBLIC_URL = "https://fraud.mch.weixin.qq.com/risk/getpublickey";
const TRANSFERS_BASE = "/mmpaymkttransfers/promotion/transfers";
const GET_TRANSFER_INFO_BASE = "/mmpaymkttransfers/gettransferinfo";
/**
* 企业付款
*
* ```
* const pay = new Bank({
* appId: "wxb80e5bddb2d804f3",
* key: "6Q9VX4N3WTBM9G9XBL7H1L9PB9ANHLY7",
* mchId: "1434712502",
* pfx: fs.readFileSync(path.resolve(__dirname, "cert.p12"))
* });
* ```
* @see {@link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_1}
*/
export class Bank extends Base {
/**
* 企业付款到零钱
*
* ```
* pay.transfers({
* partner_trade_no: "10000098201411111234567890",
* openid: "oxTWIuGaIt6gTKsQRLau2M0yL16E",
* check_name: "FORCE_CHECK",
* amount: 10099,
* desc: "理赔",
* spbill_create_ip: "192.168.0.1"
* });
* ```
* @see {@link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2}
*/
public async transfers(options: types.TransfersOptions) {
const url = this.completeURL(TRANSFERS_BASE);
const extra = await this.createFetchOptions(url, true);
extra.mapAppId = "mch_appid";
extra.mapMchId = "mchid";
return fetch<
types.TransfersOptions,
types.TransfersSuccess,
types.TransfersFail
>(options, extra);
}
/**
* 查询企业付款到零钱
*
* ```
* pay.getTransferInfo({
* partner_trade_no: "10000098201411111234567890"
* });
* ```
* @see {@link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3}
*/
public async getTransferInfo(options: types.GetTransferInfoOptions) {
const url = this.completeURL(GET_TRANSFER_INFO_BASE);
const extra = await this.createFetchOptions(url, true);
return fetch<
types.GetTransferInfoOptions,
types.GetTransferInfoSuccess,
types.GetTransferInfoFail
>(options, extra);
}
/**
* 企业付款到银行卡
*
* ```
* pay.payBank({
* partner_trade_no: "1212121221227",
* enc_bank_no: utils.rsa(pemKey, "6225760017946512"),
* enc_true_name: utils.rsa(pemKey, "王小王"),
* bank_code: "1001",
* amount: 100,
* desc: "理财"
* });
* // pemKey 通过 `pay.getPublicKey` 获取
* ```
* @see {@link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_2}
*/
public async payBank(options: types.PayBankOptions) {
const url = this.completeURL(PAY_BANK_BASE);
const extra = await this.createFetchOptions(url, true);
extra.mapAppId = "-";
return fetch<types.PayBankOptions, types.PayBankSuccess, types.PayBankFail>(
options,
extra
);
}
/**
* 查询企业付款到银行卡
*
* ```
* pay.queryBank({
* partner_trade_no: "1212121221227"
* });
* ```
* @see {@link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_3}
*/
public async queryBank(options: types.QueryBankOptions) {
const url = this.completeURL(QUERY_BANK_BASE);
const extra = await this.createFetchOptions(url, true);
extra.mapAppId = "-";
return fetch<
types.QueryBankOptions,
types.QueryBankSuccess,
types.QueryBankFail
>(options, extra);
}
/**
* 获取RSA加密公钥
*
* ```
* pay.getPublicKey({
* sign_type: SignType.MD5
* });
* ```
*/
public async getPublicKey(options: types.GetPublicKeyOptions) {
const extra = await this.createFetchOptions(GET_PUBLIC_URL, true);
extra.mapAppId = "-";
return fetch<
types.GetPublicKeyOptions,
types.GetPublicKeySuccess,
types.GetPublicKeyFail
>(options, extra);
}
}