six_001
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
"""客户群管理工具"""
|
||||
import os
|
||||
|
||||
import django
|
||||
from pydantic import BaseModel
|
||||
|
||||
from sixGuoDjango.settings import BASE_DIR
|
||||
|
||||
os.environ.setdefault(key="DJANGO_SETTINGS_MODULE", value=f"{BASE_DIR.name}.settings")
|
||||
django.setup()
|
||||
|
||||
from wechat_token.token工具包 import sixToken
|
||||
|
||||
from requests import post
|
||||
|
||||
|
||||
# class emsParameters(BaseModel):
|
||||
# demo_必填: int = Field(..., description="描述") # 必传属发生
|
||||
# demo_可选: Optional[int] = None # 可选值
|
||||
# demo_默认值: int = Field(default=100001, description="描述") # 有默认值
|
||||
# demo_联合类型: Literal["xiao", "zizi"] = Field(..., description="描述")
|
||||
#
|
||||
|
||||
|
||||
class wecom客户群管理(BaseModel):
|
||||
"""类注释"""
|
||||
pass
|
||||
|
||||
def get获取客户群列表(self):
|
||||
"""
|
||||
该接口用于获取配置过客户群管理的客户群列表。
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
wecom_token = sixToken.get_wecom_token()
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/list?access_token={wecom_token}"
|
||||
请求数据示例 = {
|
||||
# "status_filter": 0,
|
||||
# "owner_filter": {
|
||||
# "userid_list": ["abel"]
|
||||
# },
|
||||
# "cursor": "r9FqSqsI8fgNbHLHE5QoCP50UIg2cFQbfma3l2QsmwI",
|
||||
"limit": 10
|
||||
}
|
||||
data = post(url=uri, json=请求数据示例).json()
|
||||
print(data)
|
||||
|
||||
def get获取客户群详情(self, chat_id群号ID):
|
||||
"""
|
||||
通过客户群ID,获取详情。包括群名、群成员列表、群成员入群时间、入群方式。(客户群是由具有客户群使用权限的成员创建的外部群)
|
||||
需注意的是,如果发生群信息变动,会立即收到群变更事件,但是部分信息是异步处理,可能需要等一段时间调此接口才能得到最新结果
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
wecom_token = sixToken.get_wecom_token()
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get?access_token={wecom_token}"
|
||||
请求数据示例 = {
|
||||
"chat_id": chat_id群号ID, # 是 客户群ID
|
||||
"need_name": 1, # 否 是否需要返回群成员的名字group_chat.member_list.name。0-不返回;1-返回。默认不返回
|
||||
}
|
||||
data = post(url=uri, json=请求数据示例).json()
|
||||
print(data)
|
||||
|
||||
def 客户群opengid转换(self):
|
||||
"""
|
||||
用户在微信里的客户群里打开小程序时,某些场景下可以获取到群的opengid,如果该群是企业微信的客户群,则企业或第三方可以调用此接口将一个opengid转换为客户群chat_id
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
wecom_token = sixToken.get_wecom_token()
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/opengid_to_chatid?access_token={wecom_token}"
|
||||
请求数据示例 = {
|
||||
"opengid": "oAAAAAAA", # 是 小程序在微信获取到的群ID,参见wx.getGroupEnterInfo
|
||||
}
|
||||
data = post(url=uri, json=请求数据示例).json()
|
||||
print(data)
|
||||
|
||||
def 入群欢迎语素材管理(self):
|
||||
"""
|
||||
企业可通过此API向企业的入群欢迎语素材库中添加素材。每个企业的入群欢迎语素材库中,最多容纳100个素材。
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
wecom_token = sixToken.get_wecom_token()
|
||||
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/add?access_token={wecom_token}"
|
||||
请求数据示例 = {
|
||||
"text": {
|
||||
"content": "亲爱的%NICKNAME%用户,你好"
|
||||
},
|
||||
"image": {
|
||||
"media_id": "MEDIA_ID",
|
||||
"pic_url": "http://p.qpic.cn/pic_wework/3474110808/7a6344sdadfwehe42060/0"
|
||||
},
|
||||
"link": {
|
||||
"title": "消息标题",
|
||||
"picurl": "https://example.pic.com/path",
|
||||
"desc": "消息描述",
|
||||
"url": "https://example.link.com/path"
|
||||
},
|
||||
"miniprogram": {
|
||||
"title": "消息标题",
|
||||
"pic_media_id": "MEDIA_ID",
|
||||
"appid": "wx8bd80126147dfAAA",
|
||||
"page": "/path/index"
|
||||
},
|
||||
"file": {
|
||||
"media_id": "1Yv-zXfHjSjU-7LH-GwtYqDGS-zz6w22KmWAT5COgP7o"
|
||||
},
|
||||
"video": {
|
||||
"media_id": "MEDIA_ID"
|
||||
},
|
||||
"agentid": 1000014,
|
||||
"notify": 1
|
||||
}
|
||||
data = post(url=uri, json=请求数据示例).json()
|
||||
print(data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
wecom客户群管理().get获取客户群列表()
|
||||
wecom客户群管理().get获取客户群详情(chat_id群号ID="wrj4zANAAAmHh0Yqe23edo4TI462Bhpg")
|
||||
Reference in New Issue
Block a user