[WIP] 打造一个基于github登录与微信支付,但又不依赖于微信登录(由github登录替代)的创新型支付体系,简称gx。
要求:前端页面、node后端、注册一个github-oauth应用、一个开通微信支付的公众号及商户信息。
location.href = 'https://example.com/gx/api/login'
+ `?from=${encodeURIComponent(location.href)}`
let { error, user, paid } = await request({
url: 'https://example.com/gx/api/session'
})
let { error, code_url } = await request({
url: 'https://example.com/gx/api/order',
query: {
product_id,
user_id,
appid
}
})
let { openid } = await request({
url: 'https://example.com/gx/api/wx/token',
query: {
code,
appid
}
})
let { error, prepay_id } = await request({
url: 'https://example.com/gx/api/order',
query: {
trade_type: 'JSAPI',
openid,
product_id,
user_id,
appid
}
})
// gx.conf.example.js
let host_url = 'https://example.com/gx'
let host_ip = '120.11.11.111'
module.exports = {
gh: {
client_id: 'xxxxxxxxxxxxxxxxxxxx',
client_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
callback_url: `${host_url}/api/oauth/callback`
},
wx: {
mps: [ // 公众号/小程序
{
oid: 'xxxxxxxxxxxxxxx', // 原始id
appid: 'xxxxxxxxxxxxxxxxxx', // 开发者id
secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' // 秘钥
}
],
mch_id: 'xxxxxxxxxx', // 商户号
mch_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // 商户key
notify_url: `${host_url}/api/wxpay/notify`, // 通知地址
host_ip
},
app: {
keys: ['xxxxxx']
}
}