前言
因为微信支付下单的时候不允许同一个订单重复下单,所以在下单之前 对订单号加了三位随机字符串 在回调时 进行截取操作
@order_api.route('/user/wx_xcx_pay/notify', methods=['POST'])
def new_notify():
headers = request.headers
# print('headers', headers)
wxpay = wx_pay_func()
result = wxpay.callback(headers, request.data)
if result and result.get('event_type') == 'TRANSACTION.SUCCESS':
resp = result.get('resource')
out_trade_no = resp.get('out_trade_no') # 本系统订单号
transaction_id = resp.get('transaction_id') # 微信支付订单号
first_character = out_trade_no[0] # 获取开头字母 确定支付类型
order_number = out_trade_no[:-3] # 获取实际订单号
success_time = resp.get('success_time') # 支付完成时间
payer = resp.get('payer') # 付款人信息
amount = resp.get('amount').get('total') # 金额 单位分
payment_amount = Decimal(amount) / Decimal(100) # 实际支付金额 单位元
# 上门取 或者 上门洗
if first_character in ['X', 'Q']:
return order_pay_callback(order_number, amount, success_time, transaction_id, resp)
# 充值订单
elif first_character == 'C':
return recharge_pay_callback(order_number, transaction_id, payment_amount)
# 补差价订单
elif first_character == 'B':
return price_difference_payment_callback(order_number, transaction_id, payment_amount)
else:
return reg_func(200, None, '支付失败')
def load_private_key(file_name):
# 获取当前文件的目录
current_dir = os.path.dirname(__file__)
# 构建完整的文件路径
file_path = os.path.join(current_dir, file_name)
try:
# 安全地打开文件
with open(file_path, 'r') as file:
private_key = file.read()
return private_key
except FileNotFoundError:
print(f"Error: The file {
file_name} was not found in the directory