| | |
| | | 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; |
| | |
| | | Logger verifyLogger = LoggerFactory.getLogger("keyVerifyLogger"); |
| | | |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private KeyOrderService keyOrderService; |
| | | |
| | |
| | | @ResponseBody |
| | | @RequestMapping(value = "submitKey") |
| | | public String submitKey(String key) { |
| | | if(1>0){ |
| | | if (1 > 0) { |
| | | return JsonUtil.loadFalseResult(0, "接口已关闭"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(key)) { |
| | |
| | | } |
| | | |
| | | private void addKey(SubmitKeyInfo keyInfo, Long wxUid) throws KeyVerifyException, KeyOrderException, WxOrderCountException { |
| | | // 解析链接 |
| | | // 解析链接 |
| | | List<String> urllist = UrlUtils.parseUrlsFromText(keyInfo.getKey()); |
| | | |
| | | |
| | | String verifyAlipayKey = systemConfigService.getValueCache(SystemConfigKeyEnum.ALIPAY_KEY_VERIFY); |
| | | if(verifyAlipayKey!=null&&verifyAlipayKey.trim().equalsIgnoreCase("1")) { |
| | | if (verifyAlipayKey != null && verifyAlipayKey.trim().equalsIgnoreCase("1")) { |
| | | try { |
| | | // 需要验证支付宝口令 |
| | | if (urllist.size() < 1) { |
| | |
| | | throw new Exception("口令内容获取失败"); |
| | | } |
| | | // 验证内容 |
| | | DYOrderDto dto = keyOrderService.verifyKey(tradeInfo.getGoodsTitle(), orderStatus, tradeInfo.getItemRealAmount()); |
| | | }catch(KeyVerifyException ee){ |
| | | DYOrderDto dto = keyOrderService.verifyKey(tradeInfo.getGoodsTitle(), orderStatus, tradeInfo.getItemRealAmount(), wxUid); |
| | | } catch (KeyVerifyException ee) { |
| | | try { |
| | | verifyLogger.warn("校验不通过:【{}】-{}", keyInfo.getKey(), ee.getMessage()); |
| | | }catch(Exception e){ |
| | | } catch (Exception e) { |
| | | } |
| | | throw ee; |
| | | } |
| | | catch(Exception e){ |
| | | throw ee; |
| | | } catch (Exception e) { |
| | | throw new KeyVerifyException(KeyVerifyException.CODE_COMMON, e.getMessage()); |
| | | } |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | private void verifySubmitKey(String key) throws Exception{ |
| | | private void verifySubmitKey(String key) throws Exception { |
| | | List<String> urllist = UrlUtils.parseUrlsFromText(key); |
| | | if (urllist.isEmpty() || !urllist.get(0).contains("ur.alipay.com")) { |
| | | throw new Exception("不包含支付宝链接"); |
| | | throw new Exception("不包含支付宝链接"); |
| | | } |
| | | if(!key.contains("支付宝")){ |
| | | if (!key.contains("支付宝")) { |
| | | throw new Exception("没包含支付宝汉字"); |
| | | } |
| | | } |
| | |
| | | if (StringUtil.isNullOrEmpty(keyInfo.getKey())) { |
| | | return JsonUtil.loadFalseResult("请上传key"); |
| | | } |
| | | try{ |
| | | try { |
| | | verifySubmitKey(keyInfo.getKey()); |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | return JsonUtil.loadFalseResult("支付宝口令不正确"); |
| | | } |
| | | |
| | |
| | | } catch (WxOrderCountException e) { |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } catch (KeyVerifyException e) { |
| | | switch (e.getCode()){ |
| | | switch (e.getCode()) { |
| | | case KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH: |
| | | return JsonUtil.loadFalseResult("该笔订单有误,不予提交"); |
| | | case KeyVerifyException.CODE_ORDER_MONEY_NOT_MATCH: |
| | |
| | | } |
| | | |
| | | /** |
| | | * @return java.lang.String |
| | | * @author hxh |
| | | * @description 带口令与金额的口令提交接口 |
| | | * @date 0:12 2024/7/9 |
| | | * @param: keyInfo |
| | | * @param: session |
| | | * @return java.lang.String |
| | | **/ |
| | | @ResponseBody |
| | | @RequestMapping(value = "submitKeyV3") |
| | | public String submitKeyV3(SubmitKeyInfo keyInfo, HttpSession session, HttpServletRequest request) { |
| | | String referer = request.getHeader("Referer"); |
| | | String referer = request.getHeader("Referer"); |
| | | keyInfo.setReferer(referer); |
| | | WxUserInfo user = (WxUserInfo) session.getAttribute(Constant.SESSION_KEY_USER); |
| | | if (StringUtil.isNullOrEmpty(keyInfo.getKey())) { |
| | | return JsonUtil.loadFalseResult( "请上传key"); |
| | | return JsonUtil.loadFalseResult("请上传key"); |
| | | } |
| | | // if (StringUtil.isNullOrEmpty(keyInfo.getMoney())) { |
| | | // return JsonUtil.loadFalseResult("请上传money"); |
| | | // } |
| | | try{ |
| | | try { |
| | | verifySubmitKey(keyInfo.getKey()); |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | return JsonUtil.loadFalseResult("支付宝口令不正确"); |
| | | } |
| | | // 验证提交时间 |
| | | String timeStr = systemConfigService.getValueCache(SystemConfigKeyEnum.KEY_SUBMIT_TIME_RANGE); |
| | | if(StringUtil.isNullOrEmpty(timeStr)){ |
| | | 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])); |
| | | 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(e.getMessage()); |
| | | } catch (KeyVerifyException e) { |
| | | logger.debug("口令校验失败:{}-{}-{}", keyInfo.getKey(), e.getCode(), e.getMessage()); |
| | | switch (e.getCode()){ |
| | | switch (e.getCode()) { |
| | | case KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH: |
| | | return JsonUtil.loadFalseResult("该笔订单有误,不予提交"); |
| | | case KeyVerifyException.CODE_ORDER_MONEY_NOT_MATCH: |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping(value = "submitKeyV3") |
| | | @RequestMapping(value = "submitKeyV4") |
| | | public String submitKeyV4(SubmitKeyInfo keyInfo, HttpSession session, HttpServletRequest request) { |
| | | String referer = request.getHeader("Referer"); |
| | | keyInfo.setReferer(referer); |
| | | WxUserInfo user = (WxUserInfo) session.getAttribute(Constant.SESSION_KEY_USER); |
| | | if (StringUtil.isNullOrEmpty(keyInfo.getKey())) { |
| | | return JsonUtil.loadFalseResult( "请上传key"); |
| | | return JsonUtil.loadFalseResult("请上传key"); |
| | | } |
| | | try{ |
| | | |
| | | try { |
| | | verifySubmitKey(keyInfo.getKey()); |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | return JsonUtil.loadFalseResult("支付宝口令不正确"); |
| | | } |
| | | // 验证提交时间 |
| | | String timeStr = systemConfigService.getValueCache(SystemConfigKeyEnum.KEY_SUBMIT_TIME_RANGE); |
| | | if(StringUtil.isNullOrEmpty(timeStr)){ |
| | | 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])); |
| | | 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 |
| | | // SESSION_KEY_TEMP_ALIPAY_KEY |
| | | session.setAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY, keyInfo); |
| | | wxLogger.info("微信没有授权:" + session.getId()); |
| | | String redictLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_REDIRECT_LINK); |
| | |
| | | return JsonUtil.loadFalseResult("无法获取到授权链接"); |
| | | } |
| | | |
| | | redictLink=redictLink.replace("",""); |
| | | redictLink = redictLink.replace("snsapi_base", "snsapi_userinfo"); |
| | | // 没有登录,返回登录链接 |
| | | JSONObject root = new JSONObject(); |
| | | root.put("link", redictLink); |
| | |
| | | } catch (WxOrderCountException e) { |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } catch (KeyVerifyException e) { |
| | | logger.debug("口令校验失败:{}-{}-{}", keyInfo.getKey(), e.getCode(), e.getMessage()); |
| | | switch (e.getCode()){ |
| | | LogUtil.loggerDebug.debug("口令校验失败:{}-{}-{}", keyInfo.getKey(), e.getCode(), e.getMessage()); |
| | | switch (e.getCode()) { |
| | | case KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH: |
| | | return JsonUtil.loadFalseResult("该笔订单有误,不予提交"); |
| | | case KeyVerifyException.CODE_ORDER_MONEY_NOT_MATCH: |
| | |
| | | try { |
| | | WXAppInfoDto wxApp = systemConfigService.getWxAppInfoCache(); |
| | | String successLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_LOGIN_SUCCESS_LINK); |
| | | if(!StringUtil.isNullOrEmpty(referer)){ |
| | | if (!StringUtil.isNullOrEmpty(referer)) { |
| | | Map<String, String> params = HttpUtil.getPramsFromUrl(referer); |
| | | params.put("state","SUCCESS"); |
| | | successLink = HttpUtil.getWholeUrl(HttpUtil.getUrlWithoutParams(referer),params); |
| | | params.put("state", "SUCCESS"); |
| | | successLink = HttpUtil.getWholeUrl(HttpUtil.getUrlWithoutParams(referer), params); |
| | | } |
| | | |
| | | 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()); |
| | | |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | wxLogger.error("授权失败:{}", e.getMessage()); |
| | | if(!StringUtil.isNullOrEmpty(referer)){ |
| | | if (!StringUtil.isNullOrEmpty(referer)) { |
| | | Map<String, String> params = HttpUtil.getPramsFromUrl(referer); |
| | | params.put("state","FAIL"); |
| | | failLink = HttpUtil.getWholeUrl(HttpUtil.getUrlWithoutParams(referer),params); |
| | | params.put("state", "FAIL"); |
| | | failLink = HttpUtil.getWholeUrl(HttpUtil.getUrlWithoutParams(referer), params); |
| | | } |
| | | } |
| | | response.sendRedirect(failLink); |