six_003
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
class wecom推广二维码:
|
||||
@classmethod
|
||||
def 设置授权应用可见范围(cls):
|
||||
"""
|
||||
调用该接口前提是开启通讯录迁移,收到授权成功通知后可调用。企业注册初始化安装应用后,应用默认可见范围为根部门。
|
||||
如需修改应用可见范围,服务商可以调用该接口设置授权应用的可见范围。
|
||||
该接口只能使用注册完成回调事件或者查询注册状态返回的access_token,
|
||||
调用设置通讯录同步完成后或者access_token超过30分钟失效(即解除通讯录锁定状态)则不能继续调用该接口
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
@@ -1,63 +0,0 @@
|
||||
import dataclasses
|
||||
|
||||
import jmespath
|
||||
import pydash
|
||||
import requests
|
||||
from asgiref.sync import async_to_sync
|
||||
from channels.layers import get_channel_layer
|
||||
|
||||
from sixGuoDjango import redis_5
|
||||
from wechat_项目工具包.企业微信工具包.客户管理 import wecom客户管理
|
||||
from wechat_项目工具包.企业微信工具包.消息推送工具 import wecom消息推送
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class six企微回调业务处理方法():
|
||||
pass
|
||||
|
||||
def 添加企业客户事件(self, as_data):
|
||||
""""""
|
||||
"""
|
||||
添加企业客户事件
|
||||
参数 说明 配置了客户联系功能的成员添加外部联系人时,回调该事件
|
||||
ToUserName 企业微信CorpID
|
||||
FromUserName 此事件该值固定为sys,表示该消息由系统生成
|
||||
CreateTime 消息创建时间 (整型)
|
||||
MsgType 消息的类型,此时固定为event
|
||||
Event 事件的类型,此时固定为change_external_contact
|
||||
ChangeType 此时固定为add_external_contact
|
||||
UserID 企业服务人员的UserID
|
||||
ExternalUserID 外部联系人的userid,注意不是企业成员的账号
|
||||
State 添加此用户的「联系我」方式配置的state参数,或在获客链接中指定的customer_channel参数,可用于识别添加此用户的渠道
|
||||
WelcomeCode 欢迎语code,可用于发送欢迎语
|
||||
"""
|
||||
# 这是用户在添加企微好友成功时的回调信息;
|
||||
ToUserName = pydash.get(obj=as_data, path="xml.ToUserName") # toUser 企业微信CorpID
|
||||
FromUserName = pydash.get(obj=as_data, path="xml.FromUserName") # sys 此事件该值固定为sys,表示该消息由系统生成
|
||||
CreateTime = pydash.get(obj=as_data, path="xml.CreateTime") # 1403610513 消息创建时间 (整型)
|
||||
MsgType = pydash.get(obj=as_data, path="xml.MsgType") # event 消息的类型,此时固定为event
|
||||
Event = pydash.get(obj=as_data, path="xml.Event") # change_external_contact 事件的类型,此时固定为change_external_contact
|
||||
ChangeType = pydash.get(obj=as_data, path="xml.ChangeType") # add_external_contact 此时固定为add_external_contact
|
||||
UserID = pydash.get(obj=as_data, path="xml.UserID") # UserID 企业服务人员的UserID
|
||||
ExternalUserID = pydash.get(obj=as_data, path="xml.ExternalUserID", ) # woAJ2GCAAAXtWyujaWJHDDGi0mAAAA 外部联系人的userid,注意不是企业成员的账号
|
||||
State = pydash.get(obj=as_data, path="xml.State", ) # teststate 添加此用户的「联系我」方式配置的state参数,或在获客链接中指定的customer_channel参数,可用于识别添加此用户的渠道
|
||||
WelcomeCode = pydash.get(obj=as_data, path="xml.WelcomeCode") # WELCOMECODE 欢迎语code,可用于发送欢迎语
|
||||
# 发送欢迎语
|
||||
print("添加企业客户事件")
|
||||
|
||||
res_welcom_code = wecom消息推送.发送新客户欢迎语(CALLBACK_CODE=WelcomeCode)
|
||||
# 获取用户的 unionid (主要就是获取用户的unionid的值)
|
||||
res = wecom客户管理.获取客户详情(external_userid=ExternalUserID)
|
||||
print(res)
|
||||
unionid = jmespath.search(data=res, expression="external_contact.unionid")
|
||||
print(unionid)
|
||||
wecom_pay_data = requests.post(url="https://xiao.sixgou.com/demopay/transfer/", json={"unionid": unionid})
|
||||
# 存储数据(用户添加后的数据)
|
||||
print("打印数据类型", wecom_pay_data.json())
|
||||
print("打印数据类型", type(wecom_pay_data.json()))
|
||||
payData = wecom_pay_data.json()
|
||||
channels_name = redis_5.get(name=unionid)
|
||||
default_channel_layer = get_channel_layer(alias="default")
|
||||
async_to_sync(awaitable=default_channel_layer.send)(channel=channels_name, message={"type": "chat_subMsg", "data": payData})
|
||||
pass
|
||||
# 调用发红包的功能
|
||||
@@ -2,6 +2,7 @@
|
||||
import os
|
||||
|
||||
import django
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from sixGuoDjango.settings import BASE_DIR
|
||||
from wechat_token.token工具包 import sixToken
|
||||
@@ -9,40 +10,36 @@ from wechat_token.token工具包 import sixToken
|
||||
os.environ.setdefault(key="DJANGO_SETTINGS_MODULE", value=f"{BASE_DIR.name}.settings")
|
||||
django.setup()
|
||||
|
||||
import datetime
|
||||
|
||||
import jmespath
|
||||
import requests
|
||||
|
||||
from requests import post
|
||||
|
||||
|
||||
class wecom管理企业标签:
|
||||
class wecom管理企业标签(BaseModel):
|
||||
"""
|
||||
管理企业标签
|
||||
最后更新:2023/12/01
|
||||
企业客户标签是针对企业的外部联系人进行标记和分类的标签,由企业统一配置后,企业成员可使用此标签对客户进行标记。
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def 获取企业标签库(cls):
|
||||
wecom_token: str = sixToken.get_wecom_token()
|
||||
agentid: str = Field(default="1000025", description="agentid")
|
||||
|
||||
def 获取企业标签库(self, ):
|
||||
"""
|
||||
在这里返回结果为:企业微信创建的所有的企业标签,不包含个人标签
|
||||
企业可通过此接口获取企业客户标签详情。请求方式: POST(HTTP)
|
||||
"""
|
||||
pass
|
||||
wecom_token = sixToken.get_wecom_token()
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list?access_token={wecom_token}"
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list?access_token={self.wecom_token}"
|
||||
data = post(url=uri).json()
|
||||
print(data)
|
||||
tag_group = jmespath.search(data=data, expression="tag_group")
|
||||
for tag in tag_group:
|
||||
print(tag)
|
||||
|
||||
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
def 添加企业客户标签(cls):
|
||||
|
||||
def 添加企业客户标签(self):
|
||||
"""
|
||||
企业可通过此接口向客户标签库中添加新的标签组和标签,每个企业最多可配置10000个企业标签。
|
||||
注意:
|
||||
@@ -55,33 +52,26 @@ class wecom管理企业标签:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
wecom_token = sixToken.get_wecom_token()
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag?access_token={wecom_token}"
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag?access_token={self.wecom_token}"
|
||||
请求数据示例 = {
|
||||
"group_id": "etj4zANAAA1Zh_RyLIpjOr6IbuMPRB8g", # 否 标签组id
|
||||
# "group_name": "泰州市", # 否 标签组名称,最长为30个字符
|
||||
"group_name": "我的新标签组",
|
||||
"order": 1,
|
||||
"tag": [
|
||||
{
|
||||
"name": "未知", # 是 添加的标签名称,最长为30个字符
|
||||
"order": 1, # 否 标签次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
|
||||
},
|
||||
],
|
||||
# "agentid": 1000014, # 授权方安装的应用agentid。仅旧的第三方多应用套件需要填此参数
|
||||
{"name": "标签1", "order": 1},
|
||||
{"name": "标签2", "order": 2}
|
||||
]
|
||||
}
|
||||
data = post(url=uri, json=请求数据示例).json()
|
||||
print(data)
|
||||
|
||||
@classmethod
|
||||
def 编辑客户企业标签(cls, userid: str, external_userid: str, add_tag: str):
|
||||
|
||||
def 编辑客户企业标签(self, userid: str, external_userid: str, add_tag: str):
|
||||
"""
|
||||
企业可通过此接口为指定成员的客户添加上由企业统一配置的标签;注意,每个成员对同一个客户最多可以添加3000个标签。
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
wecom_token = sixToken.get_wecom_token()
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token={wecom_token}"
|
||||
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token={self.wecom_token}"
|
||||
请求数据示例 = {
|
||||
# "userid": "YuanBao1975", # 是 添加外部联系人的userid
|
||||
"userid": userid, # 是 添加外部联系人的userid
|
||||
@@ -93,32 +83,23 @@ class wecom管理企业标签:
|
||||
}
|
||||
data = post(url=uri, json=请求数据示例).json()
|
||||
print(data)
|
||||
|
||||
@classmethod
|
||||
def 更新所有的企业标签并存储到数据库(cls):
|
||||
|
||||
def 删除企业客户标签(self, 标签组ID, 标签子标签ID=None):
|
||||
pass
|
||||
data = cls.获取企业标签库()
|
||||
tag_group = jmespath.search(data=data, expression="tag_group", )
|
||||
for tag_list in tag_group:
|
||||
print(tag_list)
|
||||
# tag_list = jmespath.search(data=tag_list, expression="tag", )
|
||||
group_id = jmespath.search(data=tag_list, expression="group_id", )
|
||||
group_name = jmespath.search(data=tag_list, expression="group_name", )
|
||||
create_time = jmespath.search(data=tag_list, expression="create_time", )
|
||||
# create_time = pydash.get(obj=tag_list, path="create_time", )
|
||||
# 需要将时间戳转为时间格式
|
||||
print(create_time, "========", )
|
||||
create_time_1 = datetime.datetime.fromtimestamp(create_time)
|
||||
#
|
||||
|
||||
tag_child_list = jmespath.search(data=tag_list, expression="tag", )
|
||||
|
||||
@classmethod
|
||||
def 更新所有的用户性别组标签(cls):
|
||||
"""删除已经创建的 企业标签 tag_id和group_id不可同时为空。如果一个标签组下所有的标签均被删除,则标签组会被自动删除"""
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag?access_token={self.wecom_token}"
|
||||
删除的数据 = {
|
||||
# "tag_id": [],
|
||||
"group_id": [标签组ID],
|
||||
}
|
||||
postData = requests.post(url=uri, json=删除的数据)
|
||||
print(postData.text)
|
||||
# print(postData.json())
|
||||
|
||||
def 更新所有的用户性别组标签(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def 打标签性别(cls, userid: str, external_userid: str, gender: int):
|
||||
|
||||
def 打标签性别(self, userid: str, external_userid: str, gender: int):
|
||||
"""
|
||||
:param gender:
|
||||
:type gender:
|
||||
@@ -129,22 +110,24 @@ class wecom管理企业标签:
|
||||
"""
|
||||
print("单独更新用户性别标签")
|
||||
if gender == 1:
|
||||
cls.编辑客户企业标签(
|
||||
self.编辑客户企业标签(
|
||||
userid=userid, external_userid=external_userid,
|
||||
add_tag="et74kdKAAAO9rCHIG-GcT7ZU_gsTslkg",
|
||||
)
|
||||
if gender == 2:
|
||||
cls.编辑客户企业标签(
|
||||
self.编辑客户企业标签(
|
||||
userid=userid, external_userid=external_userid,
|
||||
add_tag="et74kdKAAAJUou62OZwyu3LeavfmxAhw",
|
||||
)
|
||||
if gender == 0:
|
||||
cls.编辑客户企业标签(
|
||||
self.编辑客户企业标签(
|
||||
userid=userid, external_userid=external_userid,
|
||||
add_tag="et74kdKAAAI_VNWc-Gzakmo_jGnK-Glw",
|
||||
)
|
||||
|
||||
def 给个微好友打标签(self):
|
||||
|
||||
def 给个微好友打标签(self, userID企微员工账号, external_userid要打标签的好友ID, add_tag要给好友添加的标签ID, remove_tag要对好友删除的标签ID=None):
|
||||
if remove_tag要对好友删除的标签ID is None:
|
||||
remove_tag要对好友删除的标签ID = []
|
||||
pass
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag"
|
||||
请求数据 = {
|
||||
@@ -153,16 +136,13 @@ class wecom管理企业标签:
|
||||
"add_tag": ["et74kdKAAAO9rCHIG-GcT7ZU_gsTslkg"], # 测试标签ID
|
||||
# "remove_tag": ["et74kdKAAAO9rCHIG-GcT7ZU_gsTslkg"] # 删除企业微信好友的 标签
|
||||
}
|
||||
wecom_token = sixToken.get_wecom_token()
|
||||
response_data = requests.post(url=uri, params={"access_token": wecom_token}, json=请求数据)
|
||||
response_data = requests.post(url=uri, params={"access_token": self.wecom_token}, json=请求数据)
|
||||
print(response_data.json())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
wecom管理企业标签.获取企业标签库()
|
||||
# wecom管理企业标签.添加企业客户标签()
|
||||
# wecom管理企业标签.更新所有的用户性别组标签()
|
||||
# wecom管理企业标签.更新所有的企业标签并存储到数据库()
|
||||
# wecom管理企业标签.获取企业标签库()
|
||||
# wecom管理企业标签().给个微好友打标签()
|
||||
|
||||
wecom管理企业标签().获取企业标签库()
|
||||
# wecom管理企业标签().删除企业客户标签(标签组ID="etj4zANAAA1Zh_RyLIpjOr6IbuMPRB8g")
|
||||
# wecom管理企业标签().添加企业客户标签()
|
||||
|
||||
Reference in New Issue
Block a user