https://github.com/willin/afdian-sdk
爱发电 SDK for Node.js & Browser
https://github.com/willin/afdian-sdk
Last synced: about 1 year ago
JSON representation
爱发电 SDK for Node.js & Browser
- Host: GitHub
- URL: https://github.com/willin/afdian-sdk
- Owner: willin
- License: apache-2.0
- Created: 2021-12-09T02:57:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-13T13:17:24.000Z (over 2 years ago)
- Last Synced: 2025-04-10T17:41:55.833Z (about 1 year ago)
- Language: TypeScript
- Size: 226 KB
- Stars: 7
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# afdian - 爱发电 SDK for Node.js & Browser
[](https://github.com/willin) [](https://npmjs.org/package/afdian) [](https://npmjs.org/package/afdian) [](https://npmjs.org/package/v0) [](https://app.travis-ci.com/willin/afdian-sdk) [](https://codeclimate.com/github/willin/afdian-sdk/maintainability) [](https://codeclimate.com/github/willin/afdian-sdk/test_coverage)
## 使用 Usage
### 安装 Install
```bash
yarn add afdian
# or
npm install --save afdian
```
### 引入 Import
```js
import Afdian, { AfdianClientOptions, AfdianSponsorResponse, AfdianOrderResponse } from 'afdian';
// 其中 { } 中 ts 类型可以不导入
// Types in { } block can be ignored
const afdian = new Afdian({
userId: 'xxxx',
token: 'xxxx'
});
// Ref: https://afdian.net/dashboard/dev
const res = await afdian.ping();
// {
// ec: 200,
// em: 'pong',
// data: { }
// }
// 查询订单
const res = await afdian.queryOrder(1);
// {
// ec: 200,
// em: 'order',
// data: {
// list: [],
// total_count: 0,
// total_page: 0
// }
// }
// 查询赞助者
const res = await afdian.querySponsor(1);
// {
// ec: 200,
// em: 'sponsor',
// data: {
// list: [],
// total_count: 0,
// total_page: 0
// }
// }
// 订单 Webhook 回调
const res = await afdian.webhookOrder(context);
// {
// "ec": 200,
// "em": "ok",
// "data": {
// "type": "order",
// "order": {
// "out_trade_no": "202106232138371083454010626",
// "user_id": "adf397fe8374811eaacee52540025c377",
// "plan_id": "a45353328af911eb973052540025c377",
// "month": 1,
// "total_amount": "5.00",
// "show_amount": "5.00",
// "status": 2,
// "remark": "",
// "redeem_id": "",
// "product_type": 0,
// "discount": "0.00",
// "sku_detail": [],
// "address_person": "",
// "address_phone": "",
// "address_address": ""
// }
// }
// }
```
## License
Apache 2.0
捐赠 / Donate: