{"id":15650189,"url":"https://github.com/gwuhaolin/direct-alipay","last_synced_at":"2025-04-30T17:29:42.837Z","repository":{"id":80950190,"uuid":"44290515","full_name":"gwuhaolin/direct-alipay","owner":"gwuhaolin","description":"alipay api for nodejs","archived":false,"fork":false,"pushed_at":"2017-11-13T02:35:47.000Z","size":20,"stargazers_count":36,"open_issues_count":0,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-12T12:18:32.058Z","etag":null,"topics":["alipay","nodejs"],"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/gwuhaolin.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":"2015-10-15T03:02:52.000Z","updated_at":"2021-10-24T10:24:23.000Z","dependencies_parsed_at":"2023-03-12T12:49:12.417Z","dependency_job_id":null,"html_url":"https://github.com/gwuhaolin/direct-alipay","commit_stats":{"total_commits":26,"total_committers":4,"mean_commits":6.5,"dds":0.3076923076923077,"last_synced_commit":"5105971c1cf006de0c09ad200ec910efed387afd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gwuhaolin%2Fdirect-alipay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gwuhaolin%2Fdirect-alipay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gwuhaolin%2Fdirect-alipay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gwuhaolin%2Fdirect-alipay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gwuhaolin","download_url":"https://codeload.github.com/gwuhaolin/direct-alipay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249543297,"owners_count":21288703,"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","nodejs"],"created_at":"2024-10-03T12:33:53.112Z","updated_at":"2025-04-18T20:31:22.305Z","avatar_url":"https://github.com/gwuhaolin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Npm Package](https://img.shields.io/npm/v/direct-alipay.svg?style=flat-square)](https://www.npmjs.com/package/direct-alipay)\n[![Npm Downloads](http://img.shields.io/npm/dm/direct-alipay.svg?style=flat-square)](https://www.npmjs.com/package/direct-alipay)\n[![Dependency Status](https://david-dm.org/gwuhaolin/direct-alipay.svg?style=flat-square)](https://npmjs.org/package/direct-alipay)\n\n# 支付宝 即时到账 NodeJS包 [demo](http://ccnu-aa.leanapp.cn/)\n\n## 集成到你的项目\n\n#### 1.安装\n```bash\n    npm install direct-alipay\n```    \n\n#### 2.配置支付宝参数\n```js\n    var directAlipay = require('direct-alipay');\n    directAlipay.config({\n        seller_email: 'jyjjh@mail.ccnu.edu.cn',\n        partner: '2088911275465084',\n        key: 'tws3ri4d3sg8ohc4t7k9dnj8kumvia05',\n        return_url: 'http://127.0.0.1:3000/return'\n    }); \n```   \n    \n参数说明见[支付宝官方文档](https://openhome.alipay.com/platform/document.htm#webApp-directPay-API-direct)\n    \n#### 3.传入订单参数,生成支付跳转URL\n```js\n    var url = directAlipay.buildDirectPayURL({\n        out_trade_no: Date.now().toString() + Math.random(),//业务侧需要为每个订单生成一个唯一订单号\n        subject: '给华中师范大学贫困学生的捐赠',//订单标题\n        body: 'body',\n        total_fee: '1'//订单金额，单位元\n    });\n```\n   \n#### 4.引导用户跳转到获得的URL，跳转到支付宝支付界面\n```js\n    window.location.href = url;\n```\n\n#### 5.用户支付完毕后,会跳转到第2步配置的return_url，在这里来判断订单是否成功支付\n```js\n    app.get('/return', function (req, res) {\n        var params = req.query;\n        directAlipay.verify(params).then(function() {\n                  //该通知是来自支付宝的合法通知\n        }).catch(function(err) {\n            console.error(err);\n        });\n    });\n```\n    \n支付宝回调通知见[官方文档](https://openhome.alipay.com/platform/document.htm#webApp-transPay-transpay-notify)\n\n## 运行Demo\n仔细`npm start`后，用浏览器打开`http://localhost:3000`\n\n## 文档\n\n##### `directAlipay`\n所有方法的入口\n```js\n    var directAlipay = require('direct-alipay');\n```\n\n##### `directAlipay.config(params)`\n配置支付宝基础配置，在使用前先配置.\n```js\n    directAlipay.config({\n        //签约支付宝账号或卖家收款支付宝帐户\n        seller_email: 'jyjjh@mail.ccnu.edu.cn',\n        //合作身份者ID，以2088开头由16位纯数字组成的字符串\n        partner: '2088911275465084',\n        //交易安全检验码，由数字和字母组成的32位字符串\n        key: 'tws3ri4d3sg8ohc4t7k9dnj8kumvia05',\n        //支付宝服务器通知的页面\n        notify_url: 'http://127.0.0.1:3000/notify',\n        //支付后跳转后的页面\n        return_url: 'http://127.0.0.1:3000/'\n    }); \n```     \n    \n其它配置参数见[官方文档](https://openhome.alipay.com/platform/document.htm#webApp-directPay-API-direct)\n\n##### `directAlipay.buildDirectPayURL(params)`\n使用订单参数构造一个支付请求\n```js\n    directAlipay.buildDirectPayURL({\n        out_trade_no: '你的网站订单系统中的唯一订单号匹配',\n        subject: '订单名称显示在支付宝收银台里的“商品名称”里，显示在支付宝的交易管理的“商品名称”的列表里',\n        body: '订单描述、订单详细、订单备注，显示在支付宝收银台里的“商品描述”里',\n        total_fee: '订单总金额'\n    });\n```\n\n返回支付宝支付请求URL 浏览器跳转到该url支付\n\n##### `directAlipay.verify(params)`\n验证来自支付宝的通知是否合法\n```js\n    app.get('/notify', function (req, res) {\n        var params = req.body;\n        directAlipay.verify(params).then(function() {\n          //该通知是来自支付宝的合法通知\n        }).catch(function(err) {\n          console.error(err);\n        })\n    });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgwuhaolin%2Fdirect-alipay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgwuhaolin%2Fdirect-alipay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgwuhaolin%2Fdirect-alipay/lists"}