feat: 选择随机回复
This commit is contained in:
110
app.py
110
app.py
@@ -57,10 +57,6 @@ def findPhoneNum(text):
|
|||||||
|
|
||||||
def resData(inputArguments, uid):
|
def resData(inputArguments, uid):
|
||||||
print("inputArguments", inputArguments)
|
print("inputArguments", inputArguments)
|
||||||
# uid:唯一标识用户的openid
|
|
||||||
# print("appid", appid, "bid", bid, "requestid", requestid, "uid", uid)
|
|
||||||
# uid='wxx'
|
|
||||||
# 要处理url编码问题decode
|
|
||||||
try:
|
try:
|
||||||
inputArguments = unquote(inputArguments, "utf-8")
|
inputArguments = unquote(inputArguments, "utf-8")
|
||||||
except:
|
except:
|
||||||
@@ -83,6 +79,7 @@ def resData(inputArguments, uid):
|
|||||||
print(f"用户输入:{inputArguments},手机号不正确,或者uid参数异常")
|
print(f"用户输入:{inputArguments},手机号不正确,或者uid参数异常")
|
||||||
# sendTg(f"用户输入:{inputArguments},手机号不正确,或者uid参数异常")
|
# sendTg(f"用户输入:{inputArguments},手机号不正确,或者uid参数异常")
|
||||||
|
|
||||||
|
|
||||||
def urlSend(num):
|
def urlSend(num):
|
||||||
try:
|
try:
|
||||||
inputArguments = unquote(num, "utf-8")
|
inputArguments = unquote(num, "utf-8")
|
||||||
@@ -112,20 +109,17 @@ def read_items(
|
|||||||
print("console :,", "appid", appid, "bid", bid, "requestid", requestid, "uid", uid)
|
print("console :,", "appid", appid, "bid", bid, "requestid", requestid, "uid", uid)
|
||||||
return {"appid": appid, "bid": bid, "requestid": requestid, "uid": uid}
|
return {"appid": appid, "bid": bid, "requestid": requestid, "uid": uid}
|
||||||
|
|
||||||
|
|
||||||
|
# 莉莉云机器人
|
||||||
@app.get("/lili")
|
@app.get("/lili")
|
||||||
# def read_root():
|
# def read_root():
|
||||||
# return {"Hello": "World"}
|
# return {"Hello": "World"}
|
||||||
def lili(
|
def lili():
|
||||||
):
|
# 直接返回字符串
|
||||||
# content = {"code":"00000","message":"请求成功","plugin":'null',"data":[{"content":"lilili","typed":1,"remark":'remark'}]}
|
return "lili"
|
||||||
# headers = {"Content-Type": "application/json"}
|
|
||||||
# return JSONResponse(content=content, headers=headers)
|
|
||||||
return 'lili'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 通过网址发送闪信
|
||||||
@app.get("/send")
|
@app.get("/send")
|
||||||
# def read_root():
|
# def read_root():
|
||||||
# return {"Hello": "World"}
|
# return {"Hello": "World"}
|
||||||
@@ -134,7 +128,7 @@ def read_items(
|
|||||||
num: Union[str, None] = None,
|
num: Union[str, None] = None,
|
||||||
):
|
):
|
||||||
print("num", num)
|
print("num", num)
|
||||||
background_tasks.add_task(urlSend,num)
|
background_tasks.add_task(urlSend, num)
|
||||||
content = {"err_code": 0, "data_list": [{"outputArguments": "test"}]}
|
content = {"err_code": 0, "data_list": [{"outputArguments": "test"}]}
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
return JSONResponse(content=content, headers=headers)
|
return JSONResponse(content=content, headers=headers)
|
||||||
@@ -152,51 +146,51 @@ async def getphonenum(
|
|||||||
requestid: Union[str, None] = Header(default=None),
|
requestid: Union[str, None] = Header(default=None),
|
||||||
uid: Union[str, None] = Header(default=None),
|
uid: Union[str, None] = Header(default=None),
|
||||||
):
|
):
|
||||||
# err_code=0
|
err_code = 0
|
||||||
# outputArguments=''
|
outputArguments = ""
|
||||||
# print("inputArguments", inputArguments)
|
print("inputArguments", inputArguments)
|
||||||
# # uid:唯一标识用户的openid
|
try:
|
||||||
# # 要处理url编码问题decode
|
inputArguments = unquote(inputArguments, "utf-8")
|
||||||
# try:
|
except:
|
||||||
# inputArguments = unquote(inputArguments, "utf-8")
|
inputArguments = ""
|
||||||
# except:
|
# 正则获取11位手机号
|
||||||
# inputArguments = ""
|
phonenumber = findPhoneNum(inputArguments)
|
||||||
# # 正则获取11位手机号
|
print("phonenumber", phonenumber)
|
||||||
# phonenumber = findPhoneNum(inputArguments)
|
# # phonenumber='13243889782'
|
||||||
# print("phonenumber", phonenumber)
|
if phonenumber is not None and uid is not None:
|
||||||
# # # phonenumber='13243889782'
|
warntext = "[异度世界],微信加群验证码:3399"
|
||||||
# if phonenumber is not None and uid is not None:
|
# sendTg(f"用户手机号{phonenumber},开始发送验证码")
|
||||||
# warntext = "[异度世界],微信加群验证码:3399"
|
# 判断用户uid是都触发过短信,不允许触发第2次
|
||||||
# # sendTg(f"用户手机号{phonenumber},开始发送验证码")
|
if findUid(uid, phonenumber) is True:
|
||||||
# # 判断用户uid是都触发过短信,不允许触发第2次
|
err_code = -1
|
||||||
# if findUid(uid, phonenumber) is True:
|
outputArguments = "验证已发送,不允许重复触发"
|
||||||
# err_code=-1
|
print("用户uid已存在,不触发短信")
|
||||||
# outputArguments='验证已发送,不允许重复触发'
|
# sendTg(f"用户{uid}已存在,不触发短信")
|
||||||
# print("用户uid已存在,不触发短信")
|
else:
|
||||||
# # sendTg(f"用户{uid}已存在,不触发短信")
|
# 发送闪信
|
||||||
# else:
|
# sendFlash(phonenumber, warntext)
|
||||||
# # 发送闪信
|
# 后台发送
|
||||||
# # sendFlash(phonenumber, warntext)
|
background_tasks.add_task(sendFlash, phonenumber, warntext)
|
||||||
# # 后台发送
|
|
||||||
# background_tasks.add_task(sendFlash,phonenumber,warntext)
|
|
||||||
|
|
||||||
# else:
|
else:
|
||||||
# err_code=-1
|
err_code = -1
|
||||||
# print(f"用户输入:{inputArguments},手机号不正确,或者uid参数异常")
|
print(f"用户输入:{inputArguments},手机号不正确,或者uid参数异常")
|
||||||
# # sendTg(f"用户输入:{inputArguments},手机号不正确,或者uid参数异常")
|
# sendTg(f"用户输入:{inputArguments},手机号不正确,或者uid参数异常")
|
||||||
|
|
||||||
# 存储uid和手机号
|
if err_code == 0:
|
||||||
# return {"appid": appid,"bid": bid,"requestid": requestid,"uid": uid,'inputArguments':inputArguments}
|
outputArguments = "验证码发送成功"
|
||||||
|
else:
|
||||||
# if err_code==0:
|
outputArguments = "验证码发送失败,请检查手机号格式,或其他异常"
|
||||||
# outputArguments='验证码发送成功'
|
# 成功的响应 0成功 -1失败
|
||||||
# else:
|
content = {
|
||||||
# outputArguments='验证码发送失败,请检查手机号格式,或其他异常'
|
"err_code": err_code,
|
||||||
# # 成功的响应 0成功 -1失败
|
"data_list": [{"outputArguments": outputArguments}],
|
||||||
|
}
|
||||||
# content = {"err_code": err_code,"data_list": [{"outputArguments":outputArguments}]}
|
|
||||||
|
|
||||||
# background_tasks.add_task(resData,inputArguments,uid)
|
|
||||||
content = {"err_code": 0, "data_list": [{"outputArguments": "test"}]}
|
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
return JSONResponse(content=content, headers=headers)
|
return JSONResponse(content=content, headers=headers)
|
||||||
|
|
||||||
|
# # 微信对话平台一定要选择: 随机回复
|
||||||
|
# background_tasks.add_task(resData, inputArguments, uid)
|
||||||
|
# content = {"err_code": 0, "data_list": [{"outputArguments": "test"}]}
|
||||||
|
# headers = {"Content-Type": "application/json"}
|
||||||
|
# return JSONResponse(content=content, headers=headers)
|
||||||
|
|||||||
Reference in New Issue
Block a user