更新验证器

This commit is contained in:
taiyi 2025-11-29 18:30:43 +08:00
parent 166506977e
commit 24c4efc128

46
test.py
View File

@ -1,5 +1,43 @@
text = "```markdown你好的"
import json
if "```markdown" in text:
text = text.replace("```markdown", "")
print(text)
import requests
def text_detection(text):
"""
百度检验文字是否违规
:param text:
:return:
"""
url = "https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined?access_token=" + get_baidu_access_token()
payload = 'text=' + text
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
content = str(response.text)
data = json.loads(content)
print(data)
# 安全地获取 conclusion 字段,如果不存在则返回默认值
conclusion = data.get('conclusion')
return conclusion
def get_baidu_access_token():
"""
使用 AKSK 生成鉴权签名Access Token百度信息获取
:return: access_token或是None(如果错误)
"""
API_KEY = "K7T5muBpNEdx1ebfc2YTag4W"
SECRET_KEY = "U3jkLq3BljN1q9YKnbFou2BY2167HZl6"
url = "https://aip.baidubce.com/oauth/2.0/token"
params = {"grant_type": "client_credentials", "client_id": API_KEY, "client_secret": SECRET_KEY}
return str(requests.post(url, params=params).json().get("access_token"))
text = "我草泥马"
result = text_detection(text)
print(result)