获取所有公众号用户的信息
程序员文章站
2022-07-12 11:20:06
...
#!/usr/bin/python
import os
import json
import requests
import sys
import string
from requests.packages.urllib3.exceptions import InsecureRequestWarning
reload(sys)
sys.setdefaultencoding('utf8')
g_getopid="https://api.weixin.qq.com/cgi-bin/user/get"
g_getopid1=g_getopid
if __name__ == '__main__':
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
num = 0
accesstoken=sys.argv[1]
next_openid=sys.argv[2]
params={}
if next_openid == "1" :
params={"access_token":accesstoken}
else:
print next_openid
params={"next_openid":next_openid,"access_token":accesstoken}
print g_getopid1
r=requests.get(g_getopid1, params=params)
print r
strResponse = r.content.decode('utf-8')
retData = json.loads(strResponse)
print retData
print "next"
print retData["next_openid"]
while retData["next_openid"] != "":
next_openid = retData["next_openid"]
lenData = len(retData["data"]["openid"])
#下面这部分,将获取到的信息一个个调用接口,保存到自己的服务
for i in range(0, lenData):
head={}
head["_version"] = "0.01"
head["_msgType"] = "request"
head["_interface"] = ""
params={}
params["openid"]= retData["data"]["openid"][i]
outData = {}
outData["_head"] = head
outData["_param"] = params
g_channelorg_url="自己的系统接口及url"
strPostData = json.dumps(outData, ensure_ascii=False)
ret=requests.post(g_channelorg_url, strPostData.encode('utf-8'), verify=False)
params={"next_openid":next_openid,"access_token":accesstoken}
print next_openid
r=requests.get(g_getopid1, params=params)
print r
strResponse = r.content.decode('utf-8')
retData = json.loads(strResponse)
print retData["next_openid"]
上一篇: DRF-Serializer反序列化
下一篇: drf 视图说明属性和方法