瀏覽代碼

refactor: rename WechatComChannel to WechatComAppChannel

master
lanvent 1 年之前
父節點
當前提交
d2bf90c6c7
共有 4 個文件被更改,包括 22 次插入21 次删除
  1. +2
    -2
      channel/channel_factory.py
  2. +11
    -11
      channel/wechatcom/wechatcomapp_channel.py
  3. +1
    -1
      channel/wechatcom/wechatcomapp_message.py
  4. +8
    -7
      config.py

+ 2
- 2
channel/channel_factory.py 查看文件

@@ -30,7 +30,7 @@ def create_channel(channel_type):


return WechatMPChannel(passive_reply=False) return WechatMPChannel(passive_reply=False)
elif channel_type == "wechatcom": elif channel_type == "wechatcom":
from channel.wechatcom.wechatcom_channel import WechatComChannel
from channel.wechatcom.wechatcomapp_channel import WechatComAppChannel


return WechatComChannel()
return WechatComAppChannel()
raise RuntimeError raise RuntimeError

channel/wechatcom/wechatcom_channel.py → channel/wechatcom/wechatcomapp_channel.py 查看文件

@@ -14,7 +14,7 @@ from wechatpy.exceptions import InvalidSignatureException, WeChatClientException
from bridge.context import Context from bridge.context import Context
from bridge.reply import Reply, ReplyType from bridge.reply import Reply, ReplyType
from channel.chat_channel import ChatChannel from channel.chat_channel import ChatChannel
from channel.wechatcom.wechatcom_message import WechatComMessage
from channel.wechatcom.wechatcomapp_message import WechatComAppMessage
from common.log import logger from common.log import logger
from common.singleton import singleton from common.singleton import singleton
from config import conf from config import conf
@@ -22,16 +22,16 @@ from voice.audio_convert import any_to_amr




@singleton @singleton
class WechatComChannel(ChatChannel):
class WechatComAppChannel(ChatChannel):
NOT_SUPPORT_REPLYTYPE = [] NOT_SUPPORT_REPLYTYPE = []


def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.corp_id = conf().get("wechatcom_corp_id") self.corp_id = conf().get("wechatcom_corp_id")
self.secret = conf().get("wechatcom_secret")
self.agent_id = conf().get("wechatcom_agent_id")
self.token = conf().get("wechatcom_token")
self.aes_key = conf().get("wechatcom_aes_key")
self.secret = conf().get("wechatcomapp_secret")
self.agent_id = conf().get("wechatcomapp_agent_id")
self.token = conf().get("wechatcomapp_token")
self.aes_key = conf().get("wechatcomapp_aes_key")
print(self.corp_id, self.secret, self.agent_id, self.token, self.aes_key) print(self.corp_id, self.secret, self.agent_id, self.token, self.aes_key)
logger.info( logger.info(
"[wechatcom] init: corp_id: {}, secret: {}, agent_id: {}, token: {}, aes_key: {}".format( "[wechatcom] init: corp_id: {}, secret: {}, agent_id: {}, token: {}, aes_key: {}".format(
@@ -43,9 +43,9 @@ class WechatComChannel(ChatChannel):


def startup(self): def startup(self):
# start message listener # start message listener
urls = ("/wxcom", "channel.wechatcom.wechatcom_channel.Query")
urls = ("/wxcom", "channel.wechatcom.wechatcomapp_channel.Query")
app = web.application(urls, globals(), autoreload=False) app = web.application(urls, globals(), autoreload=False)
port = conf().get("wechatcom_port", 8080)
port = conf().get("wechatcomapp_port", 8080)
web.httpserver.runsimple(app.wsgifunc(), ("0.0.0.0", port)) web.httpserver.runsimple(app.wsgifunc(), ("0.0.0.0", port))


def send(self, reply: Reply, context: Context): def send(self, reply: Reply, context: Context):
@@ -111,7 +111,7 @@ class WechatComChannel(ChatChannel):


class Query: class Query:
def GET(self): def GET(self):
channel = WechatComChannel()
channel = WechatComAppChannel()
params = web.input() params = web.input()
signature = params.msg_signature signature = params.msg_signature
timestamp = params.timestamp timestamp = params.timestamp
@@ -127,7 +127,7 @@ class Query:
return echostr return echostr


def POST(self): def POST(self):
channel = WechatComChannel()
channel = WechatComAppChannel()
params = web.input() params = web.input()
signature = params.msg_signature signature = params.msg_signature
timestamp = params.timestamp timestamp = params.timestamp
@@ -158,7 +158,7 @@ class Query:
return res return res
else: else:
try: try:
wechatcom_msg = WechatComMessage(msg, client=channel.client)
wechatcom_msg = WechatComAppMessage(msg, client=channel.client)
except NotImplementedError as e: except NotImplementedError as e:
logger.debug("[wechatcom] " + str(e)) logger.debug("[wechatcom] " + str(e))
return "success" return "success"

channel/wechatcom/wechatcom_message.py → channel/wechatcom/wechatcomapp_message.py 查看文件

@@ -11,7 +11,7 @@ from lib import itchat
from lib.itchat.content import * from lib.itchat.content import *




class WechatComMessage(ChatMessage):
class WechatComAppMessage(ChatMessage):
def __init__(self, msg, client: WeChatClient, is_group=False): def __init__(self, msg, client: WeChatClient, is_group=False):
super().__init__(msg) super().__init__(msg)
self.msg_id = msg.id self.msg_id = msg.id

+ 8
- 7
config.py 查看文件

@@ -75,13 +75,14 @@ available_setting = {
"wechatmp_port": 8080, # 微信公众平台的端口,需要端口转发到80或443 "wechatmp_port": 8080, # 微信公众平台的端口,需要端口转发到80或443
"wechatmp_app_id": "", # 微信公众平台的appID,仅服务号需要 "wechatmp_app_id": "", # 微信公众平台的appID,仅服务号需要
"wechatmp_app_secret": "", # 微信公众平台的appsecret,仅服务号需要 "wechatmp_app_secret": "", # 微信公众平台的appsecret,仅服务号需要
# wechatcom的配置
"wechatcom_token": "", # 企业微信的token
"wechatcom_port": 9898, # 企业微信的服务端口,不需要端口转发
"wechatcom_corp_id": "", # 企业微信的corpID
"wechatcom_secret": "", # 企业微信的secret
"wechatcom_agent_id": "", # 企业微信的appID
"wechatcom_aes_key": "", # 企业微信的aes_key
# wechatcom的通用配置
"wechatcom_corp_id": "", # 企业微信公司的corpID
# wechatcomapp的配置
"wechatcomapp_token": "", # 企业微信app的token
"wechatcomapp_port": 9898, # 企业微信app的服务端口,不需要端口转发
"wechatcomapp_secret": "", # 企业微信app的secret
"wechatcomapp_agent_id": "", # 企业微信app的agent_id
"wechatcomapp_aes_key": "", # 企业微信app的aes_key
# chatgpt指令自定义触发词 # chatgpt指令自定义触发词
"clear_memory_commands": ["#清除记忆"], # 重置会话指令,必须以#开头 "clear_memory_commands": ["#清除记忆"], # 重置会话指令,必须以#开头
# channel配置 # channel配置


Loading…
取消
儲存