diff --git a/app/api/endpoints/order_additional_fee.py b/app/api/endpoints/order_additional_fee.py index 7aa23b7..35038ad 100644 --- a/app/api/endpoints/order_additional_fee.py +++ b/app/api/endpoints/order_additional_fee.py @@ -16,6 +16,7 @@ from typing import List, Optional from datetime import datetime import aiohttp from app.core.config import settings +from app.core.qcloud import qcloud_manager router = APIRouter() @@ -65,6 +66,9 @@ async def create_additional_fee_request( db.refresh(db_fee_request) # TODO: 发送通知给用户 + user = db.query(UserDB).filter(UserDB.userid == order.userid).first() + if user: + await qcloud_manager.send_sms_code_additional_fee(user.phone) return success_response(data=OrderAdditionalFeeInfo.model_validate(db_fee_request)) except Exception as e: diff --git a/app/core/config.py b/app/core/config.py index ce44f45..ea262ec 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -56,6 +56,7 @@ class Settings(BaseSettings): SMS_SDK_APP_ID: str = "1400961527" SMS_SIGN_NAME: str = "蜂快到家公众号" SMS_TEMPLATE_ID: str = "2353143" # 验证码短信模板ID + SMS_TEMPLATE_ID_ADDITIONAL_FEE: str = "2375181" # 加价短信模板ID # 腾讯云 COS 配置 COS_REGION: str = "ap-chengdu" diff --git a/app/core/qcloud.py b/app/core/qcloud.py index 57ab452..6dbca06 100644 --- a/app/core/qcloud.py +++ b/app/core/qcloud.py @@ -107,6 +107,31 @@ class QCloudManager: except TencentCloudSDKException as e: raise Exception(f"发送短信失败: {str(e)}") + + async def send_sms_code_additional_fee(self, phone: str) -> tuple[str, str]: + """ + 发送加价短信验证码 + """ + try: + self._init_sms_client() + + # 构建请求 + req = sms_models.SendSmsRequest() + req.SmsSdkAppId = settings.SMS_SDK_APP_ID + req.SignName = settings.SMS_SIGN_NAME + req.TemplateId = settings.SMS_TEMPLATE_ID_ADDITIONAL_FEE + + # 发送短信 + response = self.sms_client.SendSms(req) + + # 检查发送结果 + if response.SendStatusSet[0].Code != "Ok": + raise Exception(response.SendStatusSet[0].Message) + + return response.RequestId + + except TencentCloudSDKException as e: + raise Exception(f"发送加价短信验证码失败: {str(e)}") async def verify_id_card(self, id_card: str, name: str) -> dict: """