from flask import Flask, request, redirect, abort, session, jsonify, url_for from utils import * from FuiouPay import H5Main # from WXPay import WXPay import os, _thread, urllib from flask_cors import CORS, cross_origin app = Flask(__name__) app.config['SECRET_KEY'] = os.urandom(24) CORS(app, supports_credentials=True) @app.route('/queryUser', methods=['GET']) def queryUserApi(): # 获取支付明细 try: id = request.args.get('user') data = queryUser(id) print("===================", data) return data except Exception as e: return {} @app.route('/page_notify', methods=['POST']) @cross_origin() def pageNotify(): """处理 POST 请求并重定向为 GET 请求到 /redirect""" try: # 使用 303 See Other 状态码,将 POST 请求转换为 GET 请求的重定向 return redirect('/redirect', code=303) except Exception as e: print(f"Error occurred: {e}") return jsonify({"error": "Internal Server Error"}), 500 @app.route('/redirect', methods=['GET']) @cross_origin() def redirectApi(): """处理 GET 请求并重定向到外部 URL""" try: # 处理 GET 请求并重定向到外部 URL return redirect('https://www.jiyuankeshang.com/f/66e412f9d396a07cd2c2662f', code=302) except Exception as e: print(f"Error occurred: {e}") return jsonify({"error": "Internal Server Error"}), 500 @app.route('/getPaymentDetails', methods=['GET']) def getPaymentDetails(): try: id = request.args.get('user', '') id = id.replace(" ", "") if not id: print("no 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("====================================paymentCallBack=========================================") msg = request.data.decode('UTF-8') print("回调参数为====", msg) msg = eval(msg) print("eval参数为====", msg) if msg['resp_desc'] == '成功': print("=================================充值回调SUCCESS==========================================") # rsa_key = RSA.importKey(open('priv_key.pem').read()) rsa_key = RSA.importKey(open('E:\YinJian\银建支付对接维护说明\DP\DP-enterprise-wechat-payment-push\priv_key.pem').read()) print("msg===",msg['message']) print(rsa_key) whp = rsa_long_decrypt(rsa_key, msg['message']) print("报文已解密", whp) whp_dict = json.loads(whp) # 打印字典中的所有键 print("1111111",whp_dict.keys()) # 获取'order_id'键的值并取前18个字符 id = whp_dict['order_id'][:18] # 查询机构、分司 res = filter_jdy_ht(id) transaction_id = whp_dict['pay_ssn'] amount = float(whp_dict['order_amt']) order_pay_type = whp_dict['order_pay_type'] # 判断支付类型 if order_pay_type[:2] == "We": pay_type = "微信支付" elif order_pay_type[:3] == "Ali": pay_type = "支付宝支付" elif order_pay_type == "0000000000": pay_type = "云闪付支付" else: pay_type = "企微支付" amount = amount / 100 payment_items = "承包金" print("充值回调处理",{"pay_amount": amount, "id": id, "sh": res[1], "base_company": res[0], "name": res[2], "transaction_id": transaction_id, "payment_items": payment_items, "pay_type": pay_type}) _thread.start_new_thread(add_payment, ({"pay_amount": amount, "id": id, "sh": res[1], "base_company": res[0], "name": res[2], "transaction_id": transaction_id, "payment_items": payment_items, "pay_type": pay_type},)) return {"code": 200} except Exception as e: return jsonify(error=str(e)), 500 @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('/transactions', methods=['GET']) def transactions(): # 调起h5支付 try: print("开始支付") id = request.args.get('user') price = request.args.get('price') print("金额", price) price = float(price) * 100 fy = H5Main("0001000F8079871") print("发起费用缴纳",f"{id}{int(time.time())}", int(price), "") message = fy.unified_order(f"{id}{int(time.time())}", int(price), "订单支付") return message except Exception as e: print("error", e) return jsonify(error=str(e)), 500 if __name__ == '__main__': app.run(host="0.0.0.0", port=3010, processes=True)