{"id":15650854,"url":"https://github.com/kaelzhang/egg-wechat-pay","last_synced_at":"2025-07-09T05:37:40.888Z","repository":{"id":57220886,"uuid":"116197751","full_name":"kaelzhang/egg-wechat-pay","owner":"kaelzhang","description":"Wechat pay plugin for egg（WIP）","archived":false,"fork":false,"pushed_at":"2018-05-27T23:44:47.000Z","size":14,"stargazers_count":34,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-13T18:16:06.707Z","etag":null,"topics":["egg","egg-plugin","wechat-pay"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":"History.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-01-04T01:05:33.000Z","updated_at":"2023-04-14T18:08:43.000Z","dependencies_parsed_at":"2022-08-29T04:01:39.382Z","dependency_job_id":null,"html_url":"https://github.com/kaelzhang/egg-wechat-pay","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/kaelzhang/egg-wechat-pay","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fegg-wechat-pay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fegg-wechat-pay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fegg-wechat-pay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fegg-wechat-pay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/egg-wechat-pay/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fegg-wechat-pay/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260783897,"owners_count":23062430,"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":["egg","egg-plugin","wechat-pay"],"created_at":"2024-10-03T12:36:05.254Z","updated_at":"2025-07-09T05:37:40.827Z","avatar_url":"https://github.com/kaelzhang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/kaelzhang/egg-wechat-pay.svg?branch=master)](https://travis-ci.org/kaelzhang/egg-wechat-pay)\n[![Coverage](https://codecov.io/gh/kaelzhang/egg-wechat-pay/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/egg-wechat-pay)\n\u003c!-- optional appveyor tst\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/egg-wechat-pay?branch=master\u0026svg=true)](https://ci.appveyor.com/project/kaelzhang/egg-wechat-pay)\n--\u003e\n\u003c!-- optional npm version\n[![NPM version](https://badge.fury.io/js/err-object.svg)](http://badge.fury.io/js/err-object)\n--\u003e\n\u003c!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/err-object.svg)](https://www.npmjs.org/package/err-object)\n--\u003e\n\u003c!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/egg-wechat-pay.svg)](https://david-dm.org/kaelzhang/egg-wechat-pay)\n--\u003e\n\n# egg-wechat-pay\n\nWechat pay plugin for egg.\n\n## Install\n\n```sh\n$ npm i egg-wechat-pay\n```\n\n## Configurations\n\nconfig/plugin.js\n\n```js\nexports.wechatPay = {\n  enable: true,\n  package: 'egg-wechat-pay'\n}\n```\n\nconfig/config.default.js\n\n```js\nexports.wechatPay = {\n  client: {\n    // Optional,\n    bodyPrefix: '麦当劳',\n    appId,\n    merchantId,\n    secret,\n    notifyUrl,\n    pfx: fs.readFileSync(thePathToPFX)\n  }\n}\n```\n\nThen:\n\n```js\n...\n  async doSomething () {\n    const params = await this.app.wechatPay.requestPayment(order)\n    // {\n    //   \"appId\": \"wx...\",\n    //   \"timeStamp\": \"1515043618\",\n    //   \"nonceStr\": \"V0UGYV...\",\n    //   \"signType\": \"MD5\",\n    //   \"package\": \"prepay_id=wx2018...\",\n    //   \"paySign\": \"54AD...\",\n    //   \"timestamp\": \"1515043618\"\n    // }\n  }\n...\n```\n\n### config.wechatPay.client\n\n- **bodyPrefix** `?String` 商品描述的前缀，避免每次都需要写商品描述，[格式见](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_2)\n- **appId** `String` 应用的 appId，注意，该应用（小程序，服务号）需要开通微信支付功能，否则会报 `商户号mch_id与appid不匹配` 的错误\n- **merchantId** `String` 微信商户号，即 `mch_id`\n- **secret** `String` 微信支付的 API 密钥，请到 \"微信支付|商户平台 -\u003e API安全\" 页面获取\n- **notifyUrl** `URL` 接收微信支付异步通知回调地址，通知url必须为直接可访问的url，不能携带参数\n- **pfx** `Buffer | String` 微信支付 API 证书（p12证书）\n\n### await wechatPay.requestPayment(order)\n\n- **order** `Object` [统一下单接口](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1\u0026index=1)的参数\n  - **ip** `String` 它是 `spbill_create_ip` 参数的简写\n  - 其他参数\n\n返回[再次签名](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7\u0026index=3)的回调结果，该结果可以直接被小程序，JSBridge，或客户端调用。\n\n```js\nconst payment = await wechatPay.requestPayment(order)\n\n// https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-pay.html#wxrequestpaymentobject\nwx.requestPayment({\n  ...payment,\n  success (res) {\n\n  },\n  fail (res) {\n\n  }\n})\n```\n\n### wechatPay.newApp(appId)\n\n创建另一个应用的微信支付实例，可创建与同一个微信支付商户绑定的多个应用的实例\n\n```js\nconst params = this.app.wechatPay.newApp('wx2...')\n.requestPayment(order)\n```\n\n### await wechatPay.parse(xml)\n\n将微信支付通知中的 `return_msg`(XML) 转换为 JavaScript 对象。XML 通知的结构见 [这个文档](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_7)。\n\n这个方法在转换的过程中，还会结合 [`config.wechatPay.client`](#configwechatpayclient) 校验 XML 是否有效，否则会 reject。\n\n返回 `Object`\n\n### wechatPay.stringify(object)\n\n将 JavaScript 转换为 XML 文本\n\n返回 `String`\n\n### wechatPay.success(ctx)\n\n- **ctx** `EggContext`\n\n向微信返回成功响应\n\n### wechatPay.fail(ctx, message)\n\n- **ctx** `EggContext`\n- **message** `String` 作为 `return_msg` 的值\n\n向微信返回失败的响应\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fegg-wechat-pay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Fegg-wechat-pay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fegg-wechat-pay/lists"}