This commit is contained in:
parent
11b29da03a
commit
0cc256601a
|
@ -5,7 +5,7 @@ class Http(object):
|
|||
BASE_URL = 'http://114.215.169.94:7035'
|
||||
|
||||
@classmethod
|
||||
def get_new_user_msg(cls, corpid, userid, external_userid, uid=None):
|
||||
def get_new_user_msg(cls, corpid, userid, external_userid=None, uid=None):
|
||||
uid = uid or 3
|
||||
url = f'{cls.BASE_URL}/api/newusermsg/getnewusermsg'
|
||||
params = {
|
||||
|
@ -19,7 +19,6 @@ class Http(object):
|
|||
return True, res.json().get('data')
|
||||
return False, None
|
||||
|
||||
# api/newusermsg/getkeywordreplymsg?corpId=&userId=&uId=&externalUserId=&sendType=&content=
|
||||
@classmethod
|
||||
def get_keyword_reply_msg(cls, corpid, userid, external_userid, uid=None, send_type=0, content=None):
|
||||
# sendType 0 私聊,1 群聊
|
||||
|
@ -38,8 +37,59 @@ class Http(object):
|
|||
return True, res.json().get('data')
|
||||
return False, None
|
||||
|
||||
@classmethod
|
||||
def get_appoint_user_msg(cls, corpid, userid, external_userid, group_id, uid=None, send_type=0, send_table_type=0,
|
||||
send_form=None, content_id=None, content_name=None):
|
||||
"""
|
||||
groupId 群id;
|
||||
sendType 0 私聊,1 群聊;
|
||||
sendTableType 0 新客欢迎表,1 关键词回复表,2 群发任务表
|
||||
contentId 主键Id
|
||||
contenrName 内容名称
|
||||
sendForm 0 极速群发,1=高级群发
|
||||
"""
|
||||
uid = uid or 3
|
||||
url = f'{cls.BASE_URL}/api/newusermsg/getappointusermsg'
|
||||
params = {
|
||||
'corpId': corpid,
|
||||
'userId': userid,
|
||||
'groupId': group_id,
|
||||
'externalUserId': external_userid,
|
||||
'uId': uid,
|
||||
'sendType': send_type,
|
||||
'sendTableType': send_table_type,
|
||||
'sendForm': send_form,
|
||||
'contentId': content_id,
|
||||
'contenrName': content_name,
|
||||
}
|
||||
res = requests.get(url, params=params)
|
||||
if res.status_code == 200:
|
||||
return True, res.json().get('data')
|
||||
return False, None
|
||||
|
||||
# api/newusermsg/getagentsendmsg?msgId=&corpId=&userId=&externalUserId=
|
||||
# msgId jqr_sendmsgrecordinfo id字段 必传
|
||||
# corpId 企业id 非必传
|
||||
# userId 用户id 非必传
|
||||
# externalUserId 接收人id 非必传
|
||||
@classmethod
|
||||
def get_agent_send_msg(cls, msg_id, corpid=None, userid=None, external_userid=None, uid=None):
|
||||
uid = uid or 3
|
||||
url = f'{cls.BASE_URL}/api/newusermsg/getagentsendmsg'
|
||||
params = {
|
||||
'corpId': corpid,
|
||||
'userId': userid,
|
||||
'externalUserId': external_userid,
|
||||
'msgId': msg_id,
|
||||
'uId': uid,
|
||||
}
|
||||
res = requests.get(url, params=params)
|
||||
if res.status_code == 200:
|
||||
return True, res.json().get('data')
|
||||
return False, None
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
success, data = Http.get_new_user_msg('ww056d00fac4950f54', 'agent-Wang', 'wmy1VmQgAAd1BJaEHCrdOttQop7gg8Rg')
|
||||
success, data = Http.get_new_user_msg('ww056d00fac4950f54', 'QingFeng', 'wmy1VmQgAAWxMDKJdWrY1mY_Gl8HAHwQ')
|
||||
print(success)
|
||||
print(data)
|
||||
|
|
|
@ -93,7 +93,7 @@ def save_add_contact_by_channel(data, corpinfo, *args, **kwargs):
|
|||
success = rc.try_lock(60 * 10)
|
||||
if hook_user.utime > nine_minute_ago and hook_user.new_user and success:
|
||||
# 发送消息
|
||||
send_new_user_msg(corpid, userid, externaluserid, uid=uid)
|
||||
send_new_user_msg(corpid, userid, external_userid=externaluserid, uid=uid)
|
||||
|
||||
|
||||
@shared_task(name='edit_add_contact', queue='contact')
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from apps.jqr.choices import JqrSendGroupMsgIsOpenChoices, JqrSendGroupMsgSendUserTypeChoices, \
|
||||
JqrSendGroupMsgSendTagTypeChoices
|
||||
from apps.jqr.ksy_http import Http
|
||||
|
@ -83,19 +85,65 @@ def get_jqr_new_send_msg_info(corpid, userid, external_userid):
|
|||
pass
|
||||
|
||||
|
||||
def send_new_user_msg(corpid, userid, external_userid, uid=None):
|
||||
msgtype_content_map = {
|
||||
1: {
|
||||
'key': 'textMsgContent',
|
||||
'replace_keys': None
|
||||
},
|
||||
2: {
|
||||
'key': 'imgMsgContent',
|
||||
'replace_keys': ['url']
|
||||
},
|
||||
3: {
|
||||
'key': 'videoMsgContent',
|
||||
'replace_keys': ['videoUrl', 'imgUrl']
|
||||
},
|
||||
4: {
|
||||
'key': 'mimiProgramMsgContent',
|
||||
'replace_keys': ['imgUrl']
|
||||
},
|
||||
5: {
|
||||
'key': 'linkMsgContent',
|
||||
'replace_keys': ['imgUrl']
|
||||
},
|
||||
6: {
|
||||
'key': 'feedVideoMsgContent',
|
||||
'replace_keys': ['avatar', 'coverUrl', 'thumbUrl', 'url']
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def transfer_data(data):
|
||||
msg_list = data.get('msgList')
|
||||
for msg in msg_list:
|
||||
msg_type = msg.get('msgType')
|
||||
content_map = msgtype_content_map.get(msg_type)
|
||||
content_key = content_map.get('key')
|
||||
replace_keys = content_map.get('replace_keys')
|
||||
content = msg.get(content_key)
|
||||
if not replace_keys:
|
||||
continue
|
||||
if content and isinstance(content, dict):
|
||||
for replace_key in replace_keys:
|
||||
if not content[replace_key].startswith('http'):
|
||||
content[replace_key] = f'{settings.CDN_URL}{content[replace_key]}'
|
||||
|
||||
|
||||
def send_new_user_msg(corpid, userid, external_userid=None, chat_id=None, uid=None):
|
||||
# 发送新客欢迎
|
||||
try:
|
||||
success, data = Http.get_new_user_msg(corpid, userid, external_userid, uid=uid)
|
||||
logger.info(f'send new user msg http ---> success: {success}, data: {data}')
|
||||
if not success:
|
||||
success, data = Http.get_new_user_msg(corpid, userid, external_userid=external_userid, uid=uid)
|
||||
if not success or data is None:
|
||||
logger.error(f'corpid: {corpid}, userid: {userid}, external_userid: {external_userid}, 发送新客欢迎失败')
|
||||
return
|
||||
return False, '获取发送内容失败'
|
||||
transfer_data(data)
|
||||
status_code = WS.send_wx_work_msg(data)
|
||||
success = status_code == 200
|
||||
logger.info(
|
||||
f'corpid: {corpid}, userid: {userid}, external_userid: {external_userid},发送新客欢迎消息成功状态:{success}, status_code: {status_code}')
|
||||
return success
|
||||
f'corpid: {corpid}, userid: {userid}, external_userid: {external_userid},发送新客欢迎消息成功状态:{success}')
|
||||
if not success:
|
||||
return False, '发送新客欢迎消息失败'
|
||||
return success, ''
|
||||
except Exception as e:
|
||||
logger.error(f'exception corpid: {corpid}, userid: {userid}, external_userid: {external_userid}, 发送新客欢迎异常: {e}')
|
||||
pass
|
||||
logger.error(f'corpid: {corpid}, userid: {userid}, external_userid: {external_userid}, 发送新客欢迎失败: {e}')
|
||||
return False, '发送新客欢迎消息失败'
|
||||
|
|
|
@ -182,6 +182,7 @@ STATIC_ROOT = BASE_DIR / "staticfiles"
|
|||
STATICFILES_DIR = []
|
||||
MEDIA_URL = ""
|
||||
MEDIA_ROOT = BASE_DIR.parent / ""
|
||||
CDN_URL = 'https://c.r-6.cn/'
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
|
|
Loading…
Reference in New Issue