update
This commit is contained in:
42
app/main.py
42
app/main.py
@@ -15,8 +15,14 @@ from fastapi.staticfiles import StaticFiles
|
||||
# from app import tgMessage # type: ignore #发送tg消息
|
||||
from datetime import datetime
|
||||
import requests
|
||||
from tentcentSMS import sendSms
|
||||
# from tentcentSMS import sendSms
|
||||
import random
|
||||
from tencentcloud.common import credential
|
||||
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
|
||||
from tencentcloud.sms.v20210111 import sms_client, models
|
||||
from tencentcloud.common.profile.client_profile import ClientProfile
|
||||
from tencentcloud.common.profile.http_profile import HttpProfile
|
||||
|
||||
|
||||
# 初始化数据库
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
@@ -53,6 +59,39 @@ def get_db():
|
||||
# return {"message": "Hello World"}
|
||||
|
||||
|
||||
|
||||
# phoneNum="+8613243889782"
|
||||
def sendSms(phoneNum,verification_code=None):
|
||||
try:
|
||||
cred = credential.Credential("AKIDOaT6SZQ0JL7cqnTryoOhkW1FBqELAizz",
|
||||
"kDPKyMTJs99sKVP1NREkzxKQFo66pIUP")
|
||||
httpProfile = HttpProfile()
|
||||
httpProfile.reqMethod = "POST" # post请求(默认为post请求)
|
||||
httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)
|
||||
httpProfile.endpoint = "sms.tencentcloudapi.com" # 指定接入地域域名(默认就近接入)
|
||||
clientProfile = ClientProfile()
|
||||
clientProfile.signMethod = "TC3-HMAC-SHA256" # 指定签名算法
|
||||
clientProfile.language = "en-US"
|
||||
clientProfile.httpProfile = httpProfile
|
||||
client = sms_client.SmsClient(cred, "ap-beijing", clientProfile)
|
||||
req = models.SendSmsRequest()
|
||||
req.SmsSdkAppId = "1400808237"
|
||||
req.SignName = "异度世界公众号"
|
||||
req.TemplateId = "1795415" #验证码为:{1}, 若非本人操作,请忽略。
|
||||
req.TemplateParamSet = [verification_code]
|
||||
newphoneNum = '+86' + phoneNum
|
||||
req.PhoneNumberSet = [newphoneNum]
|
||||
req.SessionContext = ""
|
||||
req.ExtendCode = ""
|
||||
req.SenderId = ""
|
||||
resp = client.SendSms(req)
|
||||
print(resp.to_json_string(indent=2))
|
||||
except TencentCloudSDKException as err:
|
||||
print(err)
|
||||
|
||||
|
||||
|
||||
|
||||
def sengTgmesage(message):
|
||||
url = "http://192.168.31.38:8521/send_message"
|
||||
data = {"message": message}
|
||||
@@ -295,6 +334,7 @@ def get_verification_code(wxid: str,
|
||||
user.phone_number = phone_number
|
||||
user.verification_code = verification_code
|
||||
db.commit()
|
||||
sendSms(phone_number)
|
||||
|
||||
return {
|
||||
"message": "Verification code sent",
|
||||
|
||||
Reference in New Issue
Block a user