Files
jefferyzhao 9a923a67b9 first commit
2025-07-30 18:53:06 +08:00

71 lines
2.9 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(public_key,msg, length=100):
"""
单次加密串的长度最大为 (key_size/8)-11
1024bit的证书用100 2048bit的证书用 200
"""
pub_key = RSA.importKey(open(public_key).read())
# pub_key = RSA.importKey(open('E:/YinJian/银建支付对接维护说明/富友/fy-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/api2/paymentCallBack"
# self.notify_url = "http://172.16.6.15:3006/paymentCallBack"
def unified_order(self, order_no, total, description):
if self.sub_mchnt_cd == '0001000F7152364':
param = {
"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",
}
pub_key_location = 'dg_pub_key.pem'
# pub_key_location = 'E:\YinJian\银建支付对接维护说明\DP\DP-enterprise-wechat-payment-push\dg_pub_key.pem'
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",
}
pub_key_location = 'pub_key.pem'
# pub_key_location = 'E:\YinJian\银建支付对接维护说明\DP\DP-enterprise-wechat-payment-push\pub_key.pem'
logger.info(f"======================发起支付===================={param}")
# 加密
message = json.dumps(param)
encrypted_message = rsa_long_encrypt(pub_key_location,message,100)
return json.dumps({"message": encrypted_message})