From 7eef4942d80a3f012f48eca85b8bc60872dc84ab Mon Sep 17 00:00:00 2001 From: aaron <> Date: Thu, 27 Mar 2025 17:25:51 +0800 Subject: [PATCH] update --- app/api/endpoints/coupon_activity.py | 6 ++++++ app/core/wechat.py | 10 ++++++---- app/models/coupon_activity.py | 4 ++++ jobs.sqlite | Bin 24576 -> 24576 bytes 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/api/endpoints/coupon_activity.py b/app/api/endpoints/coupon_activity.py index 89d242a..25564f3 100644 --- a/app/api/endpoints/coupon_activity.py +++ b/app/api/endpoints/coupon_activity.py @@ -258,6 +258,9 @@ async def get_url_link( if not activity: return error_response(code=404, message="活动不存在") + if activity.qr_code: + return success_response(data=activity.qr_code) + # 获取URL链接 wechat_client = WeChatClient() image_data = await wechat_client.get_wx_code(path=f"pages/my/promation/activities/index", query=f"id={activity_id}") @@ -266,6 +269,9 @@ async def get_url_link( url = await qcloud_manager.upload_file_bytes(image_data, key) + activity.qr_code = url + db.commit() + return success_response(data=url) diff --git a/app/core/wechat.py b/app/core/wechat.py index f554c6c..bae9a52 100644 --- a/app/core/wechat.py +++ b/app/core/wechat.py @@ -447,18 +447,20 @@ class WeChatClient: raise Exception(f"申请退款失败: {str(e)}") async def get_wx_code(self, path: str, query: str = None) -> bytes: - url =f"https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={await self.get_access_token()}" + url =f"https://api.weixin.qq.com/wxa/getwxacode?access_token={await self.get_access_token()}" print(f"path: {path}") + print(f"scene: {query}") # 添加调试日志 params = { - "page": path, - "scene": query, + "path": path + "?" + query, "env_version": "release" if not settings.DEBUG else "develop" } try: async with aiohttp.ClientSession() as session: - async with session.post(url, data=json.dumps(params)) as response: + # 使用json参数而不是data参数 + async with session.post(url, json=params) as response: if response.status != 200: result = await response.json() + print(f"获取小程序码失败: {result}") # 添加错误日志 raise Exception(f"获取小程序码失败: {result.get('errmsg')}") image_data = await response.read() diff --git a/app/models/coupon_activity.py b/app/models/coupon_activity.py index 913cde8..64cfbb3 100644 --- a/app/models/coupon_activity.py +++ b/app/models/coupon_activity.py @@ -19,6 +19,7 @@ class CouponActivityDB(Base): user_limit = Column(Integer, nullable=False, default=1) # 用户可领取次数 is_active = Column(Boolean, nullable=False, default=True) # 是否激活 coupon_config = Column(JSON, nullable=False) # 可领取的优惠券配置 {coupon_id: count} + qr_code = Column(String(200), nullable=True) # 活动小程序码URL create_time = Column(DateTime(timezone=True), server_default=func.now()) update_time = Column(DateTime(timezone=True), onupdate=func.now()) @@ -34,6 +35,7 @@ class CouponActivityCreate(BaseModel): user_limit: int = Field(..., gt=0) coupon_config: Dict[int, int] # {coupon_id: count} is_active: bool = Field(default=True) + qr_code: Optional[str] = Field(None, max_length=200) # 活动小程序码URL class CouponActivityUpdate(BaseModel): name: Optional[str] = Field(None, max_length=100) @@ -46,6 +48,7 @@ class CouponActivityUpdate(BaseModel): user_limit: Optional[int] = Field(None, gt=0) coupon_config: Optional[Dict[int, int]] = None is_active: Optional[bool] = None + qr_code: Optional[str] = Field(None, max_length=200) # 活动小程序码URL class CouponActivityInfo(BaseModel): id: int @@ -59,6 +62,7 @@ class CouponActivityInfo(BaseModel): user_limit: int coupon_config: Dict[int, int] is_active: bool + qr_code: Optional[str] # 活动小程序码URL create_time: datetime update_time: Optional[datetime] diff --git a/jobs.sqlite b/jobs.sqlite index 1e9f8c0e74bd64071207fa7ac987c660ca552cbe..901ed2aebf51bdac12169d31ebdb05788b6947af 100644 GIT binary patch delta 19 acmZoTz}Rqrae_2s_Cy(H#_Wv=3*rGrtp^4G delta 19 acmZoTz}Rqrae_2s@I)DB#^8+!3*rGqMF!RY