index.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /// <reference types="node" />
  2. import { Ipay, Ih5, Inative, Ijsapi, Iquery1, Iquery2, Itradebill, Ifundflowbill, Iapp, Ioptions, Irefunds1, Irefunds2, ICertificates } from './lib/interface';
  3. import { IcombineH5, IcombineNative, IcombineApp, IcombineJsapi, IcloseSubOrders } from './lib/combine_interface';
  4. import { BatchesTransfer } from './lib/interface-v2';
  5. import { Base } from './lib/base';
  6. declare class Pay extends Base {
  7. private appid;
  8. private mchid;
  9. private serial_no;
  10. private publicKey?;
  11. private privateKey?;
  12. private authType;
  13. private key?;
  14. private static certificates;
  15. /**
  16. * 构造器
  17. * @param appid 直连商户申请的公众号或移动应用appid。
  18. * @param mchid 商户号
  19. * @param publicKey 公钥
  20. * @param privateKey 密钥
  21. * @param optipns 可选参数 object 包括下面参数
  22. *
  23. * @param serial_no 证书序列号
  24. * @param authType 可选参数 认证类型,目前为WECHATPAY2-SHA256-RSA2048
  25. * @param userAgent 可选参数 User-Agent
  26. * @param key 可选参数 APIv3密钥
  27. */
  28. constructor(appid: string, mchid: string, publicKey: Buffer, privateKey: Buffer, optipns?: Ioptions);
  29. /**
  30. * 构造器
  31. * @param obj object类型 包括下面参数
  32. *
  33. * @param appid 直连商户申请的公众号或移动应用appid。
  34. * @param mchid 商户号
  35. * @param serial_no 可选参数 证书序列号
  36. * @param publicKey 公钥
  37. * @param privateKey 密钥
  38. * @param authType 可选参数 认证类型,目前为WECHATPAY2-SHA256-RSA2048
  39. * @param userAgent 可选参数 User-Agent
  40. * @param key 可选参数 APIv3密钥
  41. */
  42. constructor(obj: Ipay);
  43. /**
  44. * 获取微信平台key
  45. * @param apiSecret APIv3密钥
  46. * @returns
  47. */
  48. get_certificates(apiSecret: string): Promise<ICertificates[]>;
  49. /**
  50. * 拉取平台证书到 Pay.certificates 中
  51. * @param apiSecret APIv3密钥
  52. * https://pay.weixin.qq.com/wiki/doc/apiv3/apis/wechatpay5_1.shtml
  53. */
  54. private fetchCertificates;
  55. /**
  56. * 验证签名,提醒:node 取头部信息时需要用小写,例如:req.headers['wechatpay-timestamp']
  57. * @param params.timestamp HTTP头Wechatpay-Timestamp 中的应答时间戳
  58. * @param params.nonce HTTP头Wechatpay-Nonce 中的应答随机串
  59. * @param params.body 应答主体(response Body),需要按照接口返回的顺序进行验签,错误的顺序将导致验签失败。
  60. * @param params.serial HTTP头Wechatpay-Serial 证书序列号
  61. * @param params.signature HTTP头Wechatpay-Signature 签名
  62. * @param params.apiSecret APIv3密钥,如果在 构造器 中有初始化该值(this.key),则可以不传入。当然传入也可以
  63. */
  64. verifySign(params: {
  65. timestamp: string | number;
  66. nonce: string;
  67. body: Record<string, any> | string;
  68. serial: string;
  69. signature: string;
  70. apiSecret?: string;
  71. }): Promise<boolean>;
  72. /**
  73. * 敏感信息加密
  74. * @param str 敏感信息字段(如用户的住址、银行卡号、手机号码等)
  75. * @returns
  76. */
  77. publicEncrypt(str: string, wxPublicKey: Buffer, padding?: number): string;
  78. /**
  79. * 敏感信息解密
  80. * @param str 敏感信息字段(如用户的住址、银行卡号、手机号码等)
  81. * @returns
  82. */
  83. privateDecrypt(str: string, padding?: number): string;
  84. /**
  85. * 构建请求签名参数
  86. * @param method Http 请求方式
  87. * @param url 请求接口 例如/v3/certificates
  88. * @param timestamp 获取发起请求时的系统当前时间戳
  89. * @param nonceStr 随机字符串
  90. * @param body 请求报文主体
  91. */
  92. getSignature(method: string, nonce_str: string, timestamp: string, url: string, body?: string | Record<string, any>): string;
  93. private sign;
  94. getSN(fileData?: string | Buffer): string;
  95. /**
  96. * SHA256withRSA
  97. * @param data 待加密字符
  98. * @param privatekey 私钥key key.pem fs.readFileSync(keyPath)
  99. */
  100. sha256WithRsa(data: string): string;
  101. /**
  102. * 获取授权认证信息
  103. * @param nonceStr 请求随机串
  104. * @param timestamp 时间戳
  105. * @param signature 签名值
  106. */
  107. getAuthorization(nonce_str: string, timestamp: string, signature: string): string;
  108. /**
  109. * 回调解密
  110. * @param ciphertext Base64编码后的开启/停用结果数据密文
  111. * @param associated_data 附加数据
  112. * @param nonce 加密使用的随机串
  113. * @param key APIv3密钥
  114. */
  115. decipher_gcm<T extends any>(ciphertext: string, associated_data: string, nonce: string, key?: string): T;
  116. /**
  117. * 参数初始化
  118. */
  119. private init;
  120. /**
  121. * h5支付
  122. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_1.shtml
  123. */
  124. transactions_h5(params: Ih5): Promise<Record<string, any>>;
  125. /**
  126. * 合单h5支付
  127. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_2.shtml
  128. */
  129. combine_transactions_h5(params: IcombineH5): Promise<Record<string, any>>;
  130. /**
  131. * native支付
  132. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml
  133. */
  134. transactions_native(params: Inative): Promise<Record<string, any>>;
  135. /**
  136. * 合单native支付
  137. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_5.shtml
  138. */
  139. combine_transactions_native(params: IcombineNative): Promise<Record<string, any>>;
  140. /**
  141. * app支付
  142. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_1.shtml
  143. */
  144. transactions_app(params: Iapp): Promise<Record<string, any>>;
  145. /**
  146. * 合单app支付
  147. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_1.shtml
  148. */
  149. combine_transactions_app(params: IcombineApp): Promise<Record<string, any>>;
  150. /**
  151. * JSAPI支付 或者 小程序支付
  152. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
  153. */
  154. transactions_jsapi(params: Ijsapi): Promise<Record<string, any>>;
  155. /**
  156. * 合单JSAPI支付 或者 小程序支付
  157. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_3.shtml
  158. */
  159. combine_transactions_jsapi(params: IcombineJsapi): Promise<Record<string, any>>;
  160. /**
  161. * 查询订单
  162. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_2.shtml
  163. */
  164. query(params: Iquery1 | Iquery2): Promise<Record<string, any>>;
  165. /**
  166. * 合单查询订单
  167. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_11.shtml
  168. */
  169. combine_query(combine_out_trade_no: string): Promise<Record<string, any>>;
  170. /**
  171. * 关闭订单
  172. * @param out_trade_no 请求参数 商户订单号 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_3.shtml
  173. */
  174. close(out_trade_no: string): Promise<Record<string, any>>;
  175. /**
  176. * 合单关闭订单
  177. * @param combine_out_trade_no 请求参数 总订单号 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_12.shtml
  178. * @param sub_orders array 子单信息
  179. */
  180. combine_close(combine_out_trade_no: string, sub_orders: IcloseSubOrders[]): Promise<Record<string, any>>;
  181. /**
  182. * 申请交易账单
  183. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_6.shtml
  184. */
  185. tradebill(params: Itradebill): Promise<Record<string, any>>;
  186. /**
  187. * 申请资金账单
  188. * @param params 请求参数 object 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_7.shtml
  189. */
  190. fundflowbill(params: Ifundflowbill): Promise<Record<string, any>>;
  191. /**
  192. * 下载账单
  193. * @param download_url 请求参数 路径 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_8.shtml
  194. */
  195. downloadbill(download_url: string): Promise<Record<string, any>>;
  196. /**
  197. * 申请退款
  198. * @param params 请求参数 路径 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_9.shtml
  199. */
  200. refunds(params: Irefunds1 | Irefunds2): Promise<Record<string, any>>;
  201. /**
  202. * 查询单笔退款
  203. * @documentation 请求参数 路径 参数介绍 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_10.shtml
  204. */
  205. find_refunds(out_refund_no: string): Promise<Record<string, any>>;
  206. /**
  207. * 发起商家转账零钱
  208. * @documentation 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_1.shtml
  209. */
  210. batches_transfer(params: BatchesTransfer.Input): Promise<BatchesTransfer.IOutput>;
  211. /**
  212. * 微信批次单号查询批次单API
  213. * @documentation 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_2.shtml
  214. */
  215. query_batches_transfer_list_wx(params: BatchesTransfer.QueryBatchesTransferByWx.Input): Promise<BatchesTransfer.QueryBatchesTransferByWx.IOutput>;
  216. /**
  217. * 微信明细单号查询明细单API
  218. * @documentation 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_3.shtml
  219. */
  220. query_batches_transfer_detail_wx(params: BatchesTransfer.QueryBatchesTransferDetailByWx.Input): Promise<BatchesTransfer.QueryBatchesTransferDetailByWx.IOutput>;
  221. /**
  222. * 商家批次单号查询批次单API
  223. * @documentation 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_5.shtml
  224. */
  225. query_batches_transfer_list(params: BatchesTransfer.QueryBatchesTransferList.Input): Promise<BatchesTransfer.QueryBatchesTransferList.IOutput>;
  226. /**
  227. * 商家明细单号查询明细单API
  228. * @documentation 请看文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_6.shtml
  229. */
  230. query_batches_transfer_detail(params: BatchesTransfer.QueryBatchesTransferDetail.Input): Promise<BatchesTransfer.QueryBatchesTransferDetail.IOutput>;
  231. }
  232. export = Pay;