qrcode_be/README.md
2019-12-09 09:48:07 +08:00

220 lines
4.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 收款码合成后端文档
## 目录结构
```
|-- lib
| |-- allFunction.py
| |-- db.py
| |-- login.py
| |-- pay.py
| |-- signature.py
|-- templates
| |-- 400.html
| |-- 404.html
| |-- 410.html
| |-- 500.html
| |-- qrcode.html
|-- hello.py
|-- README.md
```
## 接口列表及说明
```js
// $ 代表参数
// <> 代表数据类型
// 用户小程序登录
// 参数code , sign
/login
|-- manageLogin()
| |-- checkContent($code,$sign)
| | |-- getOpenid($code)
| | | |-- {'errmsg': '$openid', 'errcode': 200} // 请求成功
| | | |-- {'errmsg': '<str>', 'errcode': '<Num>'} // 请求失败
| | |
| | |-- False
| |
| |-- {'userInfo': findUser($openid), 'openid': 'str', 'errcode': 200} // 请求成功
| |-- {'errmsg': '<str>', 'errcode': '<Num>'} // 请求失败
| |-- False
|
|-- {'userInfo': findUser($openid), 'openid': 'str', 'errcode': 200} // 请求成功
|-- {'errmsg': '<str>', 'errcode': '<Num>'} // 请求失败
|-- 400
// 用户扫描二维码
// 参数 id
/qr
|-- findQR()
| |-- findCode($id)
| | |-- arr '<json -> Array>' //查询成功
| | |-- False // id不合法或者查询无结果
| |
| |-- arr '<json -> Array>' // 查询成功
| |-- False // id不合法或者查询无结果
|
|-- template('qrcode.html')
|-- 410
// 小程序刷新用户信息
// 参数 openId, sign
/reflash
|-- flash()
| |-- checkContent($openId, $sign)
| | |-- {'userInfo': findUser($openId) '<json -> Array>', 'errcode': 200} // 返回查询到的所有用户信息,可能为空数组
| | |-- False //openid不合法
| |
| |-- {'userInfo': findUser($openId) '<json -> Array>', 'errcode': 200}
| |-- False //openid不合法
|
|-- {'userInfo': findUser($openId) '<json -> Array>', 'errcode': 200}
|-- 400
// 小程序删除二维码
// 参数 id, sign
/del
|-- delQR()
| |-- checkContent($id, $sign)
| | |-- delCode($id)
| | | |-- {'errcode': 200, 'errmsg': 'ok'} //删除成功
| | | |-- False //id不合法
| | |
| | |-- {'errcode': 200, 'errmsg': 'ok'} //删除成功
| | |-- False
| |
| |-- {'errcode': 200, 'errmsg': 'ok'} //删除成功
| |-- False
|
|-- {'errcode': 200, 'errmsg': 'ok'} //删除成功
|-- 400
// 创建新的订单
// 参数 data, totalFee
/newOrder
|-- createOrder()
| |-- checkData($data)
| | |-- $param = createOrderParams($totalFee) // 创建订单详情
| | |-- $dataCache = createOrderCache($data, $params) // 把 out_trade_no 放进用户上传的data里边
| | |-- $res = insertOrderCache($dataCache) // 把 data放进cache 表里边
| | |-- {'params': params, 'errcode': 200} //上一步操作成功返回
| | |-- False //以上操作出问题
| |
| |-- {'params': params, 'errcode': 200}
| |-- False
|
|-- {'params': params, 'errcode': 200}
|-- 400
// 处理订单异步查询
/notify
|-- manageNotify()
| |-- checkNotify($form) //校验数据
| | |-- cache2Test($out_trade_no, payjs_order_id)
| | | |-- True //把缓存表中内容去出加上支付识别码放进正式表,在映射表建立 out_trade_no 到正式表 ObjectId 的映射
| | | |-- False //以上操作出错
| | |
| | |-- True
| | |-- False
| |
| |-- True
| |-- False
|
|-- True
|-- False
// 小程序查询订单状态
// 参数 out_trade_no
/checkOrder
|-- checkOrder()
| |-- findOrder($out_trade_no)
| | |-- order_id '<json -> String>' //查询映射表 out_trade_no 对应的 id
| | |-- False //查询无结果或者删除映射表的数据失败
| |
| |-- {'order_id': order_id, 'errcode': 200}
| |-- False
|
|-- {'order_id': order_id, 'errcode': 200}
|-- 500
```
## TODO
* MD5加解密 验证来源
## 配置环境
安装venv
`python3 -m venv venv`
启动venv
`. venv/bin/activate`
关闭venv
`deactivate`
查看现在已经安装的依赖
`pip3 list`
更新pip
`pip install --upgrade pip`
安装Flask
` pip install Flask`
安装最新的flask
`pip install -U https://github.com/pallets/flask/archive/master.tar.gz`
安装pymongo
` pip install pymongo`
安装requests
` pip install requests`
安装payjs
` pip install payjs`
设置全局变量
`export FLASK_APP=qrcode.py`
`export FLASK_ENV=development`
启动
`flask run --host=0.0.0.0`
在虚拟环境下安装gunicorn
`pip install gunicorn`
添加配置文件 gunicorn.conf
```
# 并行工作线程数
workers = 4
# 监听内网端口5000【按需要更改】
bind = '127.0.0.1:5000'
# 设置守护进程【关闭连接时,程序仍在运行】
daemon = True
# 设置超时时间120s默认为30s。按自己的需求进行设置
timeout = 120
# 设置访问日志和错误信息日志路径
# accesslog = './logs/acess.log'
# errorlog = './logs/error.log'
# 自动重启
autostart = True
```
启动gunicorn
`gunicorn qrcode:app -c gunicorn.conf`