This repository has been archived by the owner on Mar 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
138 changed files
with
5,599 additions
and
758 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# 使用的是 REST Client 插件 | ||
|
||
### login | ||
POST http://localhost:7001/api/v1/user/login HTTP/1.1 | ||
content-type: application/json | ||
|
||
{ | ||
"username": "tlgc", | ||
"password": "qwer1234" | ||
} | ||
|
||
### login | ||
POST http://localhost:7001/api/v1/user/login HTTP/1.1 | ||
content-type: application/json | ||
|
||
{ | ||
"username": "tour", | ||
"password": "tour520" | ||
} | ||
|
||
### get weixin user | ||
GET http://localhost:7001/api/v1/wuser?pageSize=10&pageField=id HTTP/1.1 | ||
User-Agent: rest-client | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1NjQyMTU0OTUsImV4cCI6MTU2NDM4ODI5NX0.amsnvOa-aAxCc0IkD_5VCpyM3g2f_9JhPrAUlqWxTwo | ||
content-type: application/json | ||
|
||
### get weixin user | ||
GET http://localhost:7001/api/v1/wuser?pageSize=10&pageField=count HTTP/1.1 | ||
User-Agent: rest-client | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1NjQyMTU0OTUsImV4cCI6MTU2NDM4ODI5NX0.amsnvOa-aAxCc0IkD_5VCpyM3g2f_9JhPrAUlqWxTwo | ||
content-type: application/json | ||
|
||
### get system log | ||
GET http://localhost:7001/api/v1/log HTTP/1.1 | ||
User-Agent: rest-client | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1NjQyMTU0OTUsImV4cCI6MTU2NDM4ODI5NX0.amsnvOa-aAxCc0IkD_5VCpyM3g2f_9JhPrAUlqWxTwo | ||
content-type: application/json | ||
|
||
|
||
|
||
|
||
###################################################### | ||
###################################################### | ||
### get system log | ||
GET http://localhost:7001/api/v1/log HTTP/1.1 | ||
User-Agent: rest-client | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1NjM0MzIwODAsImV4cCI6MTU2MzYwNDg4MH0.F00GVxtJXLVE2VOCjp2SG3blB9BFNQjh8o2XIJTDkYM | ||
content-type: application/json | ||
|
||
### | ||
POST http://localhost:7001/api/v1/user/login HTTP/1.1 | ||
content-type: application/json | ||
|
||
{ | ||
"username": "tlgc", | ||
"password": "qwer1234" | ||
} | ||
|
||
### | ||
POST http://localhost:7001/api/v1/user/login HTTP/1.1 | ||
content-type: application/json | ||
|
||
{ | ||
"username": "tour", | ||
"password": "tour520" | ||
} | ||
|
||
### | ||
GET http://localhost:7001/api/v1/article HTTP/1.1 | ||
content-type: application/json | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1ODQ2MjkxMTMsImV4cCI6MTU4NDgwMTkxM30.uRrAdmi0Kpn0DhMbJoIBLFrGbqhNoabm7eKm1ElsQYU | ||
|
||
### | ||
GET http://localhost:7001/api/v1/wechat/logout HTTP/1.1 | ||
content-type: application/json | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1NjQyMjAxNDQsImV4cCI6MTU2NDM5Mjk0NH0.HXHFIx_tRTOOZOC9e5DWjb6zyC-NDEYxCqWd93LRl0M | ||
|
||
### | ||
GET http://localhost:7001 HTTP/1.1 | ||
content-type: application/json | ||
|
||
### | ||
GET http://localhost:7001/api/v1/test HTTP/1.1 | ||
content-type: application/json | ||
|
||
### | ||
GET http://localhost:7001/api/v1/captcha HTTP/1.1 | ||
content-type: application/json | ||
|
||
### | ||
GET http://ip.taobao.com/service/getIpInfo.php?ip=116.231.196.113 | ||
|
||
### | ||
GET http://localhost:7001/api/v1/cars/all HTTP/1.1 | ||
Content-Type: application/json | ||
|
||
### | ||
POST http://192.168.99.186:7001/api/v1/location HTTP/1.1 | ||
Content-Type: application/json | ||
|
||
{ | ||
"latitude": 1, | ||
"longitude": 1 | ||
} | ||
|
||
### | ||
GET http://192.168.99.186:7001/api/v1/location/current HTTP/1.1 | ||
Content-Type: application/json | ||
|
||
### | ||
POST http://localhost/hdfq/uvCount HTTP/1.1 | ||
Content-Type: application/json | ||
|
||
### | ||
POST http://localhost:7001/api/v1/pay HTTP/1.1 | ||
Content-Type: application/json | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1ODUxMjg3MzQsImV4cCI6MTU4NTMwMTUzNH0.qTYj2_NxOJsiiqORYVSg7XDwRCFmMZ3B-aesOy0ME-c | ||
|
||
{ | ||
"outTradeNo": "1231424142313", | ||
"totalAmount": 0.01, | ||
"subject": "ceui", | ||
"body": "ceui", | ||
"address": "长江", | ||
"mobile": 15755555555, | ||
"number": 1 | ||
} | ||
|
||
|
||
### | ||
GET http://localhost:7001/api/v1/pay/order/fewfewafewwefaaaaaaaaaaaaaa HTTP/1.1 | ||
Content-Type: application/json | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1ODUxMjg3MzQsImV4cCI6MTU4NTMwMTUzNH0.qTYj2_NxOJsiiqORYVSg7XDwRCFmMZ3B-aesOy0ME-c | ||
|
||
#Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1ODUxMjg3MzQsImV4cCI6MTU4NTMwMTUzNH0.qTYj2_NxOJsiiqORYVSg7XDwRCFmMZ3B-aesOy0ME-c | ||
### | ||
GET http://localhost:7001/api/v1/pay/order HTTP/1.1 | ||
Content-Type: application/json | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1ODUxMjg3MzQsImV4cCI6MTU4NTMwMTUzNH0.qTYj2_NxOJsiiqORYVSg7XDwRCFmMZ3B-aesOy0ME-c | ||
|
||
|
||
### | ||
GET http://localhost:7001/api/v1/pay/status/22222222222222 HTTP/1.1 | ||
Content-Type: application/json | ||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJ0bGdjIiwicm9sZSI6InN1cGVyQWRtaW4iLCJpYXQiOjE1ODUxMjg3MzQsImV4cCI6MTU4NTMwMTUzNH0.qTYj2_NxOJsiiqORYVSg7XDwRCFmMZ3B-aesOy0ME-c | ||
|
||
### | ||
GET http://localhost:7001/api/v2/toutiao/text/蛤蟆 HTTP/1.1 | ||
Content-Type: application/json |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
'use strict' | ||
|
||
const Controller = require('egg').Controller | ||
|
||
class AlipayController extends Controller { | ||
/** | ||
* PC网页支付 | ||
*/ | ||
async pay() { | ||
const { ctx } = this | ||
const { alipay } = ctx.service.v1 | ||
const data = ctx.request.body | ||
ctx.validate({ | ||
outTradeNo: {type: 'string', require: true}, | ||
totalAmount: {type: 'number', max:100000000, min:0.01, require: true}, | ||
subject: {type: 'string', require: true} | ||
}, data) | ||
const url = await alipay.pay(data) | ||
if (url) { | ||
ctx.status = 201 | ||
ctx.helper.success({ctx, res: url}) | ||
} else { | ||
ctx.helper.fail({ctx, res: '付款失败'}) | ||
} | ||
} | ||
|
||
/** | ||
* 手机端网页支付 | ||
*/ | ||
async mobilePay() { | ||
const { ctx } = this | ||
const { alipay } = ctx.service.v1 | ||
const data = ctx.request.body | ||
ctx.validate({ | ||
outTradeNo: {type: 'string', require: true}, | ||
totalAmount: {type: 'number', max:100000000, min:0.01, require: true}, | ||
subject: {type: 'string', require: true} | ||
}, data) | ||
const form = await alipay.mobilePay(data) | ||
if (form) { | ||
ctx.status = 201 | ||
ctx.helper.success({ctx, res: form}) | ||
} else { | ||
ctx.helper.fail({ctx, res: '付款失败'}) | ||
} | ||
} | ||
|
||
/** | ||
* 支付回调 | ||
*/ | ||
async payCallback() { | ||
const { ctx } = this | ||
const { alipay } = ctx.service.v1 | ||
const data = ctx.request.body | ||
const result = await alipay.checkSign(data) | ||
ctx.body = { | ||
result | ||
} | ||
} | ||
|
||
/** | ||
* 查询支付 | ||
*/ | ||
async query() { | ||
const {ctx} = this | ||
const { alipay } = ctx.service.v1 | ||
const outTradeNo = ctx.params.outTradeNo | ||
ctx.validate({ | ||
outTradeNo: {type: 'string', require: true} | ||
}, ctx.params) | ||
const result = await alipay.query(outTradeNo) | ||
ctx.helper.success({ctx, res: result}) | ||
} | ||
|
||
/** | ||
* 用户获取自己的订单 | ||
*/ | ||
async getOrderByUser () { | ||
const { ctx, app } = this | ||
// 获取用户id | ||
const userInfo = app.verifyToken(ctx) | ||
const { id: userId, role } = userInfo | ||
let { page } = ctx | ||
const { common } = ctx.service.v1 | ||
const search = ctx.request.query | ||
let where = {} | ||
where = { | ||
user_id: userId | ||
} | ||
if (role === 'superAdmin') { | ||
if (search.hasOwnProperty('userId') && search.userId !== '') { | ||
where = { | ||
user_id: search.userId | ||
} | ||
} else { | ||
where = {} | ||
} | ||
} | ||
page = { | ||
...page, | ||
pageField: 'id', | ||
pageSort: 'DESC' | ||
} | ||
const include = [] | ||
const [total, items] = await Promise.all([ | ||
common.findCount({ modelName: 'Order' }), | ||
common.findPage({ | ||
modelName: 'Order', | ||
page, | ||
include, | ||
where | ||
}) | ||
]) | ||
const res = { total, items, pageSize: page.pageSize, pageIndex: page.pageIndex } | ||
ctx.helper.success({ ctx, res: res }) | ||
} | ||
|
||
/** | ||
* 用户查询订单支付状态 | ||
*/ | ||
async checkPay () { | ||
const { ctx } = this | ||
const { alipay } = ctx.service.v1 | ||
const outTradeNo = ctx.params.outTradeNo | ||
const result = await alipay.checkPay(outTradeNo) | ||
if (result) { | ||
ctx.helper.success({ctx, res: {status: true}, msg: '支付成功'}) | ||
} else { | ||
ctx.helper.success({ctx, res: {status: false}, msg: '未支付'}) | ||
} | ||
} | ||
} | ||
|
||
module.exports = AlipayController |
Oops, something went wrong.