node-easywechat 2.6.10 → 2.8.0
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 +26 -3
- 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/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 +24 -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/Application.d.ts +4 -0
- package/dist/MiniProgram/Application.js +10 -0
- package/dist/MiniProgram/Encryptor.js +2 -6
- package/dist/MiniProgram/PhoneNumber/PhoneNumberClient.d.ts +10 -0
- package/dist/MiniProgram/PhoneNumber/PhoneNumberClient.js +20 -0
- package/dist/MiniProgram/Union/UnionClient.d.ts +3 -0
- package/dist/MiniProgram/Union/UnionClient.js +9 -0
- package/dist/MiniProgram/UrlLink/UrlLinkClient.d.ts +4 -0
- package/dist/MiniProgram/UrlLink/UrlLinkClient.js +12 -0
- 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/Jssdk/JssdkClient.d.ts +12 -0
- package/dist/Payment/Jssdk/JssdkClient.js +32 -0
- 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/Work/ExternalContact/Client.d.ts +146 -3
- package/dist/Work/ExternalContact/Client.js +156 -6
- package/dist/Work/ExternalContact/MessageClient.d.ts +45 -0
- package/dist/Work/ExternalContact/MessageClient.js +86 -0
- 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 +4 -5
|
@@ -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;
|
|
@@ -10,6 +10,7 @@ import CustomerServiceClient from '../OfficialAccount/CustomerService/CustomerSe
|
|
|
10
10
|
import UniformMessageClient from './UniformMessage/UniformMessageClient';
|
|
11
11
|
import ActivityMessageClient from './ActivityMessage/ActivityMessageClient';
|
|
12
12
|
import OpenDataClient from './OpenData/OpenDataClient';
|
|
13
|
+
import PhoneNumberClient from './PhoneNumber/PhoneNumberClient';
|
|
13
14
|
import PluginClient from './Plugin/PluginClient';
|
|
14
15
|
import PluginDevClient from './Plugin/PluginDevClient';
|
|
15
16
|
import MiniProgramBase from './Base/MiniProgramBase';
|
|
@@ -23,6 +24,7 @@ import SearchClient from './Search/SearchClient';
|
|
|
23
24
|
import MediaClient from '../BaseService/Media/MediaClient';
|
|
24
25
|
import ContentSecurityClient from '../BaseService/ContentSecurity/ContentSecurityClient';
|
|
25
26
|
import { EasyWechatConfig } from '../Core/Types';
|
|
27
|
+
import UrlLinkClient from './UrlLink/UrlLinkClient';
|
|
26
28
|
import UrlSchemeClient from './UrlScheme/UrlSchemeClient';
|
|
27
29
|
import RiskControlClient from './RiskControl/RiskControlClient';
|
|
28
30
|
import LiveClient from './Live/LiveClient';
|
|
@@ -40,6 +42,7 @@ export default class MiniProgram extends BaseApplication {
|
|
|
40
42
|
uniform_message: UniformMessageClient;
|
|
41
43
|
activity_message: ActivityMessageClient;
|
|
42
44
|
open_data: OpenDataClient;
|
|
45
|
+
phone_number: PhoneNumberClient;
|
|
43
46
|
plugin: PluginClient;
|
|
44
47
|
plugin_dev: PluginDevClient;
|
|
45
48
|
base: MiniProgramBase;
|
|
@@ -52,6 +55,7 @@ export default class MiniProgram extends BaseApplication {
|
|
|
52
55
|
search: SearchClient;
|
|
53
56
|
media: MediaClient;
|
|
54
57
|
content_security: ContentSecurityClient;
|
|
58
|
+
url_link: UrlLinkClient;
|
|
55
59
|
url_scheme: UrlSchemeClient;
|
|
56
60
|
risk_control: RiskControlClient;
|
|
57
61
|
live: LiveClient;
|
|
@@ -24,6 +24,7 @@ const CustomerServiceClient_1 = __importDefault(require("../OfficialAccount/Cust
|
|
|
24
24
|
const UniformMessageClient_1 = __importDefault(require("./UniformMessage/UniformMessageClient"));
|
|
25
25
|
const ActivityMessageClient_1 = __importDefault(require("./ActivityMessage/ActivityMessageClient"));
|
|
26
26
|
const OpenDataClient_1 = __importDefault(require("./OpenData/OpenDataClient"));
|
|
27
|
+
const PhoneNumberClient_1 = __importDefault(require("./PhoneNumber/PhoneNumberClient"));
|
|
27
28
|
const PluginClient_1 = __importDefault(require("./Plugin/PluginClient"));
|
|
28
29
|
const PluginDevClient_1 = __importDefault(require("./Plugin/PluginDevClient"));
|
|
29
30
|
const MiniProgramBase_1 = __importDefault(require("./Base/MiniProgramBase"));
|
|
@@ -36,6 +37,7 @@ const RealtimeLogClient_1 = __importDefault(require("./RealtimeLog/RealtimeLogCl
|
|
|
36
37
|
const SearchClient_1 = __importDefault(require("./Search/SearchClient"));
|
|
37
38
|
const MediaClient_1 = __importDefault(require("../BaseService/Media/MediaClient"));
|
|
38
39
|
const ContentSecurityClient_1 = __importDefault(require("../BaseService/ContentSecurity/ContentSecurityClient"));
|
|
40
|
+
const UrlLinkClient_1 = __importDefault(require("./UrlLink/UrlLinkClient"));
|
|
39
41
|
const UrlSchemeClient_1 = __importDefault(require("./UrlScheme/UrlSchemeClient"));
|
|
40
42
|
const RiskControlClient_1 = __importDefault(require("./RiskControl/RiskControlClient"));
|
|
41
43
|
const LiveClient_1 = __importDefault(require("./Live/LiveClient"));
|
|
@@ -55,6 +57,7 @@ class MiniProgram extends BaseApplication_1.default {
|
|
|
55
57
|
this.uniform_message = null;
|
|
56
58
|
this.activity_message = null;
|
|
57
59
|
this.open_data = null;
|
|
60
|
+
this.phone_number = null;
|
|
58
61
|
this.plugin = null;
|
|
59
62
|
this.plugin_dev = null;
|
|
60
63
|
this.base = null;
|
|
@@ -67,6 +70,7 @@ class MiniProgram extends BaseApplication_1.default {
|
|
|
67
70
|
this.search = null;
|
|
68
71
|
this.media = null;
|
|
69
72
|
this.content_security = null;
|
|
73
|
+
this.url_link = null;
|
|
70
74
|
this.url_scheme = null;
|
|
71
75
|
this.risk_control = null;
|
|
72
76
|
this.live = null;
|
|
@@ -126,6 +130,9 @@ class MiniProgram extends BaseApplication_1.default {
|
|
|
126
130
|
this.offsetSet('open_data', function (app) {
|
|
127
131
|
return new OpenDataClient_1.default(app);
|
|
128
132
|
});
|
|
133
|
+
this.offsetSet('phone_number', function (app) {
|
|
134
|
+
return new PhoneNumberClient_1.default(app);
|
|
135
|
+
});
|
|
129
136
|
this.offsetSet('plugin', function (app) {
|
|
130
137
|
return new PluginClient_1.default(app);
|
|
131
138
|
});
|
|
@@ -156,6 +163,9 @@ class MiniProgram extends BaseApplication_1.default {
|
|
|
156
163
|
this.offsetSet('search', function (app) {
|
|
157
164
|
return new SearchClient_1.default(app);
|
|
158
165
|
});
|
|
166
|
+
this.offsetSet('url_link', function (app) {
|
|
167
|
+
return new UrlLinkClient_1.default(app);
|
|
168
|
+
});
|
|
159
169
|
this.offsetSet('url_scheme', function (app) {
|
|
160
170
|
return new UrlSchemeClient_1.default(app);
|
|
161
171
|
});
|
|
@@ -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) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import BaseClient from '../../Core/BaseClient';
|
|
2
|
+
export default class PhoneNumber extends BaseClient {
|
|
3
|
+
/**
|
|
4
|
+
* 获取用户手机号
|
|
5
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html
|
|
6
|
+
* @param code [前端获取code方法](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html)
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
getUserPhoneNumber(code: string): Promise<any>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 BaseClient_1 = __importDefault(require("../../Core/BaseClient"));
|
|
7
|
+
class PhoneNumber extends BaseClient_1.default {
|
|
8
|
+
/**
|
|
9
|
+
* 获取用户手机号
|
|
10
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html
|
|
11
|
+
* @param code [前端获取code方法](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html)
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
getUserPhoneNumber(code) {
|
|
15
|
+
return this.httpPostJson('wxa/business/getuserphonenumber', {
|
|
16
|
+
code
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = PhoneNumber;
|