@zsjinwei/wechatpay-node-v3 4.0.3

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.
@@ -0,0 +1,180 @@
1
+ interface Iamount {
2
+ total: number;
3
+ currency?: string;
4
+ }
5
+ interface Idetail {
6
+ cost_price?: number;
7
+ invoice_id?: string;
8
+ goods_detail?: IgoodsDetail[];
9
+ }
10
+ interface IgoodsDetail {
11
+ merchant_goods_id: string;
12
+ wechatpay_goods_id?: string;
13
+ goods_name?: string;
14
+ quantity: number;
15
+ unit_price: number;
16
+ }
17
+ interface Ipayer {
18
+ openid: string;
19
+ }
20
+ interface IsceneInfoH5 {
21
+ payer_client_ip: string;
22
+ device_id?: string;
23
+ store_info?: IstoreInfo;
24
+ h5_info: Ih5Info;
25
+ }
26
+ interface IsceneInfoNative {
27
+ payer_client_ip: string;
28
+ device_id?: string;
29
+ store_info?: IstoreInfo;
30
+ }
31
+ interface IstoreInfo {
32
+ id: string;
33
+ name?: string;
34
+ area_code?: string;
35
+ address?: string;
36
+ }
37
+ interface Ih5Info {
38
+ type: string;
39
+ app_name: string;
40
+ app_url?: string;
41
+ bundle_id?: string;
42
+ package_name?: string;
43
+ }
44
+ export interface Ioptions {
45
+ userAgent?: string;
46
+ authType?: string;
47
+ key?: string;
48
+ serial_no?: string;
49
+ }
50
+ export interface Ipay {
51
+ appid: string;
52
+ mchid: string;
53
+ serial_no?: string;
54
+ publicKey: Buffer;
55
+ privateKey: Buffer;
56
+ authType?: string;
57
+ userAgent?: string;
58
+ key?: string;
59
+ }
60
+ export interface Ih5 {
61
+ appid?: string;
62
+ mchid?: string;
63
+ description: string;
64
+ out_trade_no: string;
65
+ time_expire?: string;
66
+ attach?: string;
67
+ notify_url: string;
68
+ goods_tag?: string;
69
+ amount: Iamount;
70
+ detail?: Idetail;
71
+ scene_info: IsceneInfoH5;
72
+ }
73
+ export interface Inative {
74
+ appid?: string;
75
+ mchid?: string;
76
+ description: string;
77
+ out_trade_no: string;
78
+ time_expire?: string;
79
+ attach?: string;
80
+ notify_url: string;
81
+ goods_tag?: string;
82
+ support_fapiao?: boolean;
83
+ amount: Iamount;
84
+ detail?: Idetail;
85
+ scene_info?: IsceneInfoNative;
86
+ settle_info?: {
87
+ profit_sharing?: boolean;
88
+ };
89
+ }
90
+ export interface Ijsapi {
91
+ appid?: string;
92
+ mchid?: string;
93
+ description: string;
94
+ out_trade_no: string;
95
+ time_expire?: string;
96
+ attach?: string;
97
+ notify_url: string;
98
+ goods_tag?: string;
99
+ amount: Iamount;
100
+ payer: Ipayer;
101
+ detail?: Idetail;
102
+ scene_info?: IsceneInfoNative;
103
+ }
104
+ export interface Iapp {
105
+ appid?: string;
106
+ mchid?: string;
107
+ description: string;
108
+ out_trade_no: string;
109
+ time_expire?: string;
110
+ attach?: string;
111
+ notify_url: string;
112
+ goods_tag?: string;
113
+ amount: Iamount;
114
+ detail?: Idetail;
115
+ scene_info?: IsceneInfoNative;
116
+ }
117
+ export interface Iquery1 {
118
+ transaction_id: string;
119
+ out_trade_no?: string;
120
+ }
121
+ export interface Iquery2 {
122
+ transaction_id?: string;
123
+ out_trade_no: string;
124
+ }
125
+ export interface Itradebill {
126
+ bill_date: string;
127
+ sub_mchid?: string;
128
+ bill_type: string;
129
+ tar_type?: string;
130
+ }
131
+ export interface Ifundflowbill {
132
+ bill_date: string;
133
+ account_type: string;
134
+ tar_type?: string;
135
+ }
136
+ export interface Irefunds {
137
+ out_refund_no: string;
138
+ reason?: string;
139
+ notify_url?: string;
140
+ funds_account?: string;
141
+ amount: IRamount;
142
+ goods_detail?: IRgoodsDetail[];
143
+ }
144
+ export interface Irefunds1 extends Irefunds {
145
+ transaction_id: string;
146
+ out_trade_no?: string;
147
+ }
148
+ export interface Irefunds2 extends Irefunds {
149
+ transaction_id?: string;
150
+ out_trade_no: string;
151
+ }
152
+ interface IRamount {
153
+ total: number;
154
+ currency: string;
155
+ refund: number;
156
+ }
157
+ interface IRgoodsDetail {
158
+ merchant_goods_id: string;
159
+ wechatpay_goods_id?: string;
160
+ goods_name?: string;
161
+ refund_quantity: number;
162
+ unit_price: number;
163
+ refund_amount: number;
164
+ }
165
+ /**
166
+ * 证书信息
167
+ */
168
+ export interface ICertificates {
169
+ effective_time: string;
170
+ expire_time: string;
171
+ serial_no: string;
172
+ publicKey?: string;
173
+ encrypt_certificate: {
174
+ algorithm: string;
175
+ associated_data: string;
176
+ ciphertext: string;
177
+ nonce: string;
178
+ };
179
+ }
180
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { Output } from './interface-v2';
2
+ import { IPayRequest } from './pay-request.interface';
3
+ export declare class PayRequest implements IPayRequest {
4
+ upload(url: string, params: Record<string, any>, headers: Record<string, any>): Promise<Output>;
5
+ post(url: string, params: Record<string, any>, headers: Record<string, any>): Promise<Output>;
6
+ get(url: string, headers: Record<string, any>): Promise<Output>;
7
+ }
@@ -0,0 +1,23 @@
1
+ import { Output } from './interface-v2';
2
+ export interface IPayRequest {
3
+ /**
4
+ * post 请求
5
+ * @param url url
6
+ * @param params body
7
+ * @param headers 请求头
8
+ */
9
+ post(url: string, params: Record<string, any>, headers: Record<string, any>): Promise<Output>;
10
+ /**
11
+ * 上传文件
12
+ * @param url url
13
+ * @param params body
14
+ * @param headers 请求头
15
+ */
16
+ upload(url: string, params: Record<string, any>, headers: Record<string, any>): Promise<Output>;
17
+ /**
18
+ * get 请求
19
+ * @param url url
20
+ * @param headers 请求头
21
+ */
22
+ get(url: string, headers: Record<string, any>): Promise<Output>;
23
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,153 @@
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.PayRequest = void 0;
43
+ var superagent_1 = __importDefault(require("superagent"));
44
+ var PayRequest = /** @class */ (function () {
45
+ function PayRequest() {
46
+ }
47
+ PayRequest.prototype.upload = function (url, params, headers) {
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var result, error_1, err;
50
+ var _a;
51
+ return __generator(this, function (_b) {
52
+ switch (_b.label) {
53
+ case 0:
54
+ _b.trys.push([0, 2, , 3]);
55
+ return [4 /*yield*/, superagent_1.default
56
+ .post(url)
57
+ .send(params)
58
+ .attach('file', params.pic_buffer, {
59
+ filename: '72fe0092be0cf9dd8420579cc954fb4e.jpg',
60
+ contentType: 'image/jpg',
61
+ })
62
+ .field('meta', JSON.stringify(params.fileinfo))];
63
+ case 1:
64
+ result = _b.sent();
65
+ return [2 /*return*/, {
66
+ status: result.status,
67
+ data: result.body,
68
+ }];
69
+ case 2:
70
+ error_1 = _b.sent();
71
+ err = JSON.parse(JSON.stringify(error_1));
72
+ return [2 /*return*/, {
73
+ status: err.status,
74
+ errRaw: err,
75
+ error: (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.text,
76
+ }];
77
+ case 3: return [2 /*return*/];
78
+ }
79
+ });
80
+ });
81
+ };
82
+ PayRequest.prototype.post = function (url, params, headers) {
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var result, error_2, err;
85
+ var _a;
86
+ return __generator(this, function (_b) {
87
+ switch (_b.label) {
88
+ case 0:
89
+ _b.trys.push([0, 2, , 3]);
90
+ return [4 /*yield*/, superagent_1.default
91
+ .post(url)
92
+ .send(params)
93
+ .set(headers)];
94
+ case 1:
95
+ result = _b.sent();
96
+ return [2 /*return*/, {
97
+ status: result.status,
98
+ data: result.body,
99
+ }];
100
+ case 2:
101
+ error_2 = _b.sent();
102
+ err = JSON.parse(JSON.stringify(error_2));
103
+ return [2 /*return*/, {
104
+ status: err.status,
105
+ errRaw: err,
106
+ error: (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.text,
107
+ }];
108
+ case 3: return [2 /*return*/];
109
+ }
110
+ });
111
+ });
112
+ };
113
+ PayRequest.prototype.get = function (url, headers) {
114
+ return __awaiter(this, void 0, void 0, function () {
115
+ var result, data, error_3, err;
116
+ var _a;
117
+ return __generator(this, function (_b) {
118
+ switch (_b.label) {
119
+ case 0:
120
+ _b.trys.push([0, 2, , 3]);
121
+ return [4 /*yield*/, superagent_1.default.get(url).set(headers)];
122
+ case 1:
123
+ result = _b.sent();
124
+ data = {};
125
+ if (result.type === 'text/plain') {
126
+ data = {
127
+ status: result.status,
128
+ data: result.text,
129
+ };
130
+ }
131
+ else {
132
+ data = {
133
+ status: result.status,
134
+ data: result.body,
135
+ };
136
+ }
137
+ return [2 /*return*/, data];
138
+ case 2:
139
+ error_3 = _b.sent();
140
+ err = JSON.parse(JSON.stringify(error_3));
141
+ return [2 /*return*/, {
142
+ status: err.status,
143
+ errRaw: err,
144
+ error: (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.text,
145
+ }];
146
+ case 3: return [2 /*return*/];
147
+ }
148
+ });
149
+ });
150
+ };
151
+ return PayRequest;
152
+ }());
153
+ exports.PayRequest = PayRequest;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@zsjinwei/wechatpay-node-v3",
3
+ "version": "4.0.3",
4
+ "description": "微信支付文档v3",
5
+ "keywords": [
6
+ "node",
7
+ "wechat",
8
+ "微信支付",
9
+ "微信提现"
10
+ ],
11
+ "homepage": "https://github.com/bobby169/wechatpay-node-v3-ts#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/bobby169/wechatpay-node-v3-ts/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/bobby169/wechatpay-node-v3-ts.git"
18
+ },
19
+ "license": "MIT",
20
+ "author": "klover",
21
+ "main": "dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "scripts": {
27
+ "build": "rm -rf ./dist && tsc",
28
+ "release": "npm publish --registry=https://registry.npmjs.org/",
29
+ "test": "echo \"Error: no test specified\" && exit 1"
30
+ },
31
+ "dependencies": {
32
+ "@fidm/x509": "1.2.1",
33
+ "superagent": "8.0.6"
34
+ },
35
+ "devDependencies": {
36
+ "@nestjs/common": "8.2.4",
37
+ "@types/node": "14.14.12",
38
+ "@types/superagent": "4.1.10",
39
+ "@typescript-eslint/eslint-plugin": "3.0.2",
40
+ "@typescript-eslint/parser": "3.0.2",
41
+ "eslint": "7.1.0",
42
+ "eslint-config-prettier": "6.10.0",
43
+ "eslint-plugin-import": "2.20.1",
44
+ "prettier": "1.19.1",
45
+ "ts-node": "9.1.1",
46
+ "typescript": "4.1.2"
47
+ }
48
+ }