180 lines
5.7 KiB
Python
180 lines
5.7 KiB
Python
from flask import Flask, request, redirect, abort, session
|
|
from utils import *
|
|
from WXPay import WXPay
|
|
import os, _thread, urllib
|
|
|
|
|
|
app = Flask(__name__)
|
|
app.config['SECRET_KEY'] = os.urandom(24)
|
|
|
|
|
|
|
|
@app.route('/queryUserId', methods=['GET'])
|
|
def queryUserId():
|
|
# 获取支付明细
|
|
try:
|
|
code = request.args.get('code')
|
|
data = query_wx_userid(code)
|
|
if len(data) <= 11:
|
|
res = query_wx_fj_info(data)
|
|
data = res
|
|
print(f'http://web.jiyuankeshang.com/?user={data}')
|
|
return redirect(f'http://web.jiyuankeshang.com/?user={data}')
|
|
except Exception as e:
|
|
return {}
|
|
|
|
|
|
@app.route('/queryUser', methods=['GET'])
|
|
def queryUserApi():
|
|
# 获取支付明细
|
|
try:
|
|
id = request.args.get('user')
|
|
data = queryUser(id)
|
|
return data
|
|
except Exception as e:
|
|
return {}
|
|
|
|
|
|
@app.route('/getPaymentDetails', methods=['GET'])
|
|
def getPaymentDetails():
|
|
try:
|
|
id = request.args.get('user','')
|
|
|
|
id = id.replace(" ", "")
|
|
|
|
if not id:
|
|
return {}
|
|
data = query_pay_details(id)
|
|
return data
|
|
except Exception as e:
|
|
print(e)
|
|
return {}
|
|
|
|
|
|
@app.route('/paymentCallBack', methods=['POST'])
|
|
def paymentCallBack():
|
|
# 充值成功后回调 {"pay_amount": 20000, "id": "18515367096"}
|
|
try:
|
|
print("1111111111paymentCallBack")
|
|
msg = request.data.decode('utf-8')
|
|
msg = eval(msg)
|
|
whp = decode_notify_data(msg)
|
|
print("充值回调", whp)
|
|
if whp['trade_state'] == 'SUCCESS':
|
|
print("充值回调SUCCESS")
|
|
id = whp['out_trade_no'].split('_')[0]
|
|
# 查询机构、分司
|
|
res = filter_jdy_ht(id)
|
|
transaction_id = whp['transaction_id']
|
|
amount = float(whp['amount']['total'])
|
|
amount = amount / 100
|
|
print("充值回调处理",{"pay_amount": amount, "id": id,
|
|
"fs": res[1], "jg": res[0], "name": res[4],
|
|
"fsfz": res[6],
|
|
"hphm": res[5], "transaction_id": transaction_id})
|
|
_thread.start_new_thread(add_payment, ({"pay_amount": amount, "id": id,
|
|
"fs": res[1], "jg": res[0], "name": res[4],
|
|
"fsfz": res[6],
|
|
"hphm": res[5], "transaction_id": transaction_id},))
|
|
return {"code": 200}
|
|
except Exception as e:
|
|
return {}
|
|
|
|
|
|
@app.route('/test', methods=['POST'])
|
|
def test():
|
|
# 新增未收付明细 {"pay_amount": 20000, "id": "18515367096"}
|
|
try:
|
|
data = request.data.decode("utf-8")
|
|
print(data)
|
|
return {}
|
|
except Exception as e:
|
|
print(e)
|
|
return {}
|
|
|
|
|
|
|
|
|
|
@app.route('/addUnPayment', methods=['POST'])
|
|
def addUnPayment():
|
|
# 新增未收付明细 {"pay_amount": 20000, "id": "18515367096"}
|
|
try:
|
|
data = request.data.decode("utf-8")
|
|
data = data.replace("null", "None")
|
|
data = eval(data)
|
|
data = data['data']
|
|
print("开始========", data)
|
|
res = filter_jdy_ht(data['sijishenfenzhenghao'])
|
|
_thread.start_new_thread(add_payment, ({"pay_amount": 0, "id": data['sijishenfenzhenghao'],
|
|
"fs": res[1], "jg": res[0], "name": res[4],
|
|
"fsfz": res[6],
|
|
"hphm": res[5]}, 1))
|
|
|
|
return {data}
|
|
except Exception as e:
|
|
print("addUnPayment",e, res)
|
|
return {}
|
|
|
|
|
|
@app.route('/addPayment', methods=['POST'])
|
|
def addPayment():
|
|
# 新增充值明细 {"pay_amount": 20000, "id": "18515367096"}
|
|
try:
|
|
data = request.data.decode("utf-8")
|
|
print(data)
|
|
data = data.replace("null", "None")
|
|
data = eval(data)
|
|
data = data['data']
|
|
res = filter_jdy_ht(data['id_card'])
|
|
if not data['price']:
|
|
data['price'] = 0
|
|
if not res:
|
|
# 合同表单未有数据
|
|
fsfz = data['fsfz']['dept_no'] if data['fsfz'] else ""
|
|
_thread.start_new_thread(add_payment, ({"pay_amount": data['price'], "id": data['id_card'],
|
|
"fs": data['fs'], "jg": data['jg'], "name": data['name'],
|
|
"fsfz": fsfz, "hphm": data['hphm']}, 1))
|
|
else:
|
|
_thread.start_new_thread(add_payment, ({"pay_amount": data['price'], "id": data['id_card'],
|
|
"fs": res[1], "jg": res[0], "name": res[4],
|
|
"fsfz": res[6],
|
|
"hphm": res[5]}, 1))
|
|
return {}
|
|
except Exception as e:
|
|
print("addPayment",e, data)
|
|
return {}
|
|
|
|
|
|
@app.route('/transactions', methods=['GET'])
|
|
def transactions():
|
|
# 调起h5支付
|
|
try:
|
|
id = request.args.get('user')
|
|
price = request.args.get('price')
|
|
|
|
if not float(price):
|
|
res = filter_jdy_ht(id)
|
|
_thread.start_new_thread(add_payment, ({"pay_amount": 0, "id": id,
|
|
"fs": res[1], "jg": res[0], "name": res[4],
|
|
"fsfz": res[6],
|
|
"hphm": res[5]}, 1))
|
|
return {}
|
|
else:
|
|
# 查询商户号、商户号证书
|
|
res = filter_jdy_ht(id)
|
|
if not res:
|
|
return "error"
|
|
|
|
wx = WXPay(res[3], res[2])
|
|
price = float(price) * 100
|
|
url = wx.unified_order(f"{id}_{int(time.time())}", int(price), "订单支付", res[0]).text
|
|
url = eval(url)
|
|
return url
|
|
except Exception as e:
|
|
print("error", e)
|
|
return {}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host="0.0.0.0", port=3004, processes=True)
|