{"id":19614782,"url":"https://github.com/leancloud/weapp-pay-getting-started","last_synced_at":"2025-04-28T01:32:17.844Z","repository":{"id":66228634,"uuid":"79693408","full_name":"leancloud/weapp-pay-getting-started","owner":"leancloud","description":"LeanCloud 小程序微信支付后端示例","archived":false,"fork":false,"pushed_at":"2022-11-29T03:06:14.000Z","size":21,"stargazers_count":61,"open_issues_count":1,"forks_count":18,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-05T04:51:15.642Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leancloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-22T04:23:26.000Z","updated_at":"2025-03-06T07:39:38.000Z","dependencies_parsed_at":"2023-07-12T12:45:15.158Z","dependency_job_id":null,"html_url":"https://github.com/leancloud/weapp-pay-getting-started","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/leancloud%2Fweapp-pay-getting-started","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fweapp-pay-getting-started/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fweapp-pay-getting-started/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fweapp-pay-getting-started/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leancloud","download_url":"https://codeload.github.com/leancloud/weapp-pay-getting-started/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251234131,"owners_count":21556787,"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":[],"created_at":"2024-11-11T10:53:43.674Z","updated_at":"2025-04-28T01:32:17.833Z","avatar_url":"https://github.com/leancloud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 小程序微信支付示例\n\n小程序微信支付「后端商户系统」。配合 LeanCloud 小程序 SDK 快速实现小程序微信支付功能。\n\n## 部署\n\n### 配置环境变量\n\n开始之前，请确保已经按照下面的步骤完成了环境变量的配置：\n\n1. 进入应用控制台 - 云引擎 - 设置\n2. 绑定域名\n3. 添加并保存以下环境变量\n  - `WEIXIN_APPID`：小程序 AppId\n  - `WEIXIN_MCHID`：微信支付商户号\n  - `WEIXIN_PAY_SECRET`：微信支付 API 密钥（[微信商户平台](https://pay.weixin.qq.com) - 账户设置 - API安全 - 密钥设置）\n  - `WEIXIN_NOTIFY_URL`：`https://{{yourdomain}}/weixin/pay-callback`，其中 `yourdomain` 是第二步中绑定的域名\n\n\u003cdetails\u003e\n\u003csummary\u003eExample\u003c/summary\u003e\n![image](https://cloud.githubusercontent.com/assets/175227/22236906/7c651c80-e243-11e6-819b-007d5862bdbf.png)\n\u003c/details\u003e\n\n### 本地开发\n\n首先确认本机已经安装 [Node.js](http://nodejs.org/) 运行环境和 [LeanCloud 命令行工具](https://leancloud.cn/docs/leanengine_cli.html)，然后执行下列指令：\n\n```\n$ git clone https://github.com/leancloud/weapp-pay-getting-started.git\n$ cd weapp-pay-getting-started\n```\n\n安装依赖：\n\n```\nnpm install\n```\n\n登录并关联应用：\n\n```\nlean login\nlean checkout\n```\n\n启动项目：\n\n```\nlean up\n```\n\n之后你就可以在 [localhost:3001](http://localhost:3001) 调试云函数了。\n\n### 部署\n\n部署到预备环境（若无预备环境则直接部署到生产环境）：\n```\nlean deploy\n```\n\n## 支付流程\n\n1. 登录用户在小程序客户端通过 JavaScript SDK 调用名为 `order` 的云函数下单。\n2. `order` 函数调用微信支付统一下单 API，创建「预订单」并保存在 Order 表中，返回签名过的预订单信息。\n3. 在小程序客户端调用支付 API，传入 2 中返回的预订单信息，发起支付。\n4. 支付成功后，微信通知 `/weixin/pay-callback` 支付成功，pay-callback 将对应的 order 状态更新为 `SUCCESS`。\n\n客户端的实例代码参见 [leancloud/leantodo-weapp](https://github.com/leancloud/leantodo-weapp)。\n\n## 相关文档\n\n* 小程序\n  * [在小程序中使用 LeanCloud](https://leancloud.cn/docs/weapp.html)\n  * [小程序支付客户端示例项目（LeanTodo)](https://github.com/leancloud/leantodo-weapp)\n* 支付\n  * [小程序客户端发起支付 API](https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-pay.html)\n  * [微信支付统一下单 API 参数与错误码](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1)\n  * [微信支付结果通知参数](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_7)\n* 云引擎\n  * [云函数开发指南](https://leancloud.cn/docs/leanengine_cloudfunction_guide-node.html)\n  * [网站托管开发指南](https://leancloud.cn/docs/leanengine_webhosting_guide-node.html)\n  * [JavaScript 开发指南](https://leancloud.cn/docs/leanstorage_guide-js.html)\n  * [JavaScript SDK API](https://leancloud.github.io/javascript-sdk/docs/)\n  * [Node.js SDK API](https://github.com/leancloud/leanengine-node-sdk/blob/master/API.md)\n  * [命令行工具使用指南](https://leancloud.cn/docs/cloud_code_commandline.html)\n  * [云引擎常见问题和解答](https://leancloud.cn/docs/leanengine_faq.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fweapp-pay-getting-started","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleancloud%2Fweapp-pay-getting-started","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fweapp-pay-getting-started/lists"}