Files
jefferyzhao b5128aded8 初始提交
2025-07-30 18:43:53 +08:00

67 lines
2.5 KiB
Python
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.

import json
from datetime import datetime
import requests
from Crypto.PublicKey import RSA
import base64
from Crypto.Cipher import PKCS1_v1_5
import logging
logger = logging.getLogger(__name__)
# 使用公钥加密
def rsa_long_encrypt(msg, length=100):
"""
单次加密串的长度最大为 (key_size/8)-11
1024bit的证书用100 2048bit的证书用 200
"""
pub_key = RSA.importKey(open('pub_key.pem').read())
# pub_key = RSA.importKey(open('E:/YinJian/银建支付对接维护说明/富友/enterprise-wechat-payment-push/pub_key.pem').read())
pubobj = PKCS1_v1_5.new(pub_key)
res = []
for i in range(0, len(msg), length):
res.append(pubobj.encrypt(msg[i:i + length].encode('GBK')))
return base64.b64encode(b"".join(res)).decode('GBK')
class H5Main:
def __init__(self, sub_mchnt_cd):
self.mchnt_cd = "0001000F7152279"
self.sub_mchnt_cd = sub_mchnt_cd
self.url = 'https://aggpcpay.fuioupay.com/aggh5Gate.fuiou'
self.notify_url = "http://web.jiyuankeshang.com/api/paymentCallBack"
# self.notify_url = "http://172.16.6.15:3006/paymentCallBack"
def unified_order(self, order_no, total, description):
if self.sub_mchnt_cd == '0001000F7152279':
param = {
"mchnt_cd": self.mchnt_cd,
"order_date": datetime.now().strftime("%Y%m%d"),
"order_id": order_no,
"order_amt": total,
"page_notify_url": self.notify_url,
"back_notify_url": self.notify_url,
"ver": "4.0.0",
"goods_name": "费税收取",
"goods_detail": description,
"fee_type": "CNY",
}
else:
param = {
"mchnt_cd": self.mchnt_cd,
"sub_mchnt_cd": self.sub_mchnt_cd,
"order_date": datetime.now().strftime("%Y%m%d"),
"order_id": order_no,
"order_amt": total,
"page_notify_url": self.notify_url,
"back_notify_url": self.notify_url,
"ver": "4.0.0",
"goods_name": "费税收取",
"goods_detail": description,
"fee_type": "CNY",
}
logger.info(f"======================发起支付====================",param)
# 加密
message = json.dumps(param)
encrypted_message = rsa_long_encrypt(message,100)
return json.dumps({"message": encrypted_message})