update:测试
This commit is contained in:
96
app.py
96
app.py
@@ -1,7 +1,7 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
from fastapi import FastAPI,Header
|
from fastapi import FastAPI, Header
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
from flashSMS import sendFlash
|
from flashSMS import sendFlash
|
||||||
from tgMesaage import sendTg
|
from tgMesaage import sendTg
|
||||||
import re
|
import re
|
||||||
import pickle
|
import pickle
|
||||||
@@ -13,33 +13,34 @@ app = FastAPI()
|
|||||||
|
|
||||||
|
|
||||||
# 判断uid是否存在
|
# 判断uid是否存在
|
||||||
def findUid(uiddata,phoneNum):
|
def findUid(uiddata, phoneNum):
|
||||||
isFind=False
|
isFind = False
|
||||||
newDict={}
|
newDict = {}
|
||||||
if(os.path.exists("data.txt")):
|
if os.path.exists("data.txt"):
|
||||||
# print('文件存在')
|
# print('文件存在')
|
||||||
with open("data.txt", "rb") as f:
|
with open("data.txt", "rb") as f:
|
||||||
newDict=pickle.load(f)
|
newDict = pickle.load(f)
|
||||||
if newDict[uiddata] is not None:
|
if newDict[uiddata] is not None:
|
||||||
print('newDict[uid]',newDict[uiddata])
|
print("newDict[uid]", newDict[uiddata])
|
||||||
isFind= True
|
isFind = True
|
||||||
else:
|
else:
|
||||||
newDict[uiddata] = phoneNum
|
newDict[uiddata] = phoneNum
|
||||||
with open("data.txt", "wb") as f:
|
with open("data.txt", "wb") as f:
|
||||||
pickle.dump(newDict, f)
|
pickle.dump(newDict, f)
|
||||||
isFind= False
|
isFind = False
|
||||||
return isFind
|
return isFind
|
||||||
else:
|
else:
|
||||||
# print('文件不存在')
|
# print('文件不存在')
|
||||||
isFind= False
|
isFind = False
|
||||||
newDict[uiddata] = phoneNum
|
newDict[uiddata] = phoneNum
|
||||||
with open("data.txt", "wb") as f:
|
with open("data.txt", "wb") as f:
|
||||||
pickle.dump(newDict, f)
|
pickle.dump(newDict, f)
|
||||||
return isFind
|
return isFind
|
||||||
|
|
||||||
|
|
||||||
# findUid('test','13243889782')
|
# findUid('test','13243889782')
|
||||||
|
|
||||||
|
|
||||||
# 正则查找11位手机号
|
# 正则查找11位手机号
|
||||||
def findPhoneNum(text):
|
def findPhoneNum(text):
|
||||||
pattern = re.compile(r"1[356789]\d{9}")
|
pattern = re.compile(r"1[356789]\d{9}")
|
||||||
@@ -47,50 +48,71 @@ def findPhoneNum(text):
|
|||||||
result = pattern.findall(text)
|
result = pattern.findall(text)
|
||||||
print(result)
|
print(result)
|
||||||
# ['13987692110']
|
# ['13987692110']
|
||||||
if len(result)>0:
|
if len(result) > 0:
|
||||||
return result[0]
|
return result[0]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
#def read_root():
|
# def read_root():
|
||||||
# return {"Hello": "World"}
|
# return {"Hello": "World"}
|
||||||
def read_items(appid: Union[str, None] = Header(default=None),bid: Union[str, None] = Header(default=None),requestid: Union[str, None] = Header(default=None),uid: Union[str, None] = Header(default=None)):
|
def read_items(
|
||||||
print("console :,","appid", appid,"bid", bid,"requestid", requestid,"uid", uid)
|
appid: Union[str, None] = Header(default=None),
|
||||||
return {"appid": appid,"bid": bid,"requestid": requestid,"uid": uid}
|
bid: Union[str, None] = Header(default=None),
|
||||||
|
requestid: Union[str, None] = Header(default=None),
|
||||||
|
uid: Union[str, None] = Header(default=None),
|
||||||
|
):
|
||||||
|
print("console :,", "appid", appid, "bid", bid, "requestid", requestid, "uid", uid)
|
||||||
|
return {"appid": appid, "bid": bid, "requestid": requestid, "uid": uid}
|
||||||
|
|
||||||
|
|
||||||
# 微信对话-用户输入
|
# 微信对话-用户输入
|
||||||
@app.get("/input")
|
@app.get("/input")
|
||||||
async def getphonenum(inputArguments: Union[str, None] = None,appid: Union[str, None] = Header(default=None),bid: Union[str, None] = Header(default=None),requestid: Union[str, None] = Header(default=None),uid: Union[str, None] = Header(default=None)):
|
async def getphonenum(
|
||||||
print('inputArguments',inputArguments)
|
inputArguments: Union[str, None] = None,
|
||||||
# uid:唯一标识用户的openid
|
appid: Union[str, None] = Header(default=None),
|
||||||
print("appid", appid,"bid",bid,"requestid", requestid,"uid", uid)
|
bid: Union[str, None] = Header(default=None),
|
||||||
|
requestid: Union[str, None] = Header(default=None),
|
||||||
|
uid: Union[str, None] = Header(default=None),
|
||||||
|
):
|
||||||
|
print("inputArguments", inputArguments)
|
||||||
|
# uid:唯一标识用户的openid
|
||||||
|
print("appid", appid, "bid", bid, "requestid", requestid, "uid", uid)
|
||||||
# uid='wxx'
|
# uid='wxx'
|
||||||
# 要处理url编码问题decode
|
# 要处理url编码问题decode
|
||||||
try:
|
try:
|
||||||
inputArguments = unquote(inputArguments, 'utf-8')
|
inputArguments = unquote(inputArguments, "utf-8")
|
||||||
except:
|
except:
|
||||||
inputArguments=''
|
inputArguments = ""
|
||||||
# 正则获取11位手机号
|
# 正则获取11位手机号
|
||||||
phonenumber=findPhoneNum(inputArguments)
|
phonenumber = findPhoneNum(inputArguments)
|
||||||
print('phonenumber',phonenumber)
|
print("phonenumber", phonenumber)
|
||||||
# # phonenumber='13243889782'
|
# # phonenumber='13243889782'
|
||||||
if phonenumber is not None and uid is not None:
|
if phonenumber is not None and uid is not None:
|
||||||
warntext='[异度世界],微信加群验证码:3399'
|
warntext = "[异度世界],微信加群验证码:3399"
|
||||||
sendTg(f'用户手机号{phonenumber},开始发送验证码')
|
sendTg(f"用户手机号{phonenumber},开始发送验证码")
|
||||||
# 判断用户uid是都触发过短信,不允许触发第2次
|
# 判断用户uid是都触发过短信,不允许触发第2次
|
||||||
if findUid(uid,phonenumber) is True:
|
if findUid(uid, phonenumber) is True:
|
||||||
print('用户uid已存在,不触发短信')
|
print("用户uid已存在,不触发短信")
|
||||||
sendTg(f'用户{uid}已存在,不触发短信')
|
sendTg(f"用户{uid}已存在,不触发短信")
|
||||||
else:
|
else:
|
||||||
# 发送闪信
|
# 发送闪信
|
||||||
sendFlash(phonenumber,warntext)
|
sendFlash(phonenumber, warntext)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
sendTg(f'用户输入:{inputArguments},手机号不正确,或者uid参数异常')
|
sendTg(f"用户输入:{inputArguments},手机号不正确,或者uid参数异常")
|
||||||
|
|
||||||
# 存储uid和手机号
|
# 存储uid和手机号
|
||||||
# return {"appid": appid,"bid": bid,"requestid": requestid,"uid": uid,'inputArguments':inputArguments}
|
# return {"appid": appid,"bid": bid,"requestid": requestid,"uid": uid,'inputArguments':inputArguments}
|
||||||
content = {"err_code": 0,"data_list": [{"outputArguments":'test'}]}
|
# content = {"err_code": 0,"data_list": [{"outputArguments":'test'}]}
|
||||||
headers = { "Content-Type":"application/json"}
|
content = {
|
||||||
|
"ans_node_name": "小微闲聊",
|
||||||
|
"title": "小薇兄你好",
|
||||||
|
"answer": "你好呀!",
|
||||||
|
"from_user_name": "o9U-85tEZToQxIF8ht6o-KkagxO0",
|
||||||
|
"status": "FAQ",
|
||||||
|
"to_user_name": "xalsjfasf1ljasjdf1",
|
||||||
|
}
|
||||||
|
headers = {"Content-Type": "application/json"}
|
||||||
return JSONResponse(content=content, headers=headers)
|
return JSONResponse(content=content, headers=headers)
|
||||||
|
|||||||
Reference in New Issue
Block a user