def removeTag(tagid): data = {"tag": {"id": tagid}} p = json.dumps(data, ensure_ascii=False) url = "https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=%s" % AccessToken.get_access_token( ) rep = requests.post(url, p.encode('utf-8')) return json.loads(rep.text).get("errcode") == 0
def createMenu(): p = json.dumps(MENU, ensure_ascii=False) postUrl = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s' % AccessToken.get_access_token( ) rep = requests.post(postUrl, p.encode('utf-8')) if json.loads(rep.text).get("errmsg") == "ok": return True else: return False
def getUserListByTagID(tagid): data = {"tagid": tagid, "next_openid": ""} url = "https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=%s" % AccessToken.get_access_token( ) p = json.dumps(data, ensure_ascii=False) rep = requests.post(url, p.encode('utf-8')) l = json.loads(rep.text).get("data") if l == None: return [] else: return l["openid"]
def createTag(tag): """ 创建标签 接收:允许接收推送消息的用户组 :return:rep { "tag":{ "id":134,//标签id "name":"广东" } } """ data = {"tag": {"name": tag}} p = json.dumps(data, ensure_ascii=False) url = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token=%s" % AccessToken.get_access_token( ) rep = requests.post(url, p.encode('utf-8')) return json.loads(rep.text).get("tag")
def getUserTags(): """ 获取已有的全部标签及每个标签下用户数 :return:tags 数组类型 元素如下: { "id":1, "name":"每天一罐可乐星人", "count":0 //此标签下粉丝数 } """ url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token=%s" % AccessToken.get_access_token( ) rep = requests.get(url) tags = json.loads(rep.text).get("tags") return tags
def sendByTag(tagid, msg): data = { "filter": { "is_to_all": False, "tag_id": tagid }, "text": { "content": msg }, "msgtype": "text", } p = json.dumps(data, ensure_ascii=False) url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=%s" % AccessToken.get_access_token( ) rep = requests.post(url, p.encode('utf-8')) print(rep.text)
def sendAll(): data = { "filter": { "is_to_all": True, }, "text": { "content": "CONTENT1" }, "msgtype": "text", } p = json.dumps(data, ensure_ascii=False) url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=%s" % AccessToken.get_access_token( ) rep = requests.post(url, p.encode("utf-8")) if (json.loads(rep.text).get("errcode") == 0): return True else: return False
def getUserList(): url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid=%s" % ( AccessToken.get_access_token(), NULL) rep = requests.get(url) return json.loads(rep.text).get("data")["openid"]
def sendTemplateMsg(toUser="******"): msg = { "touser": toUser, "template_id": "GqFgli7w9_T-h2NKjVX18l5cZGnRiZ_RzMnCWe7lzs8", "url": URL + "/main", "data": { "first": { "value": "推荐文章:", "color": "#173177" }, "title": { "value": "【新闻聚焦】BTV新闻:积极推广防癌健康查体", "color": "#173177" } } } p = json.dumps(msg, ensure_ascii=False) # https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN postUrl = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s' % AccessToken.get_access_token( ) rep = requests.post(postUrl, p.encode('utf-8')) if json.loads(rep.text).get("errmsg") == "ok": return True else: return False
def removeUserTag(list, tagid): """ 批量为用户取消标签 post 数据示例 { "openid_list" : [//粉丝列表 "ocYxcuAEy30bX0NXmGn4ypqx3tI0", "ocYxcuBt0mRugKZ7tGAHPnUaOW7Y" ], "tagid" : 134 } :return:boolean """ data = {"openid_list": list, "tagid": tagid} p = json.dumps(data, ensure_ascii=False) url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=%s" % AccessToken.get_access_token( ) rep = requests.post(url, p.encode('utf-8')) return json.loads(rep.text).get("errcode") == 0
def getOpenid(): url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=OPENID" % AccessToken.get_access_token( ) rep = requests.get(url) return json.loads(rep.text).get("openid")
def uploadForeverMaterial(): url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=%s&type=image" % ( AccessToken.get_access_token())