43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
|
|
SERVICER_LIST_URL = "/cgi-bin/kf/servicer/list"
|
||
|
|
SERVICER_ADD_URL = "/cgi-bin/kf/servicer/add"
|
||
|
|
SERVICER_DEL_URL = "/cgi-bin/kf/servicer/del"
|
||
|
|
|
||
|
|
|
||
|
|
class WeChatKFServicerManager:
|
||
|
|
def __init__(self, gateway):
|
||
|
|
self._gateway = gateway
|
||
|
|
|
||
|
|
async def list(self, open_kfid: str) -> dict:
|
||
|
|
return await self._post(SERVICER_LIST_URL, {"open_kfid": open_kfid})
|
||
|
|
|
||
|
|
async def add(
|
||
|
|
self,
|
||
|
|
open_kfid: str,
|
||
|
|
userid_list: list[str] | None = None,
|
||
|
|
department_id_list: list[int] | None = None,
|
||
|
|
) -> dict:
|
||
|
|
payload = {"open_kfid": open_kfid}
|
||
|
|
if userid_list:
|
||
|
|
payload["userid_list"] = userid_list
|
||
|
|
if department_id_list:
|
||
|
|
payload["department_id_list"] = department_id_list
|
||
|
|
return await self._post(SERVICER_ADD_URL, payload)
|
||
|
|
|
||
|
|
async def delete(
|
||
|
|
self,
|
||
|
|
open_kfid: str,
|
||
|
|
userid_list: list[str] | None = None,
|
||
|
|
department_id_list: list[int] | None = None,
|
||
|
|
) -> dict:
|
||
|
|
payload = {"open_kfid": open_kfid}
|
||
|
|
if userid_list:
|
||
|
|
payload["userid_list"] = userid_list
|
||
|
|
if department_id_list:
|
||
|
|
payload["department_id_list"] = department_id_list
|
||
|
|
return await self._post(SERVICER_DEL_URL, payload)
|
||
|
|
|
||
|
|
async def _post(self, url: str, payload: dict) -> dict:
|
||
|
|
token = await self._gateway.get_access_token()
|
||
|
|
resp = await self._gateway._http.post(url, params={"access_token": token}, json=payload)
|
||
|
|
return resp.json()
|