| | |
| | | package com.taoke.autopay.controller; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.taoke.autopay.dto.DYOrderDto; |
| | | import com.taoke.autopay.dto.WXAppInfoDto; |
| | | import com.taoke.autopay.entity.KeyOrder; |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping(value = "submitKeyV3") |
| | | @RequestMapping(value = "submitKeyV4") |
| | | public String submitKeyV4(SubmitKeyInfo keyInfo, HttpSession session, HttpServletRequest request) { |
| | | String referer = request.getHeader("Referer"); |
| | | keyInfo.setReferer(referer); |
| | |
| | | if (StringUtil.isNullOrEmpty(keyInfo.getKey())) { |
| | | return JsonUtil.loadFalseResult( "请上传key"); |
| | | } |
| | | try{ |
| | | verifySubmitKey(keyInfo.getKey()); |
| | | }catch (Exception e){ |
| | | return JsonUtil.loadFalseResult("支付宝口令不正确"); |
| | | } |
| | | // 验证提交时间 |
| | | String timeStr = systemConfigService.getValueCache(SystemConfigKeyEnum.KEY_SUBMIT_TIME_RANGE); |
| | | if(StringUtil.isNullOrEmpty(timeStr)){ |
| | | return JsonUtil.loadFalseResult("尚未配置生效时间"); |
| | | } |
| | | String startTime = timeStr.split(",")[0].trim().replace(":",""); |
| | | String endTime = timeStr.split(",")[1].trim().replace(":",""); |
| | | String now = TimeUtil.getGernalTime(System.currentTimeMillis(),"HHmmss"); |
| | | if(Integer.parseInt(now)<Integer.parseInt(startTime)||Integer.parseInt(now)>Integer.parseInt(endTime)){ |
| | | return JsonUtil.loadFalseResult(String.format("口令提交时间段为:%s-%s",timeStr.split(",")[0],timeStr.split(",")[1])); |
| | | if(1<0) { |
| | | try { |
| | | verifySubmitKey(keyInfo.getKey()); |
| | | } catch (Exception e) { |
| | | return JsonUtil.loadFalseResult("支付宝口令不正确"); |
| | | } |
| | | // 验证提交时间 |
| | | String timeStr = systemConfigService.getValueCache(SystemConfigKeyEnum.KEY_SUBMIT_TIME_RANGE); |
| | | if (StringUtil.isNullOrEmpty(timeStr)) { |
| | | return JsonUtil.loadFalseResult("尚未配置生效时间"); |
| | | } |
| | | String startTime = timeStr.split(",")[0].trim().replace(":", ""); |
| | | String endTime = timeStr.split(",")[1].trim().replace(":", ""); |
| | | String now = TimeUtil.getGernalTime(System.currentTimeMillis(), "HHmmss"); |
| | | if (Integer.parseInt(now) < Integer.parseInt(startTime) || Integer.parseInt(now) > Integer.parseInt(endTime)) { |
| | | return JsonUtil.loadFalseResult(String.format("口令提交时间段为:%s-%s", timeStr.split(",")[0], timeStr.split(",")[1])); |
| | | } |
| | | } |
| | | if (user == null) { |
| | | // 先保存KEY |
| | |
| | | return JsonUtil.loadFalseResult("无法获取到授权链接"); |
| | | } |
| | | |
| | | redictLink=redictLink.replace("",""); |
| | | redictLink=redictLink.replace("snsapi_base","snsapi_userinfo"); |
| | | // 没有登录,返回登录链接 |
| | | JSONObject root = new JSONObject(); |
| | | root.put("link", redictLink); |
| | |
| | | |
| | | WxApiUtil.WXAccessTokenInfo tokenInfo = WxApiUtil.getAcessTokenInfo(code, wxApp); |
| | | if (tokenInfo != null && !StringUtil.isNullOrEmpty(tokenInfo.getOpenid())) { |
| | | WxUserInfo user = wxUserService.login(tokenInfo.getOpenid()); |
| | | WxApiUtil.WXUserInfo wxUserInfo =null; |
| | | if(tokenInfo.getScope()!=null&&tokenInfo.getScope().contains("snsapi_userinfo")){ |
| | | try { |
| | | wxUserInfo = WxApiUtil.getUserInfo(tokenInfo.getAccess_token(), tokenInfo.getOpenid()); |
| | | wxLogger.info("解析结果",new Gson().toJson(wxUserInfo)); |
| | | }catch(Exception e){ |
| | | wxLogger.error("解析出错",e); |
| | | } |
| | | } |
| | | if(wxUserInfo==null){ |
| | | wxUserInfo=new WxApiUtil.WXUserInfo(); |
| | | wxUserInfo.setOpenid(tokenInfo.getOpenid()); |
| | | } |
| | | WxUserInfo user = wxUserService.login(wxUserInfo); |
| | | session.setAttribute(Constant.SESSION_KEY_USER, user); |
| | | wxLogger.info("微信保存用户信息:{} id-{}", session.getId(), user.getId()); |
| | | |