{"id":16278576,"url":"https://github.com/sigoden/wechatpay","last_synced_at":"2025-07-30T23:36:52.243Z","repository":{"id":57106101,"uuid":"133662097","full_name":"sigoden/wechatpay","owner":"sigoden","description":"微信支付 SDK，支持刷卡支付、公众号支付、扫码支付、APP支付、H5支付，以及优惠券，红包，企业付款，微信代扣","archived":false,"fork":false,"pushed_at":"2019-06-10T13:00:33.000Z","size":461,"stargazers_count":118,"open_issues_count":0,"forks_count":24,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-29T14:41:07.088Z","etag":null,"topics":["wechat","wechat-pay","wechat-sdk","wechatpay"],"latest_commit_sha":null,"homepage":"https://sigoden.github.io/wechatpay/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sigoden.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-16T12:26:27.000Z","updated_at":"2024-10-26T23:26:53.000Z","dependencies_parsed_at":"2022-08-20T23:20:16.173Z","dependency_job_id":null,"html_url":"https://github.com/sigoden/wechatpay","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigoden%2Fwechatpay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigoden%2Fwechatpay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigoden%2Fwechatpay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigoden%2Fwechatpay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sigoden","download_url":"https://codeload.github.com/sigoden/wechatpay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228520937,"owners_count":17932655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wechat","wechat-pay","wechat-sdk","wechatpay"],"created_at":"2024-10-10T18:59:02.406Z","updated_at":"2024-12-06T20:16:58.834Z","avatar_url":"https://github.com/sigoden.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 微信支付 node.js\n\n[![Build Status](https://travis-ci.org/sigoden/wechatpay.svg?branch=master)](https://travis-ci.org/sigoden/wechatpay)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f019843d36f643378a26840660c10f61)](https://www.codacy.com/app/sigoden/wechatpay?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=sigoden/wechatpay\u0026utm_campaign=Badge_Grade)\n[![dependencies Status](https://david-dm.org/sigoden/wechatpay/status.svg)](https://david-dm.org/sigoden/wechatpay)\n[![Known Vulnerabilities](https://snyk.io/test/github/sigoden/wechatpay/badge.svg?targetFile=package.json)](https://snyk.io/test/github/sigoden/wechatpay?targetFile=package.json)\n\n\u003e 微信支付 SDK，支持刷卡支付、公众号支付、扫码支付、APP 支付、H5 支付，以及优惠券，红包，企业付款，微信代扣\n\n## 特性\n\n- 使用 Typescript 编写，拥有更安全的类型和更好的代码提示\n- 支持所有类型微信支付\n- 支持微信代扣\n- 提供调试模式\n\n## 开始使用\n\n```js\nconst path = require(\"path\");\nconst fs = require(\"fs\");\nconst {\n  PubPay,\n  RequestError,\n  CommunicationError,\n  utils: { getXMLBody }\n} = require(\"@sigodenjs/wechatpay\");\n\nconst pay = new PubPay({\n  appId: \"wxb80e5bddb2d804f3\",\n  key: \"6Q9VX4N3WTBM9G9XBL7H1L9PB9ANHLY7\",\n  mchId: \"1434712502\",\n  pfx: fs.readFileSync(path.resolve(__dirname, \"cert.p12\"))\n});\n\n// 调用统一下单接口\npay\n  .unifiedOrder({\n    body: \"腾讯充值中心-QQ会员充值\",\n    out_trade_no: \"1217752501201407033233368018\",\n    total_fee: 888,\n    spbill_create_ip: \"8.8.8.8\",\n    notify_url: \"https://example.com/wechatpay/notify\",\n    trade_type: \"JSAPI\",\n    openid: \"oUpF8uMuAJO_M2pxb1Q9zNjWeS6o\"\n  })\n  .then(res =\u003e {\n    if (!pay.verifySign(res)) {\n      // 签名校验失败\n      throw new Error(\"签名校验失败\");\n    }\n    if (res.result_code === \"FAIL\") {\n      console.log(res.err_code, res.err_code_des);\n    } else {\n      console.log(res.prepay_id);\n    }\n  })\n  .catch(err =\u003e {\n    if (err instanceof RequestError) {\n      // 请求错误\n    } else if (err instanceof CommunicationError) {\n      // return_code = FAIL\n    }\n  });\n\n// 支付结果通知\nrouter.post(\"/wechatpay/notify\", (req, res) =\u003e {\n  const options = {\n    length: req.headers[\"content-length\"],\n    limit: \"1mb\",\n    encoding: \"utf8\"\n  };\n  getXMLBody(req, options).then(data =\u003e {\n    pay\n      .payNotify(data, async parsedData =\u003e {\n        if (!pay.verifySign(parsedData)) {\n          // 签名校验失败\n        }\n        if (parsedData.result_code === \"FAIL\") {\n          // 业务逻辑失败\n        }\n        // ...\n        return {\n          return_code: \"SUCCESS\",\n          return_msg: \"OK\"\n        };\n      })\n      .then(returnData =\u003e {\n        res.set(\"Content-Type\", \"application/xml; charset=utf-8\");\n        res.end(returnData);\n      });\n  });\n});\n```\n\n## 类和接口\n\n### 业务类\n- [AppPay](https://sigoden.github.io/wechatpay/classes/apppay): APP 支付\n- [Bank](https://sigoden.github.io/wechatpay/classes/bank): 企业付款\n- [Coupon](https://sigoden.github.io/wechatpay/classes/coupon): 代金券\n- [LitePay](https://sigoden.github.io/wechatpay/classes/litepay): 小程序支付\n- [PubPay](https://sigoden.github.io/wechatpay/classes/pubpay): 公众号支付\n- [PubQrPay](https://sigoden.github.io/wechatpay/classes/pubqrpay): 扫码支付\n- [PubScanPay](https://sigoden.github.io/wechatpay/classes/pubscanpay): 刷卡支付\n- [RedPack](https://sigoden.github.io/wechatpay/classes/redpack): 现金红包\n- [WapPay](https://sigoden.github.io/wechatpay/classes/wappay): H5 支付\n- [AppEntrust](https://sigoden.github.io/wechatpay/classes/appentrust): APP 代扣\n- [LiteEntrust](https://sigoden.github.io/wechatpay/classes/liteentrust): 小程序代扣\n- [PubEntrsut](https://sigoden.github.io/wechatpay/classes/pubentrsut): 公众号代扣\n- [WapEntrust](https://sigoden.github.io/wechatpay/classes/wapentrust): H5 代扣\n\n### 综合类\n\n- [Pay](https://sigoden.github.io/wechatpay/classes/pay): 组合所有支付类，包含所有支付相关接口\n- [Entrust](https://sigoden.github.io/wechatpay/classes/entrust): 组合所有代扣类，包含所有代扣相关接扣\n\n\u003e 如果你只使用了某一项支付，请使用业务类。但如果涉及多种支付，使用综合类更便捷。\n\n### 支付相关接口\n\n- [batchQueryComment](https://sigoden.github.io/wechatpay/classes/pay#batchquerycomment): 拉取订单评价数据\n- [downloadBill](https://sigoden.github.io/wechatpay/classes/pay#downloadbill): 下载对账单\n- [downloadFundFlow](https://sigoden.github.io/wechatpay/classes/pay#downloadfundflow): 下载资金账单\n- [orderQuery](https://sigoden.github.io/wechatpay/classes/pay#orderquery): 查询订单\n- [refund](https://sigoden.github.io/wechatpay/classes/pay#refund): 申请退款\n- [refundNotify](https://sigoden.github.io/wechatpay/classes/pay#refundnotify): 退款结果通知处理\n- [refundQuery](https://sigoden.github.io/wechatpay/classes/pay#refundquery): 查询退款\n- [report](https://sigoden.github.io/wechatpay/classes/pay#report): 交易保障\n- [closeOrder](https://sigoden.github.io/wechatpay/classes/pay#closeorder): 关闭订单\n- [payNotify](https://sigoden.github.io/wechatpay/classes/pay#paynotify): 支付结果通知\n- [unifiedOrder](https://sigoden.github.io/wechatpay/classes/pay#unifiedorder): 统一下单\n- [authCodeToOpenId](https://sigoden.github.io/wechatpay/classes/pay#authcodetoopenid) - 授权码查询 OpenId\n- [microPay](https://sigoden.github.io/wechatpay/classes/pay#micropay) - 提交刷卡支付\n- [reverse](https://sigoden.github.io/wechatpay/classes/pay#reverse) - 撤销订单\n- [shortURL](https://sigoden.github.io/wechatpay/classes/pay#shorturl) - 短链接转换\n- [getPublicKey](https://sigoden.github.io/wechatpay/classes/pay#getpublickey): 获取 RSA 加密公钥\n- [getTransferInfo](https://sigoden.github.io/wechatpay/classes/pay#gettransferinfo): 查询企业付款到零钱\n- [payBank](https://sigoden.github.io/wechatpay/classes/pay#paybank): 企业付款到银行卡\n- [queryBank](https://sigoden.github.io/wechatpay/classes/pay#querybank): 查询企业付款到银行卡\n- [transfers](https://sigoden.github.io/wechatpay/classes/pay#transfers): 企业付款到零钱\n- [queryCouponStock](https://sigoden.github.io/wechatpay/classes/pay#querycouponstock): 查询代金券批次\n- [queryCouponsInfo](https://sigoden.github.io/wechatpay/classes/pay#querycouponsinfo): 查询代金券信息\n- [sendCoupon](https://sigoden.github.io/wechatpay/classes/pay#sendcoupon): 发放代金券\n- [getHbInfo](https://sigoden.github.io/wechatpay/classes/pay#gethbinfo): 查询红包记录\n- [sendGroupGroupRedPack](https://sigoden.github.io/wechatpay/classes/pay#sendgroupgroupredpack): 发放裂变红包\n- [sendRedPack](https://sigoden.github.io/wechatpay/classes/pay#sendredpack): 发放普通红包\n\n### 代扣相关接口\n\n- [contractNotify](https://sigoden.github.io/wechatpay/classes/entrust#contractnotify): 签约，解约结果通知\n- [contractOrder](https://sigoden.github.io/wechatpay/classes/entrust#contractorder): 支付中签约\n- [deleteContract](https://sigoden.github.io/wechatpay/classes/entrust#deletecontract): 申请解约\n- [entrust](https://sigoden.github.io/wechatpay/classes/entrust#entrust): 纯签约\n- [papOrderQuery](https://sigoden.github.io/wechatpay/classes/entrust#paporderquery): 查询订单\n- [papPayApply](https://sigoden.github.io/wechatpay/classes/entrust#pappayapply): 申请扣款\n- [papPayNotify](https://sigoden.github.io/wechatpay/classes/entrust#pappaynotify): 扣款结果通知\n- [queryContract](https://sigoden.github.io/wechatpay/classes/entrust#querycontract): 查询签约关系\n- [downloadBill](https://sigoden.github.io/wechatpay/classes/entrust#downloadbill): 下载对账单\n- [refund](https://sigoden.github.io/wechatpay/classes/entrust#refund): 申请退款\n- [refundQuery](https://sigoden.github.io/wechatpay/classes/entrust#refundquery): 查询退款\n\n## 许可证\n\nCopyright (c) 2018 sigoden\n\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigoden%2Fwechatpay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigoden%2Fwechatpay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigoden%2Fwechatpay/lists"}