From 96d308d01673d4c1caff8f887f7e7058057d5686 Mon Sep 17 00:00:00 2001 From: Aex Date: Wed, 26 May 2021 20:31:32 +0800 Subject: [PATCH] Auto Format --- .eslintrc.json | 2 -- README.md | 14 +++++++------- src/index.ts | 1 - src/lib/CoaWxPayIsvBin.ts | 24 +++++++++++------------- src/service/CoaWxPayIsvService.ts | 22 ++++++++++------------ src/test/demo.ts | 11 ++++++----- src/typings.ts | 14 +++++++------- tsconfig.json | 4 +--- 8 files changed, 42 insertions(+), 50 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 29aae87..781bfe2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,10 +13,8 @@ "plugins": ["@typescript-eslint"], "rules": { "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/naming-convention": "off", "@typescript-eslint/no-namespace": "off", "@typescript-eslint/restrict-plus-operands": "off", - "@typescript-eslint/restrict-template-expressions": "off", "@typescript-eslint/strict-boolean-expressions": "off" } } diff --git a/README.md b/README.md index 38efd05..691a1cf 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![npm downloads](https://img.shields.io/npm/dm/coa-wx-pay-isv.svg?style=flat-square)](http://npm-stat.com/charts.html?package=coa-wx-pay-isv) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/coajs/coa-wx-pay-isv/pulls) -轻量的微信支付SDK服务商版 for Node.js +轻量的微信支付 SDK 服务商版 for Node.js ## 特点 @@ -13,7 +13,7 @@ - 覆盖了绝大多数使用场景 - 统一了异步表现形式,全部返回 Promise -- 内置类型引用,无需额外查看文档,开箱即用,IDE友好 +- 内置类型引用,无需额外查看文档,开箱即用,IDE 友好 ## 快速开始 @@ -35,7 +35,7 @@ const config = { key: '1125XXXXXXXXXXXXXXXXXXX6E20DE9', pfx: Buffer.from('XXXXXXX'), notifyPay: 'https://example.com/api/notify/pay', - notifyRefund: 'https://example.com/api/notify/refund' + notifyRefund: 'https://example.com/api/notify/refund', } // 创建BIN实例 @@ -65,7 +65,7 @@ await service.downloadBill({ date: '20210331' }) ### 错误记录 -可以使用自定义Bin的方式记录错误信息。 +可以使用自定义 Bin 的方式记录错误信息。 ```typescript import { CoaWxPayIsvBin, CoaWxPayIsvService } from 'coa-wx-pay-isv' @@ -77,12 +77,12 @@ const config = { key: '1125XXXXXXXXXXXXXXXXXXX6E20DE9', pfx: Buffer.from('XXXXXXX'), notifyPay: 'https://example.com/api/notify/pay', - notifyRefund: 'https://example.com/api/notify/refund' + notifyRefund: 'https://example.com/api/notify/refund', } // 创建自定义Bin类 class MyCoaWxPayIsvBin extends CoaWxPayIsvBin { - protected onRequestError (error: Error, response: Axios.AxiosResponse) { + protected onRequestError(error: Error, response: Axios.AxiosResponse) { console.log('error:', error.toString()) console.log('data:', response.data) } @@ -96,4 +96,4 @@ const service = new CoaWxPayIsvService(bin) // 错误调用下载日对账单 await service.downloadBill({ date: '' }) // 此时会触发 onRequestError() -``` \ No newline at end of file +``` diff --git a/src/index.ts b/src/index.ts index ef847c4..a994143 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ export { CoaWxPayIsvBin } from './lib/CoaWxPayIsvBin' export { CoaWxPayIsvService } from './service/CoaWxPayIsvService' export { CoaWxPayIsv } from './typings' - diff --git a/src/lib/CoaWxPayIsvBin.ts b/src/lib/CoaWxPayIsvBin.ts index 2a2f674..a4c1293 100644 --- a/src/lib/CoaWxPayIsvBin.ts +++ b/src/lib/CoaWxPayIsvBin.ts @@ -12,41 +12,40 @@ interface Dic { } export class CoaWxPayIsvBin { - public readonly config: CoaWxPayIsv.Config public readonly httpsAgent: Agent - constructor (config: CoaWxPayIsv.Config) { + constructor(config: CoaWxPayIsv.Config) { this.config = config this.httpsAgent = new Agent({ pfx: config.pfx, passphrase: config.mchId }) } // 生成签名 - generateSignature (object: Dic) { + generateSignature(object: Dic) { const paramList: any[] = [] _.forEach(object, (v, k) => { if (v) paramList.push(k + '=' + v) }) - paramList.sort() + paramList.sort(undefined) paramList.push('key=' + this.config.key) const paramString = paramList.join('&') return secure.md5(paramString).toUpperCase() } // 生成随机字符串 - generateNonceString () { + generateNonceString() { return Math.random().toString(36).substr(2, 15) } // 转换为已经签名的XML参数 - async toSignedXmlParams (param: Dic, signName = 'sign') { + async toSignedXmlParams(param: Dic, signName = 'sign') { param[signName] = this.generateSignature(param) return await xml.encode(param) } // 进行post请求 - async post (url: string, data: Dic | string, config: Axios.AxiosRequestConfig = {}) { - const res = await axios({ url, data, baseURL, method: 'POST', ...config }).catch(e => e) + async post(url: string, data: Dic | string, config: Axios.AxiosRequestConfig = {}) { + const res = await axios({ url, data, baseURL, method: 'POST', ...config }).catch((e) => e) // 处理结果 try { return await this.handleResult(res) @@ -56,12 +55,11 @@ export class CoaWxPayIsvBin { } } - protected onRequestError (error: Error, response: Axios.AxiosResponse) { - } + protected onRequestError(_error: Error, response: Axios.AxiosResponse) {} // 处理响应结果 - private async handleResult (res: Axios.AxiosResponse) { - const text = res.data as string || '' + private async handleResult(res: Axios.AxiosResponse) { + const text = (res.data as string) || '' if (!text) CoaError.throw('CoaWxPayIsv.ServeCallError', '微信支付服务器数据异常') if (!text.startsWith('