Last active
December 28, 2017 06:54
Revisions
-
abisuq renamed this gist
Dec 27, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
abisuq created this gist
Dec 27, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ const uuid = require('uuid') const md5 = require('md5') const qs = require('query-string') const Router = require('koa-router') const apiRoute = new Router() const NOTIFY_URL = '' const CALLBACK_URL = '' const MCHID = 'π' const KEY = 'π' const API = 'https://payjs.cn/api/cashier' apiRoute.get('/pay', (ctx, next) => { const { title: body, fee: total_fee } = ctx.query const params = { mchid: MCHID, out_trade_no: uuid.v4().replace(/-/gi, ''), body, total_fee } if (NOTIFY_URL) { params.notify_url = NOTIFY_URL } if (CALLBACK_URL) { params.callback_url = CALLBACK_URL } params.sign = sign(params) const redirectURL = API + '?' + qs.stringify(params) console.log('β¨ REDIRECT URL π :', redirectURL) ctx.redirect(redirectURL) }) module.exports = apiRoute function sign(_) { return md5(qs.stringify(_) + `&key=${KEY}`).toUpperCase() }