97 lines
6.2 KiB
Python
97 lines
6.2 KiB
Python
import requests
|
|||
|
|
from rest_framework import status
|
||
|
|
from rest_framework.decorators import action
|
||
|
|
from rest_framework.request import Request
|
||
|
|
from rest_framework.response import Response
|
||
|
|
from rest_framework.routers import DefaultRouter
|
||
|
|
from rest_framework.viewsets import ViewSet
|
||
|
|
|
||
|
|
from sixGuoDjango import ResData, BaseResponse
|
||
|
|
from wechat_token.token工具包 import sixToken
|
||
|
|
|
||
|
|
|
||
|
|
class 加入群聊管理ViewSets(ViewSet):
|
||
|
|
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="add_join_way")
|
||
|
|
def 配置客户群进群方式(self, request: Request):
|
||
|
|
""""""
|
||
|
|
print("配置请求进来了吗")
|
||
|
|
wecom_token = sixToken.get_wecom_token()
|
||
|
|
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/add_join_way?access_token={wecom_token}"
|
||
|
|
请求数据 = {
|
||
|
|
"scene": 2,
|
||
|
|
"remark": "测试一下", # 联系方式的备注信息,用于助记,超过30个字符将被截断
|
||
|
|
"auto_create_room": 1, # 当群满了后,是否自动新建群。0-否;1-是。 默认为1
|
||
|
|
"room_base_name": "销售客服群", # 自动建群的群名前缀,当auto_create_room为1时有效。最长40个utf8字符
|
||
|
|
"room_base_id": 10, # 自动建群的群起始序号,当auto_create_room为1时有效
|
||
|
|
"chat_id_list": [
|
||
|
|
"wrj4zANAAAHe5FbvwFBoDZ-dpQVpFf_w",
|
||
|
|
],
|
||
|
|
"state": "xiaozizi", # 企业自定义的state参数,用于区分不同的入群渠道。
|
||
|
|
# "mark_source": True, # 是否标记客户添加来源为该应用创建的「加入群聊」, 默认值为true; 仅对「营销获客」应用生效
|
||
|
|
}
|
||
|
|
data = requests.post(url=uri, json=请求数据)
|
||
|
|
print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 ", data.json())
|
||
|
|
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||
|
|
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="get_join_way")
|
||
|
|
def 获取客户群进群方式配置(self, request: Request):
|
||
|
|
""""""
|
||
|
|
self_user_unionid = request.data.get("self_user_unionid", None)
|
||
|
|
self_mini_openid = request.data.get("self_mini_openid", None)
|
||
|
|
wecom_token = sixToken.get_wecom_token()
|
||
|
|
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get_join_way?access_token={wecom_token}"
|
||
|
|
请求数据 = {
|
||
|
|
"config_id": "a4fa615e41b10db5c2b7d52cbcc6131a"
|
||
|
|
}
|
||
|
|
data = requests.post(url=uri, json=请求数据)
|
||
|
|
print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 ", data.json())
|
||
|
|
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||
|
|
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="update_join_way")
|
||
|
|
def 更新客户群进群方式配置(self, request: Request):
|
||
|
|
""""""
|
||
|
|
self_user_unionid = request.data.get("self_user_unionid", None)
|
||
|
|
self_mini_openid = request.data.get("self_mini_openid", None)
|
||
|
|
config_id = request.data.get("config_id", None) ## 企业联系方式的配置id
|
||
|
|
wecom_token = sixToken.get_wecom_token()
|
||
|
|
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/update_join_way"
|
||
|
|
json_data = {
|
||
|
|
"config_id": "9ad7fa5cdaa6511298498f979c4722de", # 企业联系方式的配置id
|
||
|
|
"scene": 2, # 场景。 1 - 群的小程序插件 2 - 群的二维码插件
|
||
|
|
"remark": "bb_remark", # 联系方式的备注信息,用于助记,超过30个字符将被截断
|
||
|
|
"auto_create_room": 1, # 当群满了后,是否自动新建群。0-否;1-是。 默认为1
|
||
|
|
"room_base_name": "销售客服群", # 自动建群的群名前缀,当auto_create_room为1时有效。最长40个utf8字符
|
||
|
|
"room_base_id": 10, # 自动建群的群起始序号,当auto_create_room为1时有效
|
||
|
|
"chat_id_list": ["wrOgQhDgAAH2Yy-CTZ6POca8mlBEdaaa", "wrOgQhDgAALPUthpRAKvl7mgiQRw_aaa"],
|
||
|
|
# 用该配置的客户群ID列表,最多支持5个。见客户群ID获取方法
|
||
|
|
"state": "klsdup3kj3s1", # 企业自定义的state参数,用于区分不同的入群渠道。
|
||
|
|
# "mark_source": True, # 是否标记客户添加来源为该应用创建的「加入群聊」, 默认值为true; 仅对「营销获客」应用生效, 且只能由创建此二维码的应用更新
|
||
|
|
}
|
||
|
|
data = requests.post(url=uri, params={"access_token": wecom_token, }, json=json_data)
|
||
|
|
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n", data.json(), "\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n")
|
||
|
|
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||
|
|
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="del_join_way")
|
||
|
|
def 删除客户群进群方式配置(self, request: Request):
|
||
|
|
""""""
|
||
|
|
self_user_unionid = request.data.get("self_user_unionid", None)
|
||
|
|
self_mini_openid = request.data.get("self_mini_openid", None)
|
||
|
|
config_id = request.data.get("config_id", None)
|
||
|
|
|
||
|
|
wecom_token = sixToken.get_wecom_token()
|
||
|
|
uri = f"https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/del_join_way?access_token={wecom_token}"
|
||
|
|
请求数据 = {
|
||
|
|
"config_id": "a4fa615e41b10db5c2b7d52cbcc6131a"
|
||
|
|
}
|
||
|
|
data = requests.post(url=uri, json=请求数据)
|
||
|
|
print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 ", data.json(), "\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n")
|
||
|
|
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||
|
|
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
|
||
|
|
加入群聊管理ViewSetsRouter = DefaultRouter()
|
||
|
|
加入群聊管理ViewSetsRouter.register(prefix="chat", viewset=加入群聊管理ViewSets, basename="")
|