node-easywechat 2.6.9 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -4
- package/dist/BaseService/ContentSecurity/ContentSecurityClient.d.ts +5 -3
- package/dist/BaseService/ContentSecurity/ContentSecurityClient.js +2 -2
- package/dist/BaseService/Jssdk/JssdkClient.d.ts +15 -15
- package/dist/BaseService/Jssdk/JssdkClient.js +15 -15
- package/dist/BaseService/Media/MediaClient.d.ts +22 -20
- package/dist/BaseService/Media/MediaClient.js +14 -14
- package/dist/BaseService/Url/UrlClient.d.ts +1 -1
- package/dist/Core/AES.d.ts +46 -0
- package/dist/Core/AES.js +95 -0
- package/dist/Core/BaseApplication.js +9 -5
- package/dist/Core/Encryptor.d.ts +2 -14
- package/dist/Core/Encryptor.js +9 -39
- package/dist/Core/Http/Request.js +2 -6
- package/dist/Core/Messages/Message.js +2 -16
- package/dist/Core/PKCS.d.ts +15 -0
- package/dist/Core/PKCS.js +44 -0
- package/dist/Core/RSA.d.ts +59 -0
- package/dist/Core/RSA.js +99 -0
- package/dist/Core/ServerGuard.d.ts +1 -1
- package/dist/Core/ServerGuard.js +5 -33
- package/dist/Core/Types.d.ts +29 -4
- package/dist/Core/Utils.d.ts +8 -2
- package/dist/Core/Utils.js +61 -20
- package/dist/MicroMerchant/Application.d.ts +27 -0
- package/dist/MicroMerchant/Application.js +105 -0
- package/dist/MicroMerchant/Base/MicroMerchantBase.d.ts +7 -0
- package/dist/MicroMerchant/Base/MicroMerchantBase.js +52 -0
- package/dist/MicroMerchant/Certficates/CertficatesClient.d.ts +5 -0
- package/dist/MicroMerchant/Certficates/CertficatesClient.js +52 -0
- package/dist/MicroMerchant/Core/BaseClient.d.ts +9 -0
- package/dist/MicroMerchant/Core/BaseClient.js +106 -0
- package/dist/MicroMerchant/Media/MediaClient.d.ts +6 -0
- package/dist/MicroMerchant/Media/MediaClient.js +33 -0
- package/dist/MicroMerchant/MerchantConfig/MerchantConfigClient.d.ts +8 -0
- package/dist/MicroMerchant/MerchantConfig/MerchantConfigClient.js +49 -0
- package/dist/MicroMerchant/Meterial/MeterialClient.d.ts +5 -0
- package/dist/MicroMerchant/Meterial/MeterialClient.js +30 -0
- package/dist/MicroMerchant/Withdraw/WithdrawClient.d.ts +5 -0
- package/dist/MicroMerchant/Withdraw/WithdrawClient.js +28 -0
- package/dist/MiniProgram/Encryptor.js +2 -6
- package/dist/Payment/Bill/BillClient.js +1 -1
- package/dist/Payment/Core/BaseClient.d.ts +0 -1
- package/dist/Payment/Core/BaseClient.js +2 -20
- package/dist/Payment/Notify/Handler.js +3 -11
- package/dist/Payment/Notify/Refunded.d.ts +0 -1
- package/dist/Payment/Notify/Refunded.js +1 -11
- package/dist/Payment/Transfer/TransferClient.js +4 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/node-easywechat.file_cache.easywechat.kernel.access_token.8a9684b45da7de42a06a70ba01a7005a.cache +1 -1
- package/node-easywechat.file_cache.easywechat.kernel.access_token.c3d06edaf326aad75d32f31348df787a.cache +1 -1
- package/package.json +9 -7
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import BaseApplication from '../Core/BaseApplication';
|
|
2
|
+
import { EasyWechatConfig } from '../Core/Types';
|
|
3
|
+
import MicroMerchantBase from './Base/MicroMerchantBase';
|
|
4
|
+
import CertficatesClient from './Certficates/CertficatesClient';
|
|
5
|
+
import MediaClient from './Media/MediaClient';
|
|
6
|
+
import MerchantConfigClient from './MerchantConfig/MerchantConfigClient';
|
|
7
|
+
import MeterialClient from './Meterial/MeterialClient';
|
|
8
|
+
import WithdrawClient from './Withdraw/WithdrawClient';
|
|
9
|
+
export default class MicroMerchant extends BaseApplication {
|
|
10
|
+
protected defaultConfig: EasyWechatConfig;
|
|
11
|
+
base: MicroMerchantBase;
|
|
12
|
+
certficates: CertficatesClient;
|
|
13
|
+
media: MediaClient;
|
|
14
|
+
merchantConfig: MerchantConfigClient;
|
|
15
|
+
material: MeterialClient;
|
|
16
|
+
withdraw: WithdrawClient;
|
|
17
|
+
constructor(config?: EasyWechatConfig, prepends?: Object, id?: String);
|
|
18
|
+
registerProviders(): void;
|
|
19
|
+
getKey(): string;
|
|
20
|
+
setSubMchId(subMchId: string, appId?: string): this;
|
|
21
|
+
setCertificate(certificate: string, serialNo?: string): this;
|
|
22
|
+
verifySignature(data: object): boolean;
|
|
23
|
+
submitApplication(): Promise<any>;
|
|
24
|
+
getStatus(): Promise<any>;
|
|
25
|
+
upgrade(): Promise<any>;
|
|
26
|
+
getUpgradeStatus(): Promise<any>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const BaseApplication_1 = __importDefault(require("../Core/BaseApplication"));
|
|
7
|
+
const Utils_1 = require("../Core/Utils");
|
|
8
|
+
const MicroMerchantBase_1 = __importDefault(require("./Base/MicroMerchantBase"));
|
|
9
|
+
const CertficatesClient_1 = __importDefault(require("./Certficates/CertficatesClient"));
|
|
10
|
+
const MediaClient_1 = __importDefault(require("./Media/MediaClient"));
|
|
11
|
+
const MerchantConfigClient_1 = __importDefault(require("./MerchantConfig/MerchantConfigClient"));
|
|
12
|
+
const MeterialClient_1 = __importDefault(require("./Meterial/MeterialClient"));
|
|
13
|
+
const WithdrawClient_1 = __importDefault(require("./Withdraw/WithdrawClient"));
|
|
14
|
+
class MicroMerchant extends BaseApplication_1.default {
|
|
15
|
+
constructor(config = {}, prepends = {}, id = null) {
|
|
16
|
+
super(config, prepends, id);
|
|
17
|
+
this.defaultConfig = {
|
|
18
|
+
// 必要配置
|
|
19
|
+
app_id: '',
|
|
20
|
+
mch_id: '',
|
|
21
|
+
key: '',
|
|
22
|
+
http: {
|
|
23
|
+
baseURL: 'https://api.mch.weixin.qq.com/',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
this.base = null;
|
|
27
|
+
this.certficates = null;
|
|
28
|
+
this.media = null;
|
|
29
|
+
this.merchantConfig = null;
|
|
30
|
+
this.material = null;
|
|
31
|
+
this.withdraw = null;
|
|
32
|
+
this.registerProviders();
|
|
33
|
+
}
|
|
34
|
+
registerProviders() {
|
|
35
|
+
super.registerCommonProviders();
|
|
36
|
+
this.offsetSet('base', function (app) {
|
|
37
|
+
return new MicroMerchantBase_1.default(app);
|
|
38
|
+
});
|
|
39
|
+
this.offsetSet('certficates', function (app) {
|
|
40
|
+
return new CertficatesClient_1.default(app);
|
|
41
|
+
});
|
|
42
|
+
this.offsetSet('media', function (app) {
|
|
43
|
+
return new MediaClient_1.default(app);
|
|
44
|
+
});
|
|
45
|
+
this.offsetSet('merchantConfig', function (app) {
|
|
46
|
+
return new MerchantConfigClient_1.default(app);
|
|
47
|
+
});
|
|
48
|
+
this.offsetSet('material', function (app) {
|
|
49
|
+
return new MeterialClient_1.default(app);
|
|
50
|
+
});
|
|
51
|
+
this.offsetSet('withdraw', function (app) {
|
|
52
|
+
return new WithdrawClient_1.default(app);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
getKey() {
|
|
56
|
+
let key = this.config.key;
|
|
57
|
+
if (!key) {
|
|
58
|
+
throw new Error('config key should not empty.');
|
|
59
|
+
}
|
|
60
|
+
if (32 !== key.length) {
|
|
61
|
+
throw new Error(`'${key}' should be 32 chars length.`);
|
|
62
|
+
}
|
|
63
|
+
return key;
|
|
64
|
+
}
|
|
65
|
+
setSubMchId(subMchId, appId = '') {
|
|
66
|
+
this.config.sub_mch_id = subMchId;
|
|
67
|
+
if (appId) {
|
|
68
|
+
this.config.appid = appId;
|
|
69
|
+
}
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
setCertificate(certificate, serialNo = '') {
|
|
73
|
+
this.config.certificate = certificate;
|
|
74
|
+
this.config.serial_no = serialNo;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
verifySignature(data) {
|
|
78
|
+
if (typeof data['sign'] == 'undefined' || !data['sign']) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
let sign = data['sign'];
|
|
82
|
+
delete data['sign'];
|
|
83
|
+
let signType = sign.length > 32 ? 'HMAC-SHA256' : 'MD5';
|
|
84
|
+
let secretKey = this.getKey();
|
|
85
|
+
if (Utils_1.makeSignature(data, secretKey, signType) === sign) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
throw new Error('return value signature verification error');
|
|
89
|
+
}
|
|
90
|
+
// map to `base` module
|
|
91
|
+
submitApplication() {
|
|
92
|
+
return this.base.submitApplication.apply(this.base, arguments);
|
|
93
|
+
}
|
|
94
|
+
getStatus() {
|
|
95
|
+
return this.base.getStatus.apply(this.base, arguments);
|
|
96
|
+
}
|
|
97
|
+
upgrade() {
|
|
98
|
+
return this.base.upgrade.apply(this.base, arguments);
|
|
99
|
+
}
|
|
100
|
+
getUpgradeStatus() {
|
|
101
|
+
return this.base.getUpgradeStatus.apply(this.base, arguments);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.default = MicroMerchant;
|
|
105
|
+
;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import BaseClient from '../Core/BaseClient';
|
|
2
|
+
export default class MicroMerchantBase extends BaseClient {
|
|
3
|
+
submitApplication(params: object): Promise<any>;
|
|
4
|
+
getStatus(applymentId: string, businessCode?: string): Promise<any>;
|
|
5
|
+
upgrade(params: object): Promise<any>;
|
|
6
|
+
getUpgradeStatus(subMchId?: string): Promise<any>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Utils_1 = require("../../Core/Utils");
|
|
7
|
+
const BaseClient_1 = __importDefault(require("../Core/BaseClient"));
|
|
8
|
+
class MicroMerchantBase extends BaseClient_1.default {
|
|
9
|
+
submitApplication(params) {
|
|
10
|
+
let newParams = this.processParams(Utils_1.merge(Utils_1.merge({}, params), {
|
|
11
|
+
version: '3.0',
|
|
12
|
+
cert_sn: '',
|
|
13
|
+
sign_type: 'HMAC-SHA256',
|
|
14
|
+
nonce_str: Utils_1.randomString(18),
|
|
15
|
+
}));
|
|
16
|
+
return this.safeRequest('applyment/micro/submit', newParams);
|
|
17
|
+
}
|
|
18
|
+
getStatus(applymentId, businessCode = '') {
|
|
19
|
+
let params = {
|
|
20
|
+
version: '1.0',
|
|
21
|
+
sign_type: 'HMAC-SHA256',
|
|
22
|
+
nonce_str: Utils_1.randomString(18),
|
|
23
|
+
};
|
|
24
|
+
if (applymentId) {
|
|
25
|
+
params['applyment_id'] = applymentId;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
params['business_code'] = businessCode;
|
|
29
|
+
}
|
|
30
|
+
return this.safeRequest('applyment/micro/getstate', params);
|
|
31
|
+
}
|
|
32
|
+
upgrade(params) {
|
|
33
|
+
let newParams = this.processParams(Utils_1.merge(Utils_1.merge({}, params), {
|
|
34
|
+
sub_mch_id: params['sub_mch_id'] || this.app.config.sub_mch_id,
|
|
35
|
+
version: '1.0',
|
|
36
|
+
cert_sn: '',
|
|
37
|
+
sign_type: 'HMAC-SHA256',
|
|
38
|
+
nonce_str: Utils_1.randomString(18),
|
|
39
|
+
}));
|
|
40
|
+
return this.safeRequest('applyment/micro/submitupgrade', newParams);
|
|
41
|
+
}
|
|
42
|
+
getUpgradeStatus(subMchId = '') {
|
|
43
|
+
let params = {
|
|
44
|
+
sub_mch_id: subMchId || this.app.config.sub_mch_id,
|
|
45
|
+
version: '1.0',
|
|
46
|
+
sign_type: 'HMAC-SHA256',
|
|
47
|
+
nonce_str: Utils_1.randomString(18),
|
|
48
|
+
};
|
|
49
|
+
return this.safeRequest('applyment/micro/getupgradestate', params);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = MicroMerchantBase;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const AES_1 = require("../../Core/AES");
|
|
16
|
+
const Utils_1 = require("../../Core/Utils");
|
|
17
|
+
const BaseClient_1 = __importDefault(require("../Core/BaseClient"));
|
|
18
|
+
class CertficatesClient extends BaseClient_1.default {
|
|
19
|
+
get(returnRaw = false) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
let params = {
|
|
22
|
+
sign_type: 'HMAC-SHA256',
|
|
23
|
+
nonce_str: Utils_1.randomString(18),
|
|
24
|
+
};
|
|
25
|
+
if (returnRaw) {
|
|
26
|
+
return yield this.requestRaw('risk/getcertficates', params);
|
|
27
|
+
}
|
|
28
|
+
let response = yield this.request('risk/getcertficates', params);
|
|
29
|
+
if ('SUCCESS' !== response['return_code']) {
|
|
30
|
+
throw new Error(`Failed to get certificate. return_code_msg: "${response['return_code']}(${response['return_msg']})".`);
|
|
31
|
+
}
|
|
32
|
+
if ('SUCCESS' !== response['result_code']) {
|
|
33
|
+
throw new Error(`Failed to get certificate. result_err_code_desc: "${response['return_code']}(${response['err_code']}[${response['err_code_desc']}])".`);
|
|
34
|
+
}
|
|
35
|
+
let certificates = {};
|
|
36
|
+
try {
|
|
37
|
+
certificates = JSON.parse(response['certificates'])['data'][0];
|
|
38
|
+
}
|
|
39
|
+
catch (e) { }
|
|
40
|
+
let ciphertext = this.decrypt(certificates['encrypt_certificate']);
|
|
41
|
+
delete certificates['encrypt_certificate'];
|
|
42
|
+
certificates['certificates'] = ciphertext;
|
|
43
|
+
return certificates;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
decrypt(encryptCertificate) {
|
|
47
|
+
if (!encryptCertificate)
|
|
48
|
+
return null;
|
|
49
|
+
return AES_1.AES_GCM.decrypt(Buffer.from(encryptCertificate['ciphertext'], 'base64'), this.app.config.apiv3_key, encryptCertificate['nonce'], encryptCertificate['associated_data'], 'aes-256-gcm').toString();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = CertficatesClient;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import PaymentBaseClient from '../../Payment/Core/BaseClient';
|
|
2
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
3
|
+
declare class BaseClient extends PaymentBaseClient {
|
|
4
|
+
httpUpload(url: string, files?: object, form?: object, query?: object, returnResponse?: boolean): Promise<any>;
|
|
5
|
+
protected request(endpoint: string, params?: object, method?: string, options?: AxiosRequestConfig, returnResponse?: boolean): Promise<AxiosResponse<any>>;
|
|
6
|
+
protected processParams(params: object): object;
|
|
7
|
+
protected getSensitiveFieldsName(): string[];
|
|
8
|
+
}
|
|
9
|
+
export default BaseClient;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const BaseClient_1 = __importDefault(require("../../Payment/Core/BaseClient"));
|
|
16
|
+
const Utils_1 = require("../../Core/Utils");
|
|
17
|
+
const RSA_1 = __importDefault(require("../../Core/RSA"));
|
|
18
|
+
const fs_1 = __importDefault(require("fs"));
|
|
19
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
20
|
+
class BaseClient extends BaseClient_1.default {
|
|
21
|
+
httpUpload(url, files = {}, form = {}, query = {}, returnResponse = false) {
|
|
22
|
+
let formData = new form_data_1.default;
|
|
23
|
+
for (let name in files) {
|
|
24
|
+
if (Utils_1.isString(files[name])) {
|
|
25
|
+
formData.append(name, fs_1.default.createReadStream(files[name]));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
formData.append(name, files[name]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (let name in form) {
|
|
32
|
+
formData.append(name, form[name]);
|
|
33
|
+
}
|
|
34
|
+
return this.doRequest({
|
|
35
|
+
url,
|
|
36
|
+
data: formData,
|
|
37
|
+
method: 'POST',
|
|
38
|
+
params: query,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
request(endpoint, params = {}, method = 'post', options = {}, returnResponse = false) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
let base = {
|
|
44
|
+
mch_id: this.app.config.mch_id,
|
|
45
|
+
};
|
|
46
|
+
let localParams = Utils_1.merge(Utils_1.merge(base, this.prepends()), params);
|
|
47
|
+
let secretKey = yield this.app.getKey();
|
|
48
|
+
localParams['sign'] = Utils_1.makeSignature(localParams, secretKey, localParams['sign_type'] || 'MD5');
|
|
49
|
+
let payload = Utils_1.merge(Utils_1.merge({}, options), {
|
|
50
|
+
url: endpoint,
|
|
51
|
+
method,
|
|
52
|
+
responseType: 'text',
|
|
53
|
+
data: Utils_1.buildXml(localParams)
|
|
54
|
+
});
|
|
55
|
+
let response = yield this.doRequest(payload);
|
|
56
|
+
if (returnResponse) {
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
let body = response.data;
|
|
61
|
+
try {
|
|
62
|
+
body = yield Utils_1.parseXml(body);
|
|
63
|
+
}
|
|
64
|
+
catch (e) { }
|
|
65
|
+
return body;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
processParams(params) {
|
|
70
|
+
let serial_no = this.app.config.serial_no;
|
|
71
|
+
if (serial_no == undefined || serial_no == null) {
|
|
72
|
+
throw new Error('Config `serial_no` connot be empty.');
|
|
73
|
+
}
|
|
74
|
+
let certificate = this.app.config.certificate;
|
|
75
|
+
if (certificate == undefined || certificate == null) {
|
|
76
|
+
throw new Error('Config `certificate` connot be empty.');
|
|
77
|
+
}
|
|
78
|
+
let rsa = new RSA_1.default;
|
|
79
|
+
rsa.setPublicKey(certificate);
|
|
80
|
+
let newParams = Utils_1.merge({}, params);
|
|
81
|
+
newParams['cert_sn'] = serial_no;
|
|
82
|
+
let sensitive_fields = this.getSensitiveFieldsName();
|
|
83
|
+
for (let k in newParams) {
|
|
84
|
+
if (Utils_1.inArray(k, sensitive_fields)) {
|
|
85
|
+
newParams[k] = rsa.encrypt(newParams[k]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return newParams;
|
|
89
|
+
}
|
|
90
|
+
getSensitiveFieldsName() {
|
|
91
|
+
return [
|
|
92
|
+
'id_card_name',
|
|
93
|
+
'id_card_number',
|
|
94
|
+
'account_name',
|
|
95
|
+
'account_number',
|
|
96
|
+
'contact',
|
|
97
|
+
'contact_phone',
|
|
98
|
+
'contact_email',
|
|
99
|
+
'legal_person',
|
|
100
|
+
'mobile_phone',
|
|
101
|
+
'email',
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
;
|
|
106
|
+
exports.default = BaseClient;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const Utils_1 = require("../../Core/Utils");
|
|
16
|
+
const BaseClient_1 = __importDefault(require("../Core/BaseClient"));
|
|
17
|
+
class MediaClient extends BaseClient_1.default {
|
|
18
|
+
upload(file) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
if (!file) {
|
|
21
|
+
throw new Error(`File does not exist, or the file is unreadable: '${file}'`);
|
|
22
|
+
}
|
|
23
|
+
let form = {
|
|
24
|
+
media_hash: yield Utils_1.md5File(file),
|
|
25
|
+
sign_type: 'HMAC-SHA256',
|
|
26
|
+
};
|
|
27
|
+
return this.httpUpload('secapi/mch/uploadmedia', {
|
|
28
|
+
media: file
|
|
29
|
+
}, form);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.default = MediaClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import BaseClient from '../Core/BaseClient';
|
|
2
|
+
export default class MerchantConfigClient extends BaseClient {
|
|
3
|
+
setFollowConfig(subAppId: string, subscribeAppId: string, receiptAppId?: string, subMchId?: string): Promise<any>;
|
|
4
|
+
addPath(jsapiPath: string, appId?: string, subMchId?: string): Promise<any>;
|
|
5
|
+
bindAppId(subAppId: string, appId?: string, subMchId?: string): Promise<any>;
|
|
6
|
+
private addConfig;
|
|
7
|
+
getConfig(subMchId: string, appId: string): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Utils_1 = require("../../Core/Utils");
|
|
7
|
+
const BaseClient_1 = __importDefault(require("../Core/BaseClient"));
|
|
8
|
+
class MerchantConfigClient extends BaseClient_1.default {
|
|
9
|
+
setFollowConfig(subAppId, subscribeAppId, receiptAppId = '', subMchId = '') {
|
|
10
|
+
let params = {
|
|
11
|
+
sub_appid: subAppId,
|
|
12
|
+
sub_mch_id: subMchId || this.app.config.sub_mch_id,
|
|
13
|
+
sign_type: 'HMAC-SHA256',
|
|
14
|
+
nonce_str: Utils_1.randomString(18),
|
|
15
|
+
};
|
|
16
|
+
if (subscribeAppId) {
|
|
17
|
+
params['subscribe_appid'] = subscribeAppId;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
params['receipt_appid'] = receiptAppId;
|
|
21
|
+
}
|
|
22
|
+
return this.safeRequest('secapi/mkt/addrecommendconf', params);
|
|
23
|
+
}
|
|
24
|
+
addPath(jsapiPath, appId = '', subMchId = '') {
|
|
25
|
+
return this.addConfig({
|
|
26
|
+
appid: appId || this.app.config.appid,
|
|
27
|
+
sub_mch_id: subMchId || this.app.config.sub_mch_id,
|
|
28
|
+
jsapi_path: jsapiPath,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
bindAppId(subAppId, appId = '', subMchId = '') {
|
|
32
|
+
return this.addConfig({
|
|
33
|
+
appid: appId || this.app.config.appid,
|
|
34
|
+
sub_mch_id: subMchId || this.app.config.sub_mch_id,
|
|
35
|
+
sub_appid: subAppId,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
addConfig(params) {
|
|
39
|
+
return this.safeRequest('secapi/mch/addsubdevconfig', params);
|
|
40
|
+
}
|
|
41
|
+
getConfig(subMchId, appId) {
|
|
42
|
+
let params = {
|
|
43
|
+
sub_mch_id: subMchId || this.app.config.sub_mch_id,
|
|
44
|
+
appid: appId || this.app.config.appid,
|
|
45
|
+
};
|
|
46
|
+
return this.safeRequest('secapi/mch/querysubdevconfig', params);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = MerchantConfigClient;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Utils_1 = require("../../Core/Utils");
|
|
7
|
+
const BaseClient_1 = __importDefault(require("../Core/BaseClient"));
|
|
8
|
+
class MeterialClient extends BaseClient_1.default {
|
|
9
|
+
setSettlementCard(params) {
|
|
10
|
+
let newParams = this.processParams(Utils_1.merge(Utils_1.merge({}, params), {
|
|
11
|
+
sub_mch_id: params['sub_mch_id'] || this.app.config.sub_mch_id,
|
|
12
|
+
version: '1.0',
|
|
13
|
+
cert_sn: '',
|
|
14
|
+
sign_type: 'HMAC-SHA256',
|
|
15
|
+
nonce_str: Utils_1.randomString(18),
|
|
16
|
+
}));
|
|
17
|
+
return this.safeRequest('applyment/micro/modifyarchives', newParams);
|
|
18
|
+
}
|
|
19
|
+
updateContact(params) {
|
|
20
|
+
let newParams = this.processParams(Utils_1.merge(Utils_1.merge({}, params), {
|
|
21
|
+
sub_mch_id: params['sub_mch_id'] || this.app.config.sub_mch_id,
|
|
22
|
+
version: '1.0',
|
|
23
|
+
cert_sn: '',
|
|
24
|
+
sign_type: 'HMAC-SHA256',
|
|
25
|
+
nonce_str: Utils_1.randomString(18),
|
|
26
|
+
}));
|
|
27
|
+
return this.safeRequest('applyment/micro/modifycontactinfo', newParams);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.default = MeterialClient;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Utils_1 = require("../../Core/Utils");
|
|
7
|
+
const BaseClient_1 = __importDefault(require("../Core/BaseClient"));
|
|
8
|
+
class WithdrawClient extends BaseClient_1.default {
|
|
9
|
+
queryWithdrawalStatus(date, subMchId) {
|
|
10
|
+
let params = {
|
|
11
|
+
date,
|
|
12
|
+
sub_mch_id: subMchId || this.app.config.sub_mch_id,
|
|
13
|
+
sign_type: 'HMAC-SHA256',
|
|
14
|
+
nonce_str: Utils_1.randomString(18),
|
|
15
|
+
};
|
|
16
|
+
return this.safeRequest('fund/queryautowithdrawbydate', params);
|
|
17
|
+
}
|
|
18
|
+
requestWithdraw(date, subMchId) {
|
|
19
|
+
let params = {
|
|
20
|
+
date,
|
|
21
|
+
sub_mch_id: subMchId || this.app.config.sub_mch_id,
|
|
22
|
+
sign_type: 'HMAC-SHA256',
|
|
23
|
+
nonce_str: Utils_1.randomString(18),
|
|
24
|
+
};
|
|
25
|
+
return this.safeRequest('fund/reautowithdrawbydate', params);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.default = WithdrawClient;
|
|
@@ -3,18 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
7
6
|
const Encryptor_1 = __importDefault(require("../Core/Encryptor"));
|
|
7
|
+
const AES_1 = require("../Core/AES");
|
|
8
8
|
class Encryptor extends Encryptor_1.default {
|
|
9
9
|
decryptData(sessionKey, iv, encryptData) {
|
|
10
10
|
let decoded = null;
|
|
11
11
|
try {
|
|
12
12
|
// 解密
|
|
13
|
-
|
|
14
|
-
// 设置自动 padding 为 true,删除填充补位
|
|
15
|
-
decipher.setAutoPadding(true);
|
|
16
|
-
decoded = decipher.update(Buffer.from(encryptData, 'base64'), 'binary', 'utf8');
|
|
17
|
-
decoded += decipher.final('utf8');
|
|
13
|
+
decoded = AES_1.AES.decrypt(Buffer.from(encryptData, 'base64'), Buffer.from(sessionKey, 'base64'), Buffer.from(iv, 'base64'), true, 'aes-128-cbc').toString('utf8');
|
|
18
14
|
decoded = JSON.parse(decoded);
|
|
19
15
|
}
|
|
20
16
|
catch (e) {
|
|
@@ -34,7 +34,7 @@ class BillClient extends BaseClient_1.default {
|
|
|
34
34
|
let res = yield this.requestRaw(this.wrap('pay/downloadbill'), params);
|
|
35
35
|
let content = res.getContent().toString();
|
|
36
36
|
if (content && content.indexOf('<xml>') === 0) {
|
|
37
|
-
return yield
|
|
37
|
+
return yield Utils_1.parseXml(content);
|
|
38
38
|
}
|
|
39
39
|
return StreamResponse_1.default.buildFromResponse(res);
|
|
40
40
|
});
|
|
@@ -7,7 +7,6 @@ declare class BaseClient implements HttpMixin {
|
|
|
7
7
|
constructor(app: BaseApplication);
|
|
8
8
|
protected prepends(): {};
|
|
9
9
|
protected request(endpoint: string, params?: object, method?: string, options?: AxiosRequestConfig, returnResponse?: boolean): Promise<AxiosResponse<any>>;
|
|
10
|
-
parseXml(xml: string): Promise<any>;
|
|
11
10
|
protected safeRequest(endpoint: string, params?: object, method?: string, options?: AxiosRequestConfig): Promise<any>;
|
|
12
11
|
protected requestRaw(endpoint: string, params?: object, method?: string, options?: AxiosRequestConfig): Promise<any>;
|
|
13
12
|
protected wrap(endpoint: string): string;
|
|
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const HttpMixin_1 = __importDefault(require("../../Core/Mixins/HttpMixin"));
|
|
16
16
|
const Utils_1 = require("../../Core/Utils");
|
|
17
|
-
const xml2js_1 = __importDefault(require("xml2js"));
|
|
18
17
|
const fs_1 = __importDefault(require("fs"));
|
|
19
18
|
const Response_1 = __importDefault(require("../../Core/Http/Response"));
|
|
20
19
|
const https_1 = __importDefault(require("https"));
|
|
@@ -42,19 +41,11 @@ class BaseClient {
|
|
|
42
41
|
let localParams = Utils_1.merge(Utils_1.merge(base, this.prepends()), params);
|
|
43
42
|
let secretKey = yield this.app.getKey(endpoint);
|
|
44
43
|
localParams['sign'] = Utils_1.makeSignature(localParams, secretKey, localParams['sign_type'] || 'MD5');
|
|
45
|
-
let XmlBuilder = new xml2js_1.default.Builder({
|
|
46
|
-
cdata: true,
|
|
47
|
-
renderOpts: {
|
|
48
|
-
pretty: false,
|
|
49
|
-
indent: '',
|
|
50
|
-
newline: '',
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
44
|
let payload = Utils_1.merge(Utils_1.merge({}, options), {
|
|
54
45
|
url: endpoint,
|
|
55
46
|
method,
|
|
56
47
|
responseType: 'text',
|
|
57
|
-
data:
|
|
48
|
+
data: Utils_1.buildXml(localParams)
|
|
58
49
|
});
|
|
59
50
|
let response = yield this.doRequest(payload);
|
|
60
51
|
if (returnResponse) {
|
|
@@ -63,22 +54,13 @@ class BaseClient {
|
|
|
63
54
|
else {
|
|
64
55
|
let body = response.data;
|
|
65
56
|
try {
|
|
66
|
-
body = yield
|
|
57
|
+
body = yield Utils_1.parseXml(body);
|
|
67
58
|
}
|
|
68
59
|
catch (e) { }
|
|
69
60
|
return body;
|
|
70
61
|
}
|
|
71
62
|
});
|
|
72
63
|
}
|
|
73
|
-
parseXml(xml) {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
let res = yield xml2js_1.default.parseStringPromise(xml);
|
|
76
|
-
res = Utils_1.singleItem(res);
|
|
77
|
-
if (res['xml'])
|
|
78
|
-
res = res['xml'];
|
|
79
|
-
return res;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
64
|
safeRequest(endpoint, params = {}, method = 'post', options = {}) {
|
|
83
65
|
options = Utils_1.merge(Utils_1.merge({}, options), {
|
|
84
66
|
httpsAgent: new https_1.default.Agent({
|