示例#1
0
 def post(self, request, *args, **kwargs):
     """
     返回指定用户openid列表的用户基本信息
     """
     data = json.loads(request.body.decode())
     print(data)
     total = data['total']
     count = data['count']
     openid_data = data['data']
     next_openid = data['next_openid']
     # print(type(openid_data))
     # print(openid_data['openid'])
     paras = []
     for openid in openid_data['openid']:
         tmp_openid = {'openid': openid}
         tmp_openid['lang'] = 'zh_CN'
         print(tmp_openid)
         paras.append(tmp_openid)
     openid_list = {'user_list': paras}
     print(openid_list)
     json_paras = json.dumps(openid_list, ensure_ascii=False)
     tg = TokenGetter()
     user_api = UserAPI(tg.get_token().access_token)
     user_list = user_api.batchget_user_info(json_data=json_paras)
     return HttpResponse(user_list, content_type='application/json')
示例#2
0
 def post(self, request, *args, **kwargs):
     """
     返回用户列表
     """
     tg = TokenGetter()
     user_api = UserAPI(tg.get_token().access_token)
     user_list = user_api.get_user_list()
     return HttpResponse(user_list, content_type='application/json')
示例#3
0
 def post(self, request, *args, **kwargs):
     """
     返回用户基本信息
     """
     data = json.loads(request.body.decode())
     # print('received openid: ', data['openid'])
     tg = TokenGetter()
     user_api = UserAPI(tg.get_token().access_token)
     user_info = user_api.get_user_info(openid=data['openid'])
     return HttpResponse(user_info, content_type='application/json')
示例#4
0
 def test_user_api(self):
     """
     """
     tg = TokenGetter(appid='wx4a32725dfd171687',
                      appsecret='14123aca2110ec62e097ab8c1cb2734d')
     token = tg.get_token()
     print('use token: ', token.access_token)
     user_api = UserAPI(token.access_token)
     r = user_api.get_user_list()
     # user_list = json.loads(r.content.decode())
     user_list = r.json()
     print(user_list)
     self.assertEqual(r.ok, True)
     self.assertEqual(r.status_code, 200)
示例#5
0
 def get(self, request, *args, **kwargs):
     """
     返回指定用户openid列表的用户基本信息
     """
     data = json.loads(request.body.decode())
     total = data['total']
     count = data['count']
     data = data['data']
     next_openid = data['next_openid']
     print(data)
     print(data['openid'])
     tg = TokenGetter()
     user_api = UserAPI(tg.get_token().access_token)
     user_list = user_api.batchget_user_info(json_data=paras)
     return HttpResponse(user_list, content_type='application/json')
示例#6
0
 def setUp(self):
     # 往测试数据库中插入数据,以便测试取用本地token是否有效
     tg = TokenGetter()
     token = tg.get_token()
     token.save()