|
@@ -1294,7 +1294,7 @@ class InitInfoView(View):
|
|
|
if appBundleId not in JPUSH_CONFIG.keys():
|
|
|
return response.json(904)
|
|
|
else:
|
|
|
- return response.json(444,'push_type')
|
|
|
+ return response.json(444, 'push_type')
|
|
|
uid_list = ModelService.get_uid_list(userID=userID)
|
|
|
if uid_list:
|
|
|
# 获取设备推送状态
|
|
@@ -1304,7 +1304,8 @@ class InitInfoView(View):
|
|
|
'tz': tz,
|
|
|
}
|
|
|
# 更新当前用户推送设备状态
|
|
|
- UidPushModel.objects.filter(userID_id=userID, m_code=m_code,uid_set__detect_status=1).update(**update_dict)
|
|
|
+ UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__detect_status=1).update(
|
|
|
+ **update_dict)
|
|
|
if appBundleId:
|
|
|
user_extend_qs = UserExtendModel.objects.filter(userID_id=userID)
|
|
|
if user_extend_qs.exists():
|
|
@@ -1526,3 +1527,83 @@ class wxAuthSignView(TemplateView):
|
|
|
print('---')
|
|
|
print(user_qs)
|
|
|
return self.do_login(user_qs, response)
|
|
|
+
|
|
|
+
|
|
|
+# 获取验证码
|
|
|
+class wxPerfectView(TemplateView):
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ lang = request.POST.get('lang', None)
|
|
|
+ response = ResponseObject(lang)
|
|
|
+ request_dict = request.POST
|
|
|
+ return self.ValidationError(request_dict, response)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ # Device_User.objects.filter(userEmail='chanjunkai@163.com').delete()
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ lang = request.GET.get('lang', None)
|
|
|
+ response = ResponseObject(lang)
|
|
|
+ request_dict = request.GET
|
|
|
+ # return self.do_register('157113010663213800138000', '157113010663213800138000', response, 'xx')
|
|
|
+
|
|
|
+ return self.ValidationError(request_dict, response)
|
|
|
+
|
|
|
+ def ValidationError(self, request_dict, response):
|
|
|
+ grant_code = request_dict.get('grant_code', None) # 微信授权code
|
|
|
+ appBundleID = request_dict.get('appBundleID', None) # 包名
|
|
|
+ token = request_dict.get('token', None) # 包名
|
|
|
+ if all([grant_code, appBundleID, token]):
|
|
|
+ tko = TokenObject(token)
|
|
|
+ if tko.code == 0:
|
|
|
+ userID = tko.userID
|
|
|
+ app_config = {
|
|
|
+ 'com.ansjer.zccloud': {'appid': 'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
|
+ # ios
|
|
|
+ 'com.ansjer.zccloud_ab': {'appid': 'wx2a9f5ef9baf2760f',
|
|
|
+ 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
|
+ # android
|
|
|
+ }
|
|
|
+ if appBundleID in app_config.keys():
|
|
|
+ appid = app_config[appBundleID]['appid']
|
|
|
+ secret = app_config[appBundleID]['secret']
|
|
|
+ # 获取access_token请求
|
|
|
+ at_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid={appid}&secret={secret}&code={code}&grant_type=authorization_code'.format(
|
|
|
+ appid=appid, secret=secret, code=grant_code)
|
|
|
+ res_req = requests.get(url=at_url)
|
|
|
+ res_json = res_req.json()
|
|
|
+ print(res_json)
|
|
|
+ if 'access_token' not in res_json.keys():
|
|
|
+ # 授权过期
|
|
|
+ return response.json(717)
|
|
|
+ access_token = res_json['access_token']
|
|
|
+ openid = res_json['openid']
|
|
|
+ if access_token and openid:
|
|
|
+ user_extend_qs = UserExtendModel.objects. \
|
|
|
+ filter(userID_id=userID, authType=1, appBundleId=appBundleID)
|
|
|
+ if user_extend_qs.exists():
|
|
|
+ # 如果用户绑定过则直接登录
|
|
|
+ user_extend_qs.update(authOpenID=openid)
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ try:
|
|
|
+ nowTime = int(time.time())
|
|
|
+ UserExtendModel.objects.create(
|
|
|
+ addTime=nowTime,
|
|
|
+ updTime=nowTime,
|
|
|
+ appBundleId=appBundleID,
|
|
|
+ userID_id=userID,
|
|
|
+ authType=1,
|
|
|
+ authOpenID=openid)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(424, repr(e))
|
|
|
+ else:
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(414, 'access_token,openid')
|
|
|
+ else:
|
|
|
+ return response.json(414, 'appBundleID is wrong!')
|
|
|
+ else:
|
|
|
+ return response.json(tko.code)
|
|
|
+ else:
|
|
|
+ return response.json(414)
|