优化京东token设置
This commit is contained in:
@@ -203,8 +203,8 @@ class JDTokenPlugin(MessagePluginInterface):
|
|||||||
gbm: GroupBotManager = message.get("gbm")
|
gbm: GroupBotManager = message.get("gbm")
|
||||||
bot: WechatAPIClient = message.get("bot")
|
bot: WechatAPIClient = message.get("bot")
|
||||||
|
|
||||||
# 检查命令格式
|
# 检查命令格式 - 修改正则表达式,使用非贪婪匹配捕获token部分
|
||||||
pattern = r'^设置京东\s+([^\s]+)\s+(.+)$'
|
pattern = r'^设置京东\s+(.+?)\s+([^\s].+)$'
|
||||||
match = re.match(pattern, content)
|
match = re.match(pattern, content)
|
||||||
|
|
||||||
if not match:
|
if not match:
|
||||||
@@ -220,13 +220,32 @@ class JDTokenPlugin(MessagePluginInterface):
|
|||||||
token = match.group(1)
|
token = match.group(1)
|
||||||
remark = match.group(2)
|
remark = match.group(2)
|
||||||
|
|
||||||
# 简单预检查token格式
|
# 清理token中的空格
|
||||||
if not token.startswith("pt_key=") or "pt_pin=" not in token:
|
token = token.replace(" ", "")
|
||||||
|
|
||||||
|
# 确保token格式正确
|
||||||
|
if "pt_key=" not in token or "pt_pin=" not in token:
|
||||||
await bot.send_text_message((roomid if roomid else sender),
|
await bot.send_text_message((roomid if roomid else sender),
|
||||||
f"❌ Token格式错误!正确格式应为:pt_key=xxx;pt_pin=xxx;",
|
f"❌ Token格式错误!正确格式应为:pt_key=xxx;pt_pin=xxx;",
|
||||||
sender)
|
sender)
|
||||||
return False, "Token格式错误"
|
return False, "Token格式错误"
|
||||||
|
|
||||||
|
# 标准化token格式
|
||||||
|
# 1. 确保pt_key和pt_pin之间有分号
|
||||||
|
if "pt_key=" in token and "pt_pin=" in token:
|
||||||
|
# 提取pt_key和pt_pin部分
|
||||||
|
pt_key_part = re.search(r'pt_key=[^;]*', token)
|
||||||
|
pt_pin_part = re.search(r'pt_pin=[^;]*', token)
|
||||||
|
|
||||||
|
if pt_key_part and pt_pin_part:
|
||||||
|
# 重新组合token,确保格式正确
|
||||||
|
token = f"{pt_key_part.group(0)};{pt_pin_part.group(0)};"
|
||||||
|
|
||||||
|
# 确保token以分号结尾
|
||||||
|
if not token.endswith(";"):
|
||||||
|
token += ";"
|
||||||
|
|
||||||
|
self.LOG.info(f"处理后的token格式: {token}")
|
||||||
try:
|
try:
|
||||||
# 设置京东Token
|
# 设置京东Token
|
||||||
result = self.set_jd_token(token, remark)
|
result = self.set_jd_token(token, remark)
|
||||||
|
|||||||
Reference in New Issue
Block a user