UNPKG

afdian

Version:

爱发电 SDK for Node.js and Browser

117 lines (94 loc) 3.65 kB
var $8zHUo$isomorphicunfetch = require("isomorphic-unfetch"); var $8zHUo$cryptojsmd5 = require("crypto-js/md5"); function $parcel$defineInteropFlag(a) { Object.defineProperty(a, '__esModule', {value: true, configurable: true}); } function $parcel$exportWildcard(dest, source) { Object.keys(source).forEach(function(key) { if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) { return; } Object.defineProperty(dest, key, { enumerable: true, get: function get() { return source[key]; } }); }); return dest; } function $parcel$export(e, n, v, s) { Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); } function $parcel$interopDefault(a) { return a && a.__esModule ? a.default : a; } $parcel$defineInteropFlag(module.exports); $parcel$export(module.exports, "default", () => $882b6d93070905b3$export$2e2bcd8739ae039); var $53ffd25df6034fb9$exports = {}; $parcel$export($53ffd25df6034fb9$exports, "Afdian", () => $53ffd25df6034fb9$export$5075110fe13e4f25); const $95a12c7e64004967$var$API_BASE = 'https://afdian.com/api/open'; const $95a12c7e64004967$var$getUrl = (path)=>`${$95a12c7e64004967$var$API_BASE}/${path}`; var $95a12c7e64004967$export$2e2bcd8739ae039 = { ping: $95a12c7e64004967$var$getUrl('ping'), queryOrder: $95a12c7e64004967$var$getUrl('query-order'), querySponsor: $95a12c7e64004967$var$getUrl('query-sponsor') }; const $6abb7b16f118375b$export$6c5295ef7e82f2b2 = (userId, params)=>{ const req = { user_id: userId, ts: Math.floor(Date.now() / 1000), params: JSON.stringify(params || { empty: true }) }; return req; }; const $6abb7b16f118375b$export$aa7d25cddbad24ed = (token, body)=>{ const toSign = `${token}params${body.params}ts${body.ts}user_id${body.user_id}`; const sign = (0, ($parcel$interopDefault($8zHUo$cryptojsmd5)))(toSign).toString(); return { ...body, sign: sign }; }; class $53ffd25df6034fb9$export$5075110fe13e4f25 { constructor(opts){ const { userId: userId, token: token } = opts; this.userId = userId; this.token = token; } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type send(url, params) { const signed = (0, $6abb7b16f118375b$export$aa7d25cddbad24ed)(this.token, (0, $6abb7b16f118375b$export$6c5295ef7e82f2b2)(this.userId, params)); return (0, ($parcel$interopDefault($8zHUo$isomorphicunfetch)))(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(signed) }).then((res)=>res.json()); } /* eslint-disable @typescript-eslint/no-unsafe-return */ ping() { return this.send((0, $95a12c7e64004967$export$2e2bcd8739ae039).ping); } queryOrder(page) { return this.send((0, $95a12c7e64004967$export$2e2bcd8739ae039).queryOrder, { page: page }); } querySponsor(page) { return this.send((0, $95a12c7e64004967$export$2e2bcd8739ae039).querySponsor, { page: page }); } // eslint-disable-next-line class-methods-use-this webhookOrder(context) { return context; } } var $faefaad95e5fcca0$exports = {}; var $882b6d93070905b3$export$2e2bcd8739ae039 = (0, $53ffd25df6034fb9$export$5075110fe13e4f25); $parcel$exportWildcard(module.exports, $53ffd25df6034fb9$exports); $parcel$exportWildcard(module.exports, $faefaad95e5fcca0$exports); //# sourceMappingURL=main.js.map