node-easywechat 3.0.0-beta.4 → 3.0.1
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/CHANGELOG.md +30 -0
- package/README.md +36 -1
- package/dist/Core/Contracts/RefreshableAccessTokenInterface.d.ts +2 -2
- package/dist/Core/Contracts/RefreshableAccessTokenInterface.js +2 -2
- package/dist/Core/Http/Minxins/MessageMixin.js +1 -2
- package/dist/Core/Http/ServerRequest.d.ts +1 -1
- package/dist/Core/Http/ServerRequest.js +16 -6
- package/dist/Core/HttpClient/HttpClient.js +3 -1
- package/dist/Core/HttpClient/HttpClientResponse.d.ts +16 -5
- package/dist/Core/HttpClient/HttpClientResponse.js +64 -22
- package/dist/Core/HttpClient/Mixins/PresetMixin.d.ts +0 -12
- package/dist/Core/HttpClient/Mixins/PresetMixin.js +0 -18
- package/dist/Core/Message.d.ts +0 -127
- package/dist/Core/Message.js +5 -1
- package/dist/Core/Mixins/DecryptXmlMessageMixin.js +1 -1
- package/dist/Core/Mixins/ResponseXmlMessageMixin.js +2 -2
- package/dist/Core/Support/PrivateKey.d.ts +20 -0
- package/dist/Core/Support/PrivateKey.js +38 -0
- package/dist/Core/Support/PublicKey.d.ts +14 -0
- package/dist/Core/Support/PublicKey.js +36 -0
- package/dist/Core/Support/RSA.d.ts +2 -2
- package/dist/Core/Support/RSA.js +4 -4
- package/dist/Core/Support/Utils.d.ts +6 -0
- package/dist/Core/Support/Utils.js +15 -1
- package/dist/MiniApp/Application.d.ts +4 -4
- package/dist/MiniApp/Contracts/ApplicationInterface.d.ts +2 -2
- package/dist/OfficialAccount/AccessToken.d.ts +2 -2
- package/dist/OfficialAccount/AccessToken.js +2 -2
- package/dist/OfficialAccount/Application.d.ts +4 -4
- package/dist/OfficialAccount/Application.js +0 -5
- package/dist/OfficialAccount/Contracts/ApplicationInterface.d.ts +2 -2
- package/dist/OfficialAccount/JsApiTicket.js +2 -2
- package/dist/OfficialAccount/Message.d.ts +139 -0
- package/dist/OfficialAccount/Message.js +1 -0
- package/dist/Pay/Application.d.ts +52 -0
- package/dist/Pay/Application.js +96 -0
- package/dist/Pay/Client.d.ts +54 -0
- package/dist/Pay/Client.js +146 -0
- package/dist/Pay/Config.d.ts +5 -0
- package/dist/Pay/Config.js +17 -0
- package/dist/Pay/Contracts/ApplicationInterface.d.ts +50 -0
- package/dist/Pay/Contracts/ApplicationInterface.js +45 -0
- package/dist/Pay/Contracts/MerchantInterface.d.ts +35 -0
- package/dist/Pay/Contracts/MerchantInterface.js +35 -0
- package/dist/Pay/Contracts/ResponseValidatorInterface.d.ts +9 -0
- package/dist/Pay/Contracts/ResponseValidatorInterface.js +10 -0
- package/dist/Pay/LegacySignature.d.ts +12 -0
- package/dist/Pay/LegacySignature.js +59 -0
- package/dist/Pay/Merchant.d.ts +25 -0
- package/dist/Pay/Merchant.js +53 -0
- package/dist/Pay/Message.d.ts +175 -0
- package/dist/Pay/Message.js +24 -0
- package/dist/Pay/Server.d.ts +41 -0
- package/dist/Pay/Server.js +122 -0
- package/dist/Pay/Signature.d.ts +15 -0
- package/dist/Pay/Signature.js +44 -0
- package/dist/Pay/Utils.d.ts +54 -0
- package/dist/Pay/Utils.js +142 -0
- package/dist/Types/global.d.ts +110 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
exports.PublicKey = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
class PublicKey {
|
|
10
|
+
constructor(certificate) {
|
|
11
|
+
this.certificate = certificate;
|
|
12
|
+
if (fs_1.default.existsSync(certificate)) {
|
|
13
|
+
this.certificate = fs_1.default.readFileSync(certificate, 'utf8') || '';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 获取公钥的序列号
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
getSerialNo() {
|
|
21
|
+
try {
|
|
22
|
+
return new crypto_1.X509Certificate(this.certificate).serialNumber;
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
throw new Error('Read the $certificate failed, please check it whether or nor correct');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 转为字符串
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
toString() {
|
|
33
|
+
return this.certificate;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.PublicKey = PublicKey;
|
|
@@ -23,7 +23,7 @@ declare class RSA {
|
|
|
23
23
|
* 加密
|
|
24
24
|
* @param plaintext 待加密文本
|
|
25
25
|
* @param encoding 编码,默认:'base64'
|
|
26
|
-
* @param hashType 哈希方式,默认:'
|
|
26
|
+
* @param hashType 哈希方式,默认:'sha256'
|
|
27
27
|
* @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_OAEP_PADDING
|
|
28
28
|
* @returns
|
|
29
29
|
*/
|
|
@@ -32,7 +32,7 @@ declare class RSA {
|
|
|
32
32
|
* 解密
|
|
33
33
|
* @param ciphertext 待解密文本
|
|
34
34
|
* @param encoding 编码,默认:'base64'
|
|
35
|
-
* @param hashType 哈希方式,默认:'
|
|
35
|
+
* @param hashType 哈希方式,默认:'sha256'
|
|
36
36
|
* @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_OAEP_PADDING
|
|
37
37
|
* @returns
|
|
38
38
|
*/
|
package/dist/Core/Support/RSA.js
CHANGED
|
@@ -34,11 +34,11 @@ class RSA {
|
|
|
34
34
|
* 加密
|
|
35
35
|
* @param plaintext 待加密文本
|
|
36
36
|
* @param encoding 编码,默认:'base64'
|
|
37
|
-
* @param hashType 哈希方式,默认:'
|
|
37
|
+
* @param hashType 哈希方式,默认:'sha256'
|
|
38
38
|
* @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_OAEP_PADDING
|
|
39
39
|
* @returns
|
|
40
40
|
*/
|
|
41
|
-
encrypt(plaintext, encoding = 'base64', hashType = '
|
|
41
|
+
encrypt(plaintext, encoding = 'base64', hashType = 'sha256', padding = crypto_1.default.constants.RSA_PKCS1_OAEP_PADDING) {
|
|
42
42
|
let encryptedData = crypto_1.default.publicEncrypt({
|
|
43
43
|
key: this.publicKey,
|
|
44
44
|
padding,
|
|
@@ -50,11 +50,11 @@ class RSA {
|
|
|
50
50
|
* 解密
|
|
51
51
|
* @param ciphertext 待解密文本
|
|
52
52
|
* @param encoding 编码,默认:'base64'
|
|
53
|
-
* @param hashType 哈希方式,默认:'
|
|
53
|
+
* @param hashType 哈希方式,默认:'sha256'
|
|
54
54
|
* @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_OAEP_PADDING
|
|
55
55
|
* @returns
|
|
56
56
|
*/
|
|
57
|
-
decrypt(ciphertext, encoding = 'base64', hashType = '
|
|
57
|
+
decrypt(ciphertext, encoding = 'base64', hashType = 'sha256', padding = crypto_1.default.constants.RSA_PKCS1_OAEP_PADDING) {
|
|
58
58
|
let decryptedData = crypto_1.default.privateDecrypt({
|
|
59
59
|
key: this.privateKey,
|
|
60
60
|
padding,
|
|
@@ -93,3 +93,9 @@ export declare const parseXml: (xml: string) => Promise<Record<string, any>>;
|
|
|
93
93
|
* @returns
|
|
94
94
|
*/
|
|
95
95
|
export declare const buildXml: (data: Record<string, any>, rootName?: string) => string;
|
|
96
|
+
/**
|
|
97
|
+
* 创建UserAgent
|
|
98
|
+
* @param appends 可选,附加的字符串列表
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export declare const createUserAgent: (appends?: string[]) => string;
|
|
@@ -12,12 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.buildXml = exports.parseXml = exports.singleItem = exports.strSnake = exports.strCamel = exports.strStudly = exports.strLcwords = exports.strUcwords = exports.rtrim = exports.ltrim = exports.trim = exports.applyMixins = exports.inArray = exports.isIp = exports.isIpv6 = exports.isIpv4 = exports.isFunction = exports.isObject = exports.isNumber = exports.isArray = exports.isString = exports.makeSignature = exports.randomString = exports.parseQueryString = exports.buildQueryString = exports.getTimestamp = exports.md5File = exports.createHmac = exports.createHash = void 0;
|
|
15
|
+
exports.createUserAgent = exports.buildXml = exports.parseXml = exports.singleItem = exports.strSnake = exports.strCamel = exports.strStudly = exports.strLcwords = exports.strUcwords = exports.rtrim = exports.ltrim = exports.trim = exports.applyMixins = exports.inArray = exports.isIp = exports.isIpv6 = exports.isIpv4 = exports.isFunction = exports.isObject = exports.isNumber = exports.isArray = exports.isString = exports.makeSignature = exports.randomString = exports.parseQueryString = exports.buildQueryString = exports.getTimestamp = exports.md5File = exports.createHmac = exports.createHash = void 0;
|
|
16
16
|
const crypto_1 = __importDefault(require("crypto"));
|
|
17
17
|
const qs_1 = __importDefault(require("qs"));
|
|
18
18
|
const xml2js_1 = __importDefault(require("xml2js"));
|
|
19
19
|
const stream_1 = __importDefault(require("stream"));
|
|
20
20
|
const fs_1 = __importDefault(require("fs"));
|
|
21
|
+
const axios_1 = __importDefault(require("axios"));
|
|
21
22
|
const createHash = function (str, type = 'sha1') {
|
|
22
23
|
return crypto_1.default.createHash(type).update(str).digest('hex');
|
|
23
24
|
};
|
|
@@ -321,3 +322,16 @@ const buildXml = function (data, rootName = 'xml') {
|
|
|
321
322
|
return XmlBuilder.buildObject(data).replace('<?xml version="1.0"?>', '');
|
|
322
323
|
};
|
|
323
324
|
exports.buildXml = buildXml;
|
|
325
|
+
/**
|
|
326
|
+
* 创建UserAgent
|
|
327
|
+
* @param appends 可选,附加的字符串列表
|
|
328
|
+
* @returns
|
|
329
|
+
*/
|
|
330
|
+
const createUserAgent = function (appends = []) {
|
|
331
|
+
let values = [];
|
|
332
|
+
values.push(`node-easywechat/${require('../../../package.json').version}`);
|
|
333
|
+
values.push(`axios/${axios_1.default.VERSION}`);
|
|
334
|
+
values = values.concat(appends);
|
|
335
|
+
return values.join(' ');
|
|
336
|
+
};
|
|
337
|
+
exports.createUserAgent = createUserAgent;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import AccessTokenInterface from '../Core/Contracts/AccessTokenInterface';
|
|
2
1
|
import ConfigInterface from '../Core/Contracts/ConfigInterface';
|
|
3
2
|
import ServerInterface from '../Core/Contracts/ServerInterface';
|
|
4
3
|
import Encryptor from '../Core/Encryptor';
|
|
@@ -12,6 +11,7 @@ import { MiniAppConfig } from '../Types/global';
|
|
|
12
11
|
import AccountInterface from './Contracts/AccountInterface';
|
|
13
12
|
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
14
13
|
import Utils from './Utils';
|
|
14
|
+
import RefreshableAccessTokenInterface from '../Core/Contracts/RefreshableAccessTokenInterface';
|
|
15
15
|
/**
|
|
16
16
|
* 小程序应用
|
|
17
17
|
*/
|
|
@@ -20,7 +20,7 @@ declare class Application implements ApplicationInterface {
|
|
|
20
20
|
protected account: AccountInterface;
|
|
21
21
|
protected encryptor: Encryptor;
|
|
22
22
|
protected server: ServerInterface;
|
|
23
|
-
protected accessToken:
|
|
23
|
+
protected accessToken: RefreshableAccessTokenInterface;
|
|
24
24
|
getAccount(): AccountInterface;
|
|
25
25
|
/**
|
|
26
26
|
* 设置当前账户实例
|
|
@@ -42,13 +42,13 @@ declare class Application implements ApplicationInterface {
|
|
|
42
42
|
* @returns
|
|
43
43
|
*/
|
|
44
44
|
setServer(server: ServerInterface): this;
|
|
45
|
-
getAccessToken():
|
|
45
|
+
getAccessToken(): RefreshableAccessTokenInterface;
|
|
46
46
|
/**
|
|
47
47
|
* 设置AccessToken实例
|
|
48
48
|
* @param accessToken
|
|
49
49
|
* @returns
|
|
50
50
|
*/
|
|
51
|
-
setAccessToken(accessToken:
|
|
51
|
+
setAccessToken(accessToken: RefreshableAccessTokenInterface): this;
|
|
52
52
|
getUtils(): Utils;
|
|
53
53
|
createClient(): AccessTokenAwareClient;
|
|
54
54
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
|
|
2
1
|
import CacheInterface from "../../Core/Contracts/CacheInterface";
|
|
3
2
|
import ConfigInterface from "../../Core/Contracts/ConfigInterface";
|
|
4
3
|
import AccessTokenAwareClient from "../../Core/HttpClient/AccessTokenAwareClient";
|
|
@@ -8,6 +7,7 @@ import ServerRequestInterface from "../../Core/Http/Contracts/ServerRequestInter
|
|
|
8
7
|
import Encryptor from "../../Core/Encryptor";
|
|
9
8
|
import AccountInterface from "./AccountInterface";
|
|
10
9
|
import Utils from "../Utils";
|
|
10
|
+
import RefreshableAccessTokenInterface from "../../Core/Contracts/RefreshableAccessTokenInterface";
|
|
11
11
|
declare abstract class ApplicationInterface {
|
|
12
12
|
/**
|
|
13
13
|
* 获取当前账户实例
|
|
@@ -53,7 +53,7 @@ declare abstract class ApplicationInterface {
|
|
|
53
53
|
* 获取AccessToken实例
|
|
54
54
|
* @returns
|
|
55
55
|
*/
|
|
56
|
-
getAccessToken():
|
|
56
|
+
getAccessToken(): RefreshableAccessTokenInterface;
|
|
57
57
|
/**
|
|
58
58
|
* 获取缓存实例
|
|
59
59
|
* @returns
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import CacheInterface from "../Core/Contracts/CacheInterface";
|
|
2
2
|
import HttpClientInterface from "../Core/HttpClient/Contracts/HttpClientInterface";
|
|
3
|
-
import
|
|
4
|
-
declare class AccessToken implements
|
|
3
|
+
import RefreshableAccessTokenInterface from "../Core/Contracts/RefreshableAccessTokenInterface";
|
|
4
|
+
declare class AccessToken implements RefreshableAccessTokenInterface {
|
|
5
5
|
protected appId: string;
|
|
6
6
|
protected secret: string;
|
|
7
7
|
protected key: string;
|
|
@@ -66,13 +66,13 @@ class AccessToken {
|
|
|
66
66
|
}
|
|
67
67
|
refresh() {
|
|
68
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
let response =
|
|
69
|
+
let response = (yield this.httpClient.request('get', 'cgi-bin/token', {
|
|
70
70
|
params: {
|
|
71
71
|
grant_type: 'client_credential',
|
|
72
72
|
appid: this.appId,
|
|
73
73
|
secret: this.secret,
|
|
74
74
|
}
|
|
75
|
-
})).toObject(
|
|
75
|
+
})).toObject();
|
|
76
76
|
if (!response['access_token']) {
|
|
77
77
|
throw new Error('Failed to get access_token: ' + JSON.stringify(response));
|
|
78
78
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import ProviderInterface from 'node-socialite/dist/Core/ProviderInterface';
|
|
2
|
-
import AccessTokenInterface from '../Core/Contracts/AccessTokenInterface';
|
|
3
2
|
import ConfigInterface from '../Core/Contracts/ConfigInterface';
|
|
4
3
|
import ServerInterface from '../Core/Contracts/ServerInterface';
|
|
5
4
|
import Encryptor from '../Core/Encryptor';
|
|
@@ -14,6 +13,7 @@ import AccountInterface from './Contracts/AccountInterface';
|
|
|
14
13
|
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
15
14
|
import JsApiTicket from './JsApiTicket';
|
|
16
15
|
import Utils from './Utils';
|
|
16
|
+
import RefreshableAccessTokenInterface from '../Core/Contracts/RefreshableAccessTokenInterface';
|
|
17
17
|
/**
|
|
18
18
|
* 公众号应用
|
|
19
19
|
*/
|
|
@@ -22,7 +22,7 @@ declare class Application implements ApplicationInterface {
|
|
|
22
22
|
protected account: AccountInterface;
|
|
23
23
|
protected encryptor: Encryptor;
|
|
24
24
|
protected server: ServerInterface;
|
|
25
|
-
protected accessToken:
|
|
25
|
+
protected accessToken: RefreshableAccessTokenInterface;
|
|
26
26
|
protected oauthFactory: OfficialAccountOAuthFactory;
|
|
27
27
|
protected ticket: JsApiTicket;
|
|
28
28
|
getAccount(): AccountInterface;
|
|
@@ -46,13 +46,13 @@ declare class Application implements ApplicationInterface {
|
|
|
46
46
|
* @returns
|
|
47
47
|
*/
|
|
48
48
|
setServer(server: ServerInterface): this;
|
|
49
|
-
getAccessToken():
|
|
49
|
+
getAccessToken(): RefreshableAccessTokenInterface;
|
|
50
50
|
/**
|
|
51
51
|
* 设置AccessToken实例
|
|
52
52
|
* @param accessToken
|
|
53
53
|
* @returns
|
|
54
54
|
*/
|
|
55
|
-
setAccessToken(accessToken:
|
|
55
|
+
setAccessToken(accessToken: RefreshableAccessTokenInterface): this;
|
|
56
56
|
setOAuthFactory(oauthFactory: OfficialAccountOAuthFactory): this;
|
|
57
57
|
getOAuth(): ProviderInterface;
|
|
58
58
|
getTicket(): JsApiTicket;
|
|
@@ -75,11 +75,6 @@ class Application {
|
|
|
75
75
|
}
|
|
76
76
|
getServer() {
|
|
77
77
|
if (!this.server) {
|
|
78
|
-
let token = this.getAccount().getToken();
|
|
79
|
-
let aesKey = this.getAccount().getAesKey();
|
|
80
|
-
if (!token || !aesKey) {
|
|
81
|
-
throw new Error('token or aes_key cannot be empty.');
|
|
82
|
-
}
|
|
83
78
|
this.server = new Server_1.default(this.getRequest(), this.getAccount().getAesKey() ? this.getEncryptor() : null);
|
|
84
79
|
}
|
|
85
80
|
return this.server;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import ProviderInterface from "node-socialite/dist/Core/ProviderInterface";
|
|
2
|
-
import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
|
|
3
2
|
import CacheInterface from "../../Core/Contracts/CacheInterface";
|
|
4
3
|
import ConfigInterface from "../../Core/Contracts/ConfigInterface";
|
|
5
4
|
import AccessTokenAwareClient from "../../Core/HttpClient/AccessTokenAwareClient";
|
|
@@ -11,6 +10,7 @@ import AccountInterface from "./AccountInterface";
|
|
|
11
10
|
import { OfficialAccountOAuthFactory } from "../../Types/global";
|
|
12
11
|
import JsApiTicket from "../JsApiTicket";
|
|
13
12
|
import Utils from "../Utils";
|
|
13
|
+
import RefreshableAccessTokenInterface from "../../Core/Contracts/RefreshableAccessTokenInterface";
|
|
14
14
|
declare abstract class ApplicationInterface {
|
|
15
15
|
/**
|
|
16
16
|
* 获取当前账户实例
|
|
@@ -56,7 +56,7 @@ declare abstract class ApplicationInterface {
|
|
|
56
56
|
* 获取AccessToken实例
|
|
57
57
|
* @returns
|
|
58
58
|
*/
|
|
59
|
-
getAccessToken():
|
|
59
|
+
getAccessToken(): RefreshableAccessTokenInterface;
|
|
60
60
|
/**
|
|
61
61
|
* 获取缓存实例
|
|
62
62
|
* @returns
|
|
@@ -35,11 +35,11 @@ class JsApiTicket extends AccessToken_1.default {
|
|
|
35
35
|
if (!!ticket && typeof ticket === 'string') {
|
|
36
36
|
return ticket;
|
|
37
37
|
}
|
|
38
|
-
let response =
|
|
38
|
+
let response = (yield this.httpClient.request('get', '/cgi-bin/ticket/getticket', {
|
|
39
39
|
params: {
|
|
40
40
|
type: 'jsapi',
|
|
41
41
|
}
|
|
42
|
-
})).toObject(
|
|
42
|
+
})).toObject();
|
|
43
43
|
if (!response['ticket']) {
|
|
44
44
|
throw new Error('Failed to get jssdk_ticket: ' + JSON.stringify(response));
|
|
45
45
|
}
|
|
@@ -1,4 +1,143 @@
|
|
|
1
1
|
import BaseMessage from '../Core/Message';
|
|
2
2
|
declare class Message extends BaseMessage {
|
|
3
3
|
}
|
|
4
|
+
interface Message {
|
|
5
|
+
/**
|
|
6
|
+
* 消息密文,兼容模式、安全模式才有
|
|
7
|
+
*/
|
|
8
|
+
Encrypt?: string;
|
|
9
|
+
/**
|
|
10
|
+
* 开发者微信号
|
|
11
|
+
*/
|
|
12
|
+
ToUserName?: string;
|
|
13
|
+
/**
|
|
14
|
+
* 发送方帐号 OpenId
|
|
15
|
+
*/
|
|
16
|
+
FromUserName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* 消息创建时间
|
|
19
|
+
*/
|
|
20
|
+
CreateTime?: number;
|
|
21
|
+
/**
|
|
22
|
+
* 消息类型
|
|
23
|
+
* - `event` 事件
|
|
24
|
+
* - `text` 文本
|
|
25
|
+
* - `image` 图片
|
|
26
|
+
* - `voice` 语音
|
|
27
|
+
* - `video` 视频
|
|
28
|
+
* - `shortvideo` 小视频
|
|
29
|
+
* - `location` 地理位置
|
|
30
|
+
* - `link` 链接
|
|
31
|
+
*/
|
|
32
|
+
MsgType?: string;
|
|
33
|
+
/**
|
|
34
|
+
* 消息id,64位整型
|
|
35
|
+
* @scope MsgType='text' | 'image' | 'voice' | 'video' | 'shortvideo' | 'location'
|
|
36
|
+
*/
|
|
37
|
+
MsgId?: string;
|
|
38
|
+
/**
|
|
39
|
+
* 文本消息内容
|
|
40
|
+
* @scope MsgType='text'
|
|
41
|
+
*/
|
|
42
|
+
Content?: string;
|
|
43
|
+
/**
|
|
44
|
+
* 图片链接
|
|
45
|
+
* @scope MsgType='image'
|
|
46
|
+
*/
|
|
47
|
+
PicUrl?: string;
|
|
48
|
+
/**
|
|
49
|
+
* 媒体id,可以调用获取临时素材接口拉取数据
|
|
50
|
+
* @scope MsgType='image' | 'voice'
|
|
51
|
+
*/
|
|
52
|
+
MediaId?: string;
|
|
53
|
+
/**
|
|
54
|
+
* 语音格式,如amr,speex等
|
|
55
|
+
* @scope MsgType='voice'
|
|
56
|
+
*/
|
|
57
|
+
Format?: string;
|
|
58
|
+
/**
|
|
59
|
+
* 语音识别结果,UTF8编码
|
|
60
|
+
* @scope MsgType='voice'
|
|
61
|
+
*/
|
|
62
|
+
Recognition?: string;
|
|
63
|
+
/**
|
|
64
|
+
* 缩略图的媒体id
|
|
65
|
+
* @scope MsgType='video' | 'shortvideo'
|
|
66
|
+
*/
|
|
67
|
+
ThumbMediaId?: string;
|
|
68
|
+
/**
|
|
69
|
+
* 纬度
|
|
70
|
+
* @scope MsgType='location'
|
|
71
|
+
*/
|
|
72
|
+
Location_X?: number;
|
|
73
|
+
/**
|
|
74
|
+
* 经度
|
|
75
|
+
* @scope MsgType='location'
|
|
76
|
+
*/
|
|
77
|
+
Location_Y?: number;
|
|
78
|
+
/**
|
|
79
|
+
* 地图缩放大小
|
|
80
|
+
* @scope MsgType='location'
|
|
81
|
+
*/
|
|
82
|
+
Scale?: number;
|
|
83
|
+
/**
|
|
84
|
+
* 地理位置信息
|
|
85
|
+
* @scope MsgType='location'
|
|
86
|
+
*/
|
|
87
|
+
Label?: number;
|
|
88
|
+
/**
|
|
89
|
+
* 消息标题
|
|
90
|
+
* @scope MsgType='link'
|
|
91
|
+
*/
|
|
92
|
+
Title?: string;
|
|
93
|
+
/**
|
|
94
|
+
* 消息描述
|
|
95
|
+
* @scope MsgType='link'
|
|
96
|
+
*/
|
|
97
|
+
Description?: string;
|
|
98
|
+
/**
|
|
99
|
+
* 消息链接
|
|
100
|
+
* @scope MsgType='link'
|
|
101
|
+
*/
|
|
102
|
+
Url?: string;
|
|
103
|
+
/**
|
|
104
|
+
* 事件类型
|
|
105
|
+
* - `subscribe` 关注
|
|
106
|
+
* - `unsubscribe` 取消关注
|
|
107
|
+
* - `SCAN` 扫描(用户已关注)
|
|
108
|
+
* - `LOCATION` 地理位置
|
|
109
|
+
* - `CLICK` 自定义菜单事件
|
|
110
|
+
* - `VIEW` 点击菜单跳转链接
|
|
111
|
+
* @scope MsgType='event'
|
|
112
|
+
*/
|
|
113
|
+
Event?: string;
|
|
114
|
+
/**
|
|
115
|
+
* 事件KEY值
|
|
116
|
+
* - Event='subscribe' | 'SCAN'时:qrscene_为前缀,后面为二维码的参数值
|
|
117
|
+
* - Event='CLICK'时:自定义菜单接口中KEY值对应
|
|
118
|
+
* - Event='VIEW'时:设置的跳转URL
|
|
119
|
+
* @scope MsgType='event' && Event='subscribe' | 'SCAN' | 'CLICK' | 'VIEW'
|
|
120
|
+
*/
|
|
121
|
+
EventKey?: string;
|
|
122
|
+
/**
|
|
123
|
+
* 二维码的ticket,可用来换取二维码图片
|
|
124
|
+
* @scope MsgType='event' && Event='subscribe' | 'SCAN'
|
|
125
|
+
*/
|
|
126
|
+
Ticket?: string;
|
|
127
|
+
/**
|
|
128
|
+
* 纬度
|
|
129
|
+
* @scope MsgType='event' && Event='LOCATION'
|
|
130
|
+
*/
|
|
131
|
+
Latitude?: number;
|
|
132
|
+
/**
|
|
133
|
+
* 经度
|
|
134
|
+
* @scope MsgType='event' && Event='LOCATION'
|
|
135
|
+
*/
|
|
136
|
+
Longitude?: number;
|
|
137
|
+
/**
|
|
138
|
+
* 位置精度
|
|
139
|
+
* @scope MsgType='event' && Event='LOCATION'
|
|
140
|
+
*/
|
|
141
|
+
Precision?: number;
|
|
142
|
+
}
|
|
4
143
|
export = Message;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import ConfigInterface from '../Core/Contracts/ConfigInterface';
|
|
2
|
+
import ServerInterface from '../Core/Contracts/ServerInterface';
|
|
3
|
+
import Encryptor from '../Core/Encryptor';
|
|
4
|
+
import CacheMixin from '../Core/Mixins/CacheMixin';
|
|
5
|
+
import ConfigMixin from '../Core/Mixins/ConfigMixin';
|
|
6
|
+
import HttpClientMixin from '../Core/Mixins/HttpClientMixin';
|
|
7
|
+
import ServerRequestMixin from '../Core/Mixins/ServerRequestMixin';
|
|
8
|
+
import { PayConfig } from '../Types/global';
|
|
9
|
+
import MerchantInterface from './Contracts/MerchantInterface';
|
|
10
|
+
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
11
|
+
import Utils from './Utils';
|
|
12
|
+
import Client from './Client';
|
|
13
|
+
/**
|
|
14
|
+
* 微信支付应用
|
|
15
|
+
*/
|
|
16
|
+
declare class Application implements ApplicationInterface {
|
|
17
|
+
constructor(config: ConfigInterface | PayConfig);
|
|
18
|
+
protected merchant: MerchantInterface;
|
|
19
|
+
protected encryptor: Encryptor;
|
|
20
|
+
protected server: ServerInterface;
|
|
21
|
+
protected client: Client;
|
|
22
|
+
getMerchant(): MerchantInterface;
|
|
23
|
+
/**
|
|
24
|
+
* 设置当前账户实例
|
|
25
|
+
* @param merchant
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
setMerchant(merchant: MerchantInterface): this;
|
|
29
|
+
getServer(): ServerInterface;
|
|
30
|
+
/**
|
|
31
|
+
* 设置服务端实例
|
|
32
|
+
* @param server
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
setServer(server: ServerInterface): this;
|
|
36
|
+
getUtils(): Utils;
|
|
37
|
+
getClient(): Client;
|
|
38
|
+
/**
|
|
39
|
+
* 设置客户端
|
|
40
|
+
* @param client
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
setClient(client: Client): this;
|
|
44
|
+
/**
|
|
45
|
+
* 获取请求默认配置
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
protected getHttpClientDefaultOptions(): Record<string, any>;
|
|
49
|
+
}
|
|
50
|
+
interface Application extends ConfigMixin, CacheMixin, ServerRequestMixin, HttpClientMixin {
|
|
51
|
+
}
|
|
52
|
+
export = Application;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const merge_1 = __importDefault(require("merge"));
|
|
6
|
+
const ConfigInterface_1 = __importDefault(require("../Core/Contracts/ConfigInterface"));
|
|
7
|
+
const CacheMixin_1 = __importDefault(require("../Core/Mixins/CacheMixin"));
|
|
8
|
+
const ConfigMixin_1 = __importDefault(require("../Core/Mixins/ConfigMixin"));
|
|
9
|
+
const HttpClientMixin_1 = __importDefault(require("../Core/Mixins/HttpClientMixin"));
|
|
10
|
+
const ServerRequestMixin_1 = __importDefault(require("../Core/Mixins/ServerRequestMixin"));
|
|
11
|
+
const Utils_1 = require("../Core/Support/Utils");
|
|
12
|
+
const Merchant_1 = __importDefault(require("./Merchant"));
|
|
13
|
+
const Server_1 = __importDefault(require("./Server"));
|
|
14
|
+
const Utils_2 = __importDefault(require("./Utils"));
|
|
15
|
+
const Config_1 = __importDefault(require("../OfficialAccount/Config"));
|
|
16
|
+
const PrivateKey_1 = require("../Core/Support/PrivateKey");
|
|
17
|
+
const PublicKey_1 = require("../Core/Support/PublicKey");
|
|
18
|
+
const Client_1 = __importDefault(require("./Client"));
|
|
19
|
+
/**
|
|
20
|
+
* 微信支付应用
|
|
21
|
+
*/
|
|
22
|
+
class Application {
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.merchant = null;
|
|
25
|
+
this.encryptor = null;
|
|
26
|
+
this.server = null;
|
|
27
|
+
if (config instanceof ConfigInterface_1.default) {
|
|
28
|
+
this.setConfig(config);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.setConfig(new Config_1.default(config));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
getMerchant() {
|
|
35
|
+
var _a;
|
|
36
|
+
if (!this.merchant) {
|
|
37
|
+
this.merchant = new Merchant_1.default(this.config.get('mch_id'), new PrivateKey_1.PrivateKey(this.config.get('private_key')), new PublicKey_1.PublicKey(this.config.get('certificate')), this.config.get('secret_key'), this.config.get('v2_secret_key'), (_a = this.config.get('platform_certs')) !== null && _a !== void 0 ? _a : []);
|
|
38
|
+
}
|
|
39
|
+
return this.merchant;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 设置当前账户实例
|
|
43
|
+
* @param merchant
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
setMerchant(merchant) {
|
|
47
|
+
this.merchant = merchant;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
getServer() {
|
|
51
|
+
if (!this.server) {
|
|
52
|
+
this.server = new Server_1.default(this.getMerchant(), this.getRequest());
|
|
53
|
+
}
|
|
54
|
+
return this.server;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 设置服务端实例
|
|
58
|
+
* @param server
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
setServer(server) {
|
|
62
|
+
this.server = server;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
getUtils() {
|
|
66
|
+
return new Utils_2.default(this.getMerchant());
|
|
67
|
+
}
|
|
68
|
+
getClient() {
|
|
69
|
+
if (!this.client) {
|
|
70
|
+
this.client = (new Client_1.default(this.getMerchant(), this.getHttpClient(), this.config.get('http', {}))).setPresets(this.config.all());
|
|
71
|
+
}
|
|
72
|
+
return this.client;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 设置客户端
|
|
76
|
+
* @param client
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
setClient(client) {
|
|
80
|
+
this.client = client.setPresets(this.config.all());
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 获取请求默认配置
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
getHttpClientDefaultOptions() {
|
|
88
|
+
return (0, merge_1.default)(true, {
|
|
89
|
+
baseURL: 'https://api.weixin.qq.com/',
|
|
90
|
+
}, this.getConfig().get('http'));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
;
|
|
94
|
+
;
|
|
95
|
+
(0, Utils_1.applyMixins)(Application, [ConfigMixin_1.default, CacheMixin_1.default, ServerRequestMixin_1.default, HttpClientMixin_1.default]);
|
|
96
|
+
module.exports = Application;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Method, AxiosRequestConfig, AxiosInstance } from "axios";
|
|
2
|
+
import HttpClientInterface from "../Core/HttpClient/Contracts/HttpClientInterface";
|
|
3
|
+
import HttpClientMethodsMixin from '../Core/HttpClient/Mixins/HttpClientMethodsMixin';
|
|
4
|
+
import { LogHandler } from '../Types/global';
|
|
5
|
+
import HttpClientResponse from '../Core/HttpClient/HttpClientResponse';
|
|
6
|
+
import PresetMixin from '../Core/HttpClient/Mixins/PresetMixin';
|
|
7
|
+
import MerchantInterface from './Contracts/MerchantInterface';
|
|
8
|
+
declare class Client implements HttpClientInterface {
|
|
9
|
+
protected merchant: MerchantInterface;
|
|
10
|
+
protected throw: boolean;
|
|
11
|
+
protected client: HttpClientInterface;
|
|
12
|
+
protected defaultOptions: AxiosRequestConfig<any>;
|
|
13
|
+
V3_URI_PREFIXES: string[];
|
|
14
|
+
constructor(merchant: MerchantInterface, client: HttpClientInterface, defaultOptions?: Record<string, any>);
|
|
15
|
+
getInstance(): AxiosInstance;
|
|
16
|
+
setInstance(instance: AxiosInstance): this;
|
|
17
|
+
setLogger(logger: LogHandler): this;
|
|
18
|
+
request(method: Method, url: string, payload?: AxiosRequestConfig<any>): Promise<HttpClientResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* 判断是否是V3请求
|
|
21
|
+
* @param url 请求地址
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
protected isV3Request(url: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 创建签名(V3)
|
|
27
|
+
* @param method 请求方式
|
|
28
|
+
* @param url 请求地址
|
|
29
|
+
* @param payload 请求载荷
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
protected createSignature(method: string, url: string, payload: AxiosRequestConfig<any>): string;
|
|
33
|
+
/**
|
|
34
|
+
* 创建签名(V2)
|
|
35
|
+
* @param body 请求参数
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
protected attachLegacySignature(body: Record<string, any>): Record<string, string | number>;
|
|
39
|
+
/**
|
|
40
|
+
* 预设置mch_id(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
41
|
+
* @param new_mch_id
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
withMchId(new_mch_id?: string): this;
|
|
45
|
+
/**
|
|
46
|
+
* 预设置mch_id别名(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
47
|
+
* @param new_alias
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
withMchIdAs(new_alias?: string): this;
|
|
51
|
+
}
|
|
52
|
+
interface Client extends HttpClientMethodsMixin, PresetMixin {
|
|
53
|
+
}
|
|
54
|
+
export = Client;
|