del payjs functions

This commit is contained in:
RainSun 2019-12-08 11:21:13 +08:00
parent 05d8c0ce5a
commit 7c70274be3
7 changed files with 216 additions and 51 deletions

View File

@ -1,4 +1,4 @@
from db import findUser, findCode, delCode, insertOrderCache, cache2Test, findOrder
from db import findUser, findCode, delCode, insertOrderCache, cache2Test, findOrder, insertCode
from login import getOpenid
from pay import checkNotify, createOrderParams
import re
@ -64,6 +64,20 @@ def delQR(request):
else:
return False
# 用户上传二维码
def addQR(request):
# 流程同createOrder一样但是直接插入到正式表中然后返回id
dataCache = json.loads(request.form['data']) # josn化应该能当dist用
checked = checkData(dataCache) # 校验所有用户上传的内容
if checked:
res = insertCode(checked)
if res:
return {'errcode': 200, 'id': res}
else:
return False
else:
return False
# 微信小程序创建订单 debug完成
def createOrder(request):
@ -257,7 +271,7 @@ def checkData(data):
return False
if hrefCount >= 2 and usernameCount and openIdCount and timeoutCount:
return {'username': username, 'node': node, 'wxcode': wxcode, 'alcode': alcode, 'qqcode': qqcode, 'openId': openId, 'timeout': timeout}
return {'username': username, 'node': node, 'wxcode': wxcode, 'alcode': alcode, 'qqcode': qqcode, 'openId': openId, 'timeout': timeout, 'create_time':int(time.time())}
else:
return False

View File

@ -18,11 +18,13 @@ def col(arg: str = None):
return conn.yingbo.order
elif param == 'cache':
return conn.yingbo.cache
elif param == 'code':
return conn.yingbo.code
# 查找该用户所有信息
def findUser(openid):
arr = []
for i in col().find({'openId': openid}):
for i in col('code').find({'openId': openid}):
arr.append(i)
return json_util.dumps(arr)
@ -30,7 +32,7 @@ def findUser(openid):
def findCode(id):
arr = []
try:
for i in col().find({"_id" : ObjectId(id)}):
for i in col('code').find({"_id" : ObjectId(id)}):
arr.append(i)
except Exception as e:
# id不合法
@ -43,7 +45,7 @@ def findCode(id):
# 删除该二维码
def delCode(id):
try:
col().remove({"_id" : ObjectId(id)})
col('code').remove({"_id" : ObjectId(id)})
except Exception as e:
# id不合法
return False
@ -105,4 +107,14 @@ def findOrder(out_trade_no):
except Exception as e:
# 失败
return False
return json_util.dumps(arr[0]['inserted_id'])
return json_util.dumps(arr[0]['inserted_id'])
# 用户上传进入主表
def insertCode(data):
try:
res = col('code').insert_one(data)
inserted_id = res.inserted_id
except Exception as e:
# 失败
return False
return json_util.dumps(inserted_id)

View File

@ -3,7 +3,7 @@ sys.path.append('./lib')
import os
from flask import Flask, escape, url_for, request, render_template, redirect, abort, send_from_directory
from allFunction import manageLogin, findQR, flash, delQR, manageNotify, createOrder, checkOrder
from allFunction import manageLogin, findQR, flash, delQR, manageNotify, createOrder, checkOrder, addQR
app = Flask(__name__)
@ -46,30 +46,45 @@ def delQRCode():
else:
abort(400)
# 创建新的订单
@app.route('/newOrder',methods=['POST'])
def newOrder():
res = createOrder(request)
# 用户添加二维码
@app.route('/add',methods=['POST'])
def addQRCode():
res = addQR(request)
if(res):
return res
else:
abort(400)
# 处理订单异步通知
@app.route('/notify',methods=['POST'])
def notify():
manageNotify(request)
return 'ok'
# 创建新的订单(暂时废弃)
# @app.route('/newOrder',methods=['POST'])
# def newOrder():
# res = createOrder(request)
# if(res):
# return res
# else:
# abort(400)
# 处理订单异步通知(暂时废弃)
# @app.route('/notify',methods=['POST'])
# def notify():
# manageNotify(request)
# return 'ok'
# 小程序查询订单状态(暂时废弃)
# @app.route('/checkOrder',methods=['POST'])
# def check():
# res = checkOrder(request)
# print(res)
# if res:
# return res
# else:
# abort(500)
# 控制小程序是否显示“最佳案例”
@app.route('/config', methods=['post'])
def config():
return {'errcode': 200, 'showBest': 'true'}
# 小程序查询订单状态
@app.route('/checkOrder',methods=['POST'])
def check():
res = checkOrder(request)
print(res)
if res:
return res
else:
abort(500)
# 图标
@app.route('/favicon.ico')

View File

@ -59,7 +59,7 @@ const login = callBack => {
})
}
const createOder = (totalFee, data, callBack) => {
const createOrder = (totalFee, data, callBack) => {
wx.request({
url: 'https://qr.powerrain.cn/newOrder',
method: 'POST',
@ -136,7 +136,6 @@ const reflash = (openId, callBack) => {
icon: "none"
})
} else {
wx.hideLoading();
callBack && callBack(JSON.parse(res.data.userInfo))
}
},
@ -193,11 +192,61 @@ const checkOrder = (out_trade_no, callBack, cancelCallBack) => {
})
}
const getConfig = (callback) => {
wx.request({
url: 'https://qr.powerrain.cn/config',
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
},
success: function (res) {
if(res.data.errcode == 200) {
delete res.data.errcode
callback && callback(res.data)
} else {
delete res.data.errcode
callback && callback(res.data)
}
},
fail: function () {
callback && callback(false)
}
})
}
const createCode = (data, callBack) => {
wx.request({
url: 'https://qr.powerrain.cn/add',
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
data:JSON.stringify(data),
},
success: function (res) {
if (res.data.errcode !== 200) {
wx.hideLoading();
wx.showToast({
title: "创建订单失败",
icon: "none"
})
} else {
callBack && callBack(JSON.parse(res.data.id)['$oid']);
}
},
})
}
module.exports = {
getyiyian: getyiyian, // callBack()
login: login, // callBack(res.data)
createOder: createOder, // totalFee, data, callBack(res.data.params)
createOrder: createOrder, // totalFee, data, callBack(res.data.params)
delCode: delCode, // id, callBack()
reflash: reflash, // openId, callBack(userInfo)
checkOrder: checkOrder // out_trade_no, callBack(order_id)
checkOrder: checkOrder, // out_trade_no, callBack(order_id)
getConfig: getConfig, // callback
createCode:createCode
}

View File

@ -38,12 +38,25 @@ Page({
orderParams: {}, // 支付发起参数
preparePay: false, // 控制 payjs 组件的创建与销毁
paying: false, // 可选:如需知晓用户是否「已经跳转到了 PAYJS 小程序还未返回」的状态则可通过事件处理函数监听事件内的 paying 数据
showBest: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var config = wx.getStorageSync('config')
if(config.showBest == 'false') {
this.setData({
showBest: false
})
} else {
this.setData({
showBest: true
})
}
wx.hideShareMenu()
this.setData({
yiyan: wx.getStorageSync('yiyan'),
@ -214,10 +227,20 @@ Page({
this.data.animating = false
return
}
if (type == 'start' && g.is_apple) {
// 不支持苹果手机的警告
// if (type == 'start' && g.is_apple) {
// wx.showModal({
// title: '警告',
// content: '本应用不支持苹果手机',
// showCancel: false
// })
// this.data.animating = false
// return
// }
if (type == 'start' && this.data.codes.length >= 3) {
wx.showModal({
title: '警告',
content: '本应用不支持苹果手机',
content: '一个人最多持有三个二维码',
showCancel: false
})
this.data.animating = false
@ -278,7 +301,7 @@ Page({
var that = this
wx.showModal({
title: '警告',
content: '此操作不可恢复,并且不会返还费用',
content: '此操作不可恢复',
success(res) {
if (res.confirm) {
wx.showLoading({
@ -290,6 +313,7 @@ Page({
api.reflash(wx.getStorageSync('openid'), function (info) {
wx.setStorageSync('codes', info);
that.manageCodes(function () {
wx.hideLoading()
wx.showToast({
title: "删除成功"
})
@ -324,8 +348,8 @@ Page({
qq: true,
al: true
}
var text = '最佳案例'
var id = '5dcc19b74f5a926dc227431e'
var text = '小例子~欢迎测试~'
var id = '5de3cc411e83c77332ded8a5'
}
else {
// 在这里还要完成页面的切换操作
@ -489,15 +513,44 @@ Page({
if (!res) return
console.log(res)
wx.showLoading({
title: '订单创建中',
title: '疯狂上传中',
mask: true
})
api.createOder(res.totalFee, res.data, function (parms) {
// 获取order 然后调起支付接口
// api.createOrder(res.totalFee, res.data, function (parms) {
// that.setData({
// preparePay: true,
// orderParams: parms
// })
// wx.hideLoading()
// })
api.createCode(res.data,function (order_id) {
//重置createCode
var data = that.data.createCode
data._id = {}
data._id['$oid'] = order_id
that.data.createCode = {
wxcode: '',
qqcode: '',
alcode: '',
username: '',
openId: wx.getStorageSync('openid'),
node: '',
timeout: '',
month: 0
}
that.setData({
preparePay: true,
orderParams: parms
createCode: that.data.createCode,
orderParams: {}
})
//调起绘制二维码的界面
//刷新并处理数据
api.reflash(wx.getStorageSync('openid'), function (info) {
wx.setStorageSync('codes', info);
that.manageCodes()
})
wx.hideLoading()
that.rouseQRcode(false,data)
})
@ -603,6 +656,13 @@ Page({
paying: res.detail.paying
})
}
}
},
showQrcode() {
wx.previewImage({
urls: ['cloud://cloud-83621f.636c-cloud-83621f/cherryStore/money.png'],
current: 'cloud://cloud-83621f.636c-cloud-83621f/cherryStore/money.png' // 当前显示图片的http链接
})
},
})

View File

@ -26,7 +26,7 @@
</view>
<view class="lable">开始合并</view>
</view>
<view class="content" data-type="example" bindtap="showUtils">
<view class="content" data-type="example" bindtap="showUtils" wx:if="{{showBest}}">
<view class="content-circle">
<text></text>
</view>
@ -54,21 +54,26 @@
</view>
<view class="safe-warp" wx:if="{{display['safe']}}">
<view class="safe-main">
<view class="safe-stitle">先说明一个准则:<span style="color:#f43d68;">免费的最贵</span></view>
<!-- <view class="safe-stitle">先说明一个准则:<span style="color:#f43d68;">免费的最贵</span></view> -->
<view class="safe-stitle"><span style="color:#f43d68;">免费</span>的收款码合成服务,</view>
<view class="safe-stitle" style="margin-bottom:50rpx;">轻松创建属于自己的三合一收款码</view>
<view class="safe-title">1.合并后的收款码有扫码次数和时间限制嘛?</view>
<view class="safe-content">当前是在选购的时间内不限扫码次数(<span style="color:#f43d68;">0.5元每月</span>后续将推出每1000次收费0.1元的套餐</view>
<!-- <view class="safe-content">当前是在选购的时间内不限扫码次数(<span style="color:#f43d68;">0.5元每月</span>后续将推出每1000次收费0.1元的套餐</view> -->
<view class="safe-content">在你填写的时间之内<span style="color:#eeba1c;">完全没有限制,</span>随便扫,放开了扫</view>
<view class="safe-title">2.合并后的收款码<span style="color:#f43d68;">安全</span>嘛?</view>
<view class="safe-content">怎么说呢,别人拿到了这个收款码,唯一能做的事情就是给你付钱。你说它安不安全~hhh</view>
<view class="safe-content">怎么说呢,别人拿到了这个收款码,唯一能做的事情就是<span style="color:#eeba1c;">给你付钱。</span>你说它安不安全~hhh</view>
<view class="safe-title">3.钱收完<span style="color:#f43d68;">去哪了</span></view>
<view class="safe-content">当然微信进微信钱包,支付宝进支付宝账户,和直接把没合并的收款码给顾客一样,如果您开启了收款提示音,依然可以愉快的听到到账的提示~</view>
<view class="safe-title">4.为啥微信或者QQ扫码之后还得长按识别一下</view>
<view class="safe-content">微信QQ不给权限毕竟微信不是专门做支付的这方面还是没支付宝好~我本人用的时候也超级想吐槽这个问题。注这问题是共性的友商们也没辙hhhh</view>
<view class="safe-title">5.你就合并个二维码我咋还收钱?</view>
<view class="safe-content">服务器是要花钱的顾客每扫一次是要占用我服务器资源的我花了更多的钱做CDN加速和COS对象存储只为了能更快速的进入付款界面在下保证永无广告一切以用户体验为最优先</view>
<view class="safe-title">6.关于这个小程序</view>
<view class="safe-content">最初主要是为了解决我老爸当出租车司机两张码来回翻给用户看太麻烦了寻思写个合并到一起的小程序方便点顺手带上了QQ一张二维码能收三个码的钱到哪都挺方便的饭店里一张桌子贴一张也不用怕看着不利索hhh</view>
<view class="safe-title">7.下一步要做的事</view>
<view class="safe-content">赶紧解决苹果手机不能合并的问题,写完背景商店就可以免费更换二维码背景啦!</view>
<!-- <view class="safe-title">5.你就合并个二维码我咋还收钱?</view> -->
<!-- <view class="safe-content">服务器是要花钱的顾客每扫一次是要占用我服务器资源的我花了更多的钱做CDN加速和COS对象存储只为了能更快速的进入付款界面在下保证永无广告一切以用户体验为最优先</view> -->
<view class="safe-title">5.关于这个小程序</view>
<!-- <view class="safe-content">最初主要是为了解决我老爸当出租车司机两张码来回翻给用户看太麻烦了寻思写个合并到一起的小程序方便点顺手带上了QQ一张二维码能收三个码的钱到哪都挺方便的饭店里一张桌子贴一张也不用怕看着不利索hhh</view> -->
<view class="safe-content">我只是一个在校大学生,我并不是为了盈利而建这个平台,这只是我的个人爱好,我不求有多高的收入和回报,自己码的开心就行了,大家信任我而使用这个平台,我就很有成就感了~我为了自己的爱好我愿意花这么多钱去购置服务器、维护这个平台,有何不可?同时在这期间我也认识了很多有技术、有才华的人,他们也给了我很大的帮助,在此我向各位帮助过我的人表示衷心的感谢。</view>
<!-- <view class="safe-title">7.下一步要做的事</view> -->
<!-- <view class="safe-title">7.能为您提供服务是我的荣幸~不打算支持一下我嘛~<span style="color:#f43d68;" bindtap='showQrcode'> 点我支持 </span></view> -->
<!-- <view class="safe-content">赶紧解决苹果手机不能合并的问题,写完背景商店就可以免费更换二维码背景啦!</view> -->
<view class="safe-title">最后祝各位<span style="color:#eeba1c;">生意兴隆,好运连连!</span><text></text></view>
</view>
</view>
@ -104,7 +109,7 @@
</view>
<view class="input-box">
<view class="label">使用时长(0.5元/月)</view>
<view class="label">使用时长/月</view>
<input type="number" placeholder="输入1-12的整数" bindinput="inputChange" data-type="month"/>
</view>

View File

@ -76,7 +76,7 @@ Page({
//初始化
init : function() {
// 一共两个进程
this.flag = 2
this.flag = 3
// 登录
var that = this
api.login(function(info,openid) {
@ -88,6 +88,16 @@ Page({
api.getyiyian(()=> {
that.flag = util.checkFlag('yiyan',that.flag,that.jumpToHome)
})
// 获取config
api.getConfig((config)=> {
if(config != false) {
wx.setStorageSync('config', config);
} else {
// 先这么存着
wx.setStorageSync('config', {showBest: false});
}
that.flag = util.checkFlag('config',that.flag,that.jumpToHome)
})
},
// 跳到主页