def sendtextmessage(self, sender_type, sender_value, recevice_type, recevice_value, content): wx_public = public_sdk.public_sdk(self._appid, self._appSercret) access_token = wx_public.getAccessToken() postdata = { "sender": { "type":sender_type, "id": sender_value }, "receiver": { "type": recevice_type, "id": recevice_value }, "msgtype": "text", "text": { "content": content } } sendmessageurl = "https://qyapi.weixin.qq.com/cgi-bin/kf/send?access_token=" + access_token data = json.dumps(postdata, ensure_ascii=False).encode('utf8') print data req = urllib2.Request(sendmessageurl, data) req.add_header("Content-Type", "application/json") response = urllib2.urlopen(req) html = response.read().decode("utf-8") tokeninfo = json.loads(html) print tokeninfo
def query_menu(self, agentid): wxsdk = public_sdk.public_sdk(self._appid, self._appsercret) accessToken = wxsdk.getAccessToken() queryMenuUrl = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?access_token=" + accessToken + "&agentid=" + agentid response = urllib2.urlopen(queryMenuUrl) html = response.read().decode("utf-8") #tokeninfo = json.loads(html,ensure_ascii=False) tokeninfo = json.loads(html) return tokeninfo
def delete_menu(self, agentid): wxsdk = public_sdk.public_sdk(self._appid, self._appsercret) accessToken = wxsdk.getAccessToken() queryMenuUrl = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?access_token=" + accessToken + "&agentid=" + agentid response = urllib2.urlopen(queryMenuUrl) html = response.read().decode("utf-8") tokeninfo = json.loads(html) if tokeninfo['errcode'] == 0: return "删除菜单成功" else: return "删除菜单失败:" + tokeninfo['errmsg']
def create_menu(self, menuData, agentid): print menuData wxsdk = public_sdk.public_sdk(self._appid, self._appsercret) accessToken = wxsdk.getAccessToken() print accessToken logging.debug("accessToken:" + accessToken) createMenuUrl = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken + "&agentid=" + agentid req = urllib2.Request(createMenuUrl, (menuData).encode("utf-8")) response = urllib2.urlopen(req) html = response.read().decode("utf-8") #import requests #res = requests.post(url=createMenuUrl, data=menuData, ) create_menu_result = json.loads(html) if create_menu_result['errcode'] == 0: return "创建菜单成功" else: return "创建菜单失败:" + str( create_menu_result['errcode']) + create_menu_result['errmsg']
def sendimagemessage(self, agentid, imageid, userlist, partylist, taglist, issafe): wx_public = public_sdk.public_sdk(self._appid, self._appSercret) access_token = wx_public.getAccessToken() postdata = { "touser": userlist, "toparty": partylist, "totag": taglist, "msgtype": "image", "agentid": agentid, "image": { "media_id": imageid }, "safe": issafe } sendmessageurl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + access_token data = json.dumps(postdata, ensure_ascii=False).encode('utf8') print data req = urllib2.Request(sendmessageurl, data) req.add_header("Content-Type", "application/json") response = urllib2.urlopen(req) html = response.read().decode("utf-8") tokeninfo = json.loads(html) print tokeninfo
def sendtextmessage(self, agentid, content, userlist, partylist, taglist, issafe): wx_public = public_sdk.public_sdk(self._appid, self._appSercret) access_token = wx_public.getAccessToken() sendtextmessage_access_token(agentid, content, userlist, partylist, taglist, issafe, access_token)