update
This commit is contained in:
parent
1b34452c1f
commit
bfff5ada51
@ -157,8 +157,6 @@ async def wechat_corp_callback(
|
||||
update_detail=update_detail,
|
||||
join_user_id=join_user_id
|
||||
)
|
||||
logger.info(f"发送欢迎消息到群聊:{chat_id}")
|
||||
await wecom_client.send_welcome_message(chat_id)
|
||||
|
||||
# 兼容旧格式,如果找不到MemChangeList,尝试JoinUserID
|
||||
elif msg_root.find('JoinUserID') is not None:
|
||||
@ -172,8 +170,6 @@ async def wechat_corp_callback(
|
||||
update_detail=update_detail,
|
||||
join_user_id=join_user_id
|
||||
)
|
||||
logger.info(f"发送欢迎消息到群聊:{chat_id}")
|
||||
await wecom_client.send_welcome_message(chat_id)
|
||||
|
||||
# 处理成员离开事件
|
||||
elif update_detail == 'del_member':
|
||||
|
||||
@ -116,68 +116,6 @@ class WecomClient:
|
||||
logger.error(f"unionid_to_external_userid异常: {str(e)}")
|
||||
return None
|
||||
|
||||
async def send_welcome_message(self, chat_id: str, user_id: str = None) -> bool:
|
||||
"""发送欢迎消息
|
||||
|
||||
Args:
|
||||
chat_id: 群聊ID
|
||||
user_id: 用户ID,如果指定则发送私信,否则发送群消息
|
||||
|
||||
Returns:
|
||||
bool: 是否发送成功
|
||||
"""
|
||||
try:
|
||||
# 1. 获取 access_token
|
||||
access_token = await self.get_access_token()
|
||||
if not access_token:
|
||||
logger.error("获取access_token失败")
|
||||
return False
|
||||
|
||||
welcome_text = f"""🥳 欢迎您进群,在群内可以享受📦【代取快递】跑腿服务。
|
||||
|
||||
‼ 微信下单,快递到家 ‼
|
||||
|
||||
🎁 新人礼包
|
||||
𝟏 赠送𝟏𝟓张【𝟑元跑腿券】
|
||||
𝟐 赠送𝟔枚鲜鸡蛋【首次下单】
|
||||
━ ━ ━ ━ ━🎊━ ━ ━ ━ ━
|
||||
↓点击↓小程序领券下单 &"""
|
||||
|
||||
# 2. 发送欢迎消息
|
||||
if user_id:
|
||||
# 发送私信
|
||||
url = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg?access_token={access_token}"
|
||||
data = {
|
||||
"welcome_code": user_id, # 这里使用user_id作为临时的欢迎码
|
||||
"text": {
|
||||
"content": welcome_text
|
||||
}
|
||||
}
|
||||
else:
|
||||
# 发送群消息
|
||||
url = f"https://qyapi.weixin.qq.com/cgi-bin/appchat/send?access_token={access_token}"
|
||||
data = {
|
||||
"chatid": chat_id,
|
||||
"msgtype": "text",
|
||||
"text": {
|
||||
"content": welcome_text
|
||||
},
|
||||
"safe": 0
|
||||
}
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(url, json=data) as response:
|
||||
result = await response.json()
|
||||
if result.get("errcode") == 0:
|
||||
return True
|
||||
else:
|
||||
logger.error(f"发送欢迎消息失败: {result}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"发送欢迎消息异常: {str(e)}")
|
||||
return False
|
||||
|
||||
async def get_external_chat_info(self, chat_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""获取外部群聊信息
|
||||
|
||||
@ -358,14 +296,6 @@ class WecomClient:
|
||||
member_db = WecomExternalChatMemberDB(**member_create.model_dump())
|
||||
db.add(member_db)
|
||||
db.commit()
|
||||
|
||||
# 发送欢迎消息
|
||||
if member_type == "EXTERNAL":
|
||||
await self.send_welcome_message(chat_id)
|
||||
|
||||
# 更新发送欢迎消息状态
|
||||
member_db.welcome_sent = True
|
||||
db.commit()
|
||||
|
||||
# 更新群成员数量
|
||||
if chat_db:
|
||||
|
||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user