def send_text(self, msg=None, users=[], parties=[], tags=[]): self.json_data = requests.post( self._send_url, params={ "access_token": WeWork.get_app_token() }, # 需要设置UTF8编码 headers={ 'content-type': 'application/json; charset=utf-8' }, json={ "touser": "******".join(users), "toparty": "|".join(parties), "totag": "|".join(tags), "msgtype": "text", "agentid": WeWork.agent_id, "text": { "content": msg }, "safe": 0, "enable_id_trans": 0 }, proxies=self.proxies, verify=False).json() self.verbose(self.json_data)
def request(self, method, url, params: dict, json, data): #todo: 封装从外部读取api、或者api默认追加的一些参数 self.json_data = requests.request( method, url=url, params=params.update({"access_token": WeWork.get_app_token()})) self.verbose(self.json_data) return self.json_data
def upload_long_source(self): long_content = { "Content-Disposition": "form-data", "name": "fieldNameHere", "filename": "20180103195745.png", "Content-Type": "image/png", "Content-Length": 220 } self.json_data = requests.post(self._long_url, params={ "access_token": WeWork.get_app_token() }, json=long_content, data="file").json() self.verbose(self.json_data)
def upload_tmp_source(self, type): tmp_content = { "Content-Type": "multipart/form-data", "boundary": "-------------------------acebdf13572468", "Content-Length": 220, "Content-Disposition": "form-data", "name": "media", "filename": "wework.txt", "filelength": 6, "Content-Type": "application/octet-stream" } # self.request(post, self._tmp_url, # params={"access_token": WeWork.get_app_token()}, # json=content, data=type) self.json_data = requests.post(self._tmp_url, params={ "access_token": WeWork.get_app_token() }, json=tmp_content).json() self.verbose(self.json_data)
def send_text(self, msg=None, users=[], parties=[], tags=[]): content = { "touser": "******".join(users), "toparty": "|".join(parties), "totag": "|".join(tags), "msgtype": "text", "agentid": WeWork.agentid, "text": { "content": msg }, "safe": 0, "enable_id_trans": 0 } self.json_data = requests.post( self._send_url, params={ "access_token": WeWork.get_app_token() }, json=content, # proxies= self.proxies, verify=False).json() self.verbose(self.json_data)