{"id":16489117,"url":"https://github.com/thundernet8/youzanpayportal","last_synced_at":"2025-03-16T18:31:50.589Z","repository":{"id":79658659,"uuid":"119496996","full_name":"thundernet8/YouzanPayPortal","owner":"thundernet8","description":"利用有赞云和有赞微小店实现个人收款解决方案","archived":false,"fork":false,"pushed_at":"2018-09-23T06:25:51.000Z","size":55,"stargazers_count":183,"open_issues_count":3,"forks_count":34,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-02-27T12:15:08.298Z","etag":null,"topics":["alipay","wechat-pay","youzanyun"],"latest_commit_sha":null,"homepage":"https://webapproach.net/shop/experience-tint-qr-pay.html","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/thundernet8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-01-30T07:11:04.000Z","updated_at":"2024-12-24T14:44:37.000Z","dependencies_parsed_at":"2023-05-14T07:15:31.391Z","dependency_job_id":null,"html_url":"https://github.com/thundernet8/YouzanPayPortal","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/thundernet8%2FYouzanPayPortal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2FYouzanPayPortal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2FYouzanPayPortal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2FYouzanPayPortal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thundernet8","download_url":"https://codeload.github.com/thundernet8/YouzanPayPortal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826783,"owners_count":20354220,"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":["alipay","wechat-pay","youzanyun"],"created_at":"2024-10-11T13:43:06.559Z","updated_at":"2025-03-16T18:31:49.950Z","avatar_url":"https://github.com/thundernet8.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n## YouzanQrPayPortal\n\n**利用有赞云和有赞微小店实现个人收款解决方案 .**\n\n[![GitHub issues](https://img.shields.io/github/issues/thundernet8/YouzanPayPortal.svg)](https://github.com/thundernet8/YouzanPayPortal/issues)\n[![GitHub forks](https://img.shields.io/github/forks/thundernet8/YouzanPayPortal.svg)](https://github.com/thundernet8/YouzanPayPortal/network)\n[![GitHub stars](https://img.shields.io/github/stars/thundernet8/YouzanPayPortal.svg)](https://github.com/thundernet8/YouzanPayPortal/stargazers)\n[![dependency status](https://img.shields.io/david/thundernet8/YouzanPayPortal.svg?maxAge=3600\u0026style=flat)](https://david-dm.org/thundernet8/YouzanPayPortal)\n[![Build Status](https://travis-ci.org/thundernet8/YouzanPayPortal.svg?branch=master)](https://travis-ci.org/thundernet8/YouzanPayPortal)\n[![GitHub license](https://img.shields.io/github/license/thundernet8/YouzanPayPortal.svg)](https://github.com/thundernet8/YouzanPayPortal/blob/master/LICENSE)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n## Intro\n\n利用有赞云和有赞微小店实现个人收款解决方案, 提供如下两个服务:\n\n* 代理简化生成收款二维码的 API，支持微信支付宝扫描付款\n* 接收有赞云的交易消息推送并处理(需要二次请求交易详情)，简化订单状态通知到指定的服务器\n\n核心原理是提供了一个支付中转层，将自有商户订单与有赞云的订单绑定起来，实现支付状态更新\n\n为什么做成单独的服务:\n\n* 方便对接任何系统\n* 状态推送可以更灵活的自定义\n* 单独服务模式维护减少对原有系统影响\n\n## Usage\n\n### 有赞云端\n\n* 注册[有赞云](https://console.youzanyun.com/register) 开发者\n\n* 创建[有赞微小店](https://h5.youzan.com/v2/index/wxdpc) 并扫码下载相应 APP 便于后续管理资金，注意这个小店在有赞后台看不到，只有 APP 可见\n\n* 应用授权-有赞云控制台创建自用型应用并授权刚创建的店铺，在[推送服务]设置中设置推送网址*http://www.example.com/api/status* , 同时勾选下方的交易消息选项。\n\n### 本服务\n\n* 启动服务配置环境参数，复制`envrc.sample`为`envrc`并填写\n\n其中:\n\n`YOUZANYUN_CLIENT_ID`: 有赞云应用的 client_id\n\n`YOUZANYUN_CLIENT_SECRET`: 有赞云应用的 client_secret\n\n`YOUZAN_KDT_ID`: 有赞云应用绑定的微小店 ID\n\n`SELF_SECRET`: 自有订单系统接收本服务推送数据的加盐 secret\n\n`PUSH_API`: 自有订单系统接收本服务推送数据的地址\n\n```\nnpm run start // 启动服务\nnpm run list // 查看服务列表及状态\nnpm run stop // 停止服务\n```\n\n* 提供公网服务，请使用 Nginx 代理至 Node Server，这样能够让有赞推送消息到达推送网址\n\n### 自有订单系统端\n\n* 接入自有商店订单系统，支付时请求服务生成收款二维码\n\n    * 接口地址示例: `http://www.example.com/api/payment/qrcode`\n    * 调用方法 `POST application/json`\n    * 请求数据 `name`: 商品名, `price`: 价格(分), `order_id`: 自有系统的订单号\n    * 返回数据 \n        * 1. 正常情况 `qr_id`: 二维码 ID; `qr_url`: 有赞系统内支付地址(不推荐使用，需要付费者注册有赞); `qr_code`: Base64 图片数据，可直接作为 img 的 src 使用 \n        * 2. 异常情况 `null`\n\n\n    ```curl\n    curl -X POST -H 'Content-type: application/json' --data '{\"name\":\"test name\", \"price\": 1, \"order_id\": \"your orderid\"}' http://www.example.com/api/payment/qrcode\n    ```\n\n* 接收状态推送自有订单系统提供一个`PUSH_API`地址接收数据推送，数据格式如下:\n\n    ```json\n    {\n        \"tradeNo\": \"E20180201105656001353613-6377801\",\n        \"orderId\": \"1515174485676262\",\n        \"payment\": 10,\n        \"status\": \"TRADE_SUCCESS\",\n        \"sign\": \"c857c0f8d52ae9713a77b5c07dda93dc\",\n        \"time\": \"1517457474\"\n    }\n    ```\n\n    其中 sign 是`time`,`tradeNo`,`orderId`,`payment`,`status`,`SELF_SECRET`使用\"|\"拼接字符串的 MD5 特征值，请在状态接收端按此逻辑进行校验数据合法性\n\n    此外 status 的 enum 如下:\n\n    ```typescript\n    enum YZBusinessStatus {\n        // 等待买家付款\n        WAIT_BUYER_PAY = \"WAIT_BUYER_PAY\",\n        // 待确认，包括（待成团：拼团订单、待接单：外卖订单）\n        WAIT_CONFIRM = \"WAIT_CONFIRM\",\n        // 等待卖家发货，即:买家已付款\n        WAIT_SELLER_SEND_GOODS = \"WAIT_SELLER_SEND_GOODS\",\n        // 等待买家确认收货,即:卖家已发货\n        WAIT_BUYER_CONFIRM_GOODS = \"WAIT_BUYER_CONFIRM_GOODS\",\n        // 买家已签收\n        TRADE_BUYER_SIGNED = \"TRADE_BUYER_SIGNED\",\n        // 交易成功\n        TRADE_SUCCESS = \"TRADE_SUCCESS\",\n        // 交易关闭\n        TRADE_CLOSED = \"TRADE_CLOSED\"\n    }\n    ```\n\n    一般处理`TRADE_SUCCESS`和`TRADE_CLOSED`即可，返回 200 状态表示处理成功\n\n## TODO\n\n* [ ] 推送失败重推\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthundernet8%2Fyouzanpayportal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthundernet8%2Fyouzanpayportal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthundernet8%2Fyouzanpayportal/lists"}