This commit is contained in:
doudou201703
2026-09-19 11:51:34 +08:00
parent dd4383130d
commit 922583becb
15 changed files with 223 additions and 124 deletions
@@ -0,0 +1,58 @@
from datetime import datetime
from zoneinfo import ZoneInfo
import requests
import yarl
from pydantic import BaseModel
from ulid import ULID
from wechat_微信支付证书.江苏六果科技有限公司支付证书.六果公司支付类 import sixWechatPay六果泡泡支付
class MerchantCoupon代金券API(BaseModel):
# demo_必填: int = Field(..., description="描述") # 必传属发生
# demo_可选: Optional[int] = None # 可选值
# demo_默认值: int = Field(default=100001, description="描述") # 有默认值
# demo_联合类型: Literal["xiao", "zizi"] = Field(..., description="描述") 商家券
def model_post_init(self, __context):
print("初始化完成,自动调用 model_post_init")
def 发放指定批次的代金券(self, mini_openid):
pass
uri = f"https://api.mch.weixin.qq.com/v3/marketing/favor/users/{mini_openid}/coupons"
out_request_no = str(ULID())
body = {
"stock_id": "22941326", # 必须为代金券(全场券或单品券)批次号
"out_request_no": out_request_no, # 【商户单据号】商户此次发放凭据号(格式:商户id+日期+流水号),商户侧需保持唯一性
"appid": sixWechatPay六果泡泡支付().appid, # 公众账号ID】微信为发券方商户分配的公众账号ID
"stock_creator_mchid": sixWechatPay六果泡泡支付().mchid, # 创建方商户号。
}
header = sixWechatPay六果泡泡支付(pay_uri=uri, pay_请求体=body, ).pay_Headers
print(header)
postData = requests.post(url=uri, json=body, headers=header).json()
print(postData)
def 根据商户号查用户的券(self, mini_openid):
pass
uri = ""
uri = yarl.URL.build(scheme='https', host="api.mch.weixin.qq.com", path=f"/v3/marketing/favor/users/{mini_openid}/coupons",
query={"appid": sixWechatPay六果泡泡支付().appid, "creator_mchid": sixWechatPay六果泡泡支付().mchid}
) # yarl
print(uri.human_repr())
headers = sixWechatPay六果泡泡支付(pay_uri=uri.human_repr(), pay_methon方法="GET").pay_Headers
print(headers)
postData = requests.get(url=uri.human_repr(), headers=headers).json()
print(postData)
if __name__ == "__main__":
pass
print(ULID(), type(ULID()))
# MerchantCoupon代金券API().发放指定批次的代金券(mini_openid="ohQkD7NMWkO2aehP9wjBTUXtN7Y0")
MerchantCoupon代金券API().根据商户号查用户的券(mini_openid="ohQkD7NMWkO2aehP9wjBTUXtN7Y0")
utc_unix_timestamp = int(datetime.now(tz=ZoneInfo("utc")).timestamp())
uri = yarl.URL.build(scheme='https', host="xiao.sixgou.com", path="/开票/开票回调接口/",
query={"key": "value"}
) # yarl
@@ -54,11 +54,8 @@ class paymentCategory(sixpay六果科技公司):
class wechatPay(BaseModel):
payment: type[sixpay六果科技公司] | type[six六果服务商支付参数]
def 构造签名串(self, uri: str, body_data: dict | bytes | str | None = None,
method: Optional[Literal["GET", "POST", "PATCH"]] = "POST",
):
def 构造签名串(self, uri: str, body_data: dict | bytes | str | None = None, method: Optional[Literal["GET", "POST", "PATCH"]] = "POST", ):
"""
"""
url_data = re.search(r'/v3.*', string=uri).group()
shi_jian_chou = str(int(time.time())) # 时间戳
@@ -101,16 +98,13 @@ class wechatPay(BaseModel):
str_list = ",".join([f'{key}="{value}"' for key, value in data.items()])
# 生成请求头
Authorization = f"{s_with_space}{str_list}"
headers = {
"Content-Type": "application/json", "Authorization": Authorization,
}
headers = {"Content-Type": "application/json", "Authorization": Authorization, }
# headers.update({"Wechatpay-Serial": self.payment.微信支付公钥ID})
return headers
def getpay_jsapi(self, uri, body_data: dict | bytes | str | None = None, method: Optional[
Literal["GET", "POST"]] = "POST",
):
headers = self.构造签名串(uri=uri, body_data=body_data, method=method)
# 发送请求
response: Response = requests.post(url=uri, json=body_data, headers=headers)
@@ -309,8 +303,8 @@ class wechatPay(BaseModel):
@return:
@rtype:
"""
public_key = RSA.import_key(self.payment.wechat_certificate)
# public_key = RSA.import_key(self.payment.pem微信支付公钥)
# public_key = RSA.import_key(self.payment.wechat_certificate)
public_key = RSA.import_key(self.payment.pem微信支付公钥)
Wechatpay_Timestamp = pydash.get(response_headers, "Wechatpay-Timestamp")
Wechatpay_Nonce = pydash.get(response_headers, "Wechatpay-Nonce")
Wechatpay_Signa = pydash.get(response_headers, "Wechatpay-Signature")