six_003
This commit is contained in:
@@ -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