From 320e9165ac6cc6d90978fbef3074a8ed9add1790 Mon Sep 17 00:00:00 2001 From: Administrator <1101184511@qq.com> Date: 星期五, 09 五月 2025 01:21:32 +0800 Subject: [PATCH] 后台管理页面完成 --- src/main/java/com/taoke/autopay/controller/WebApiController.java | 136 ++++++++++++++++++++++++++++++--------------- 1 files changed, 90 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/taoke/autopay/controller/WebApiController.java b/src/main/java/com/taoke/autopay/controller/WebApiController.java index 2ddcd2c..c4fdc9a 100644 --- a/src/main/java/com/taoke/autopay/controller/WebApiController.java +++ b/src/main/java/com/taoke/autopay/controller/WebApiController.java @@ -6,6 +6,7 @@ import com.taoke.autopay.entity.KeyOrder; import com.taoke.autopay.entity.SystemConfigKeyEnum; import com.taoke.autopay.entity.WxUserInfo; +import com.taoke.autopay.entity.agent.ChannelAgent; import com.taoke.autopay.exception.KeyOrderException; import com.taoke.autopay.exception.KeyVerifyException; import com.taoke.autopay.exception.WxOrderCountException; @@ -13,13 +14,14 @@ import com.taoke.autopay.service.KeyOrderService; import com.taoke.autopay.service.SystemConfigService; import com.taoke.autopay.service.WxUserService; +import com.taoke.autopay.service.agent.ChannelAgentService; import com.taoke.autopay.utils.*; import com.taoke.autopay.vo.SubmitKeyInfo; import net.sf.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.util.AntPathMatcher; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.yeshi.utils.UrlUtils; @@ -29,7 +31,10 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; -import java.util.*; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Controller @RequestMapping("webapi") @@ -49,8 +54,11 @@ @Resource private SystemConfigService systemConfigService; - @Autowired + @Resource private PayCountVerifyManager payCountVerifyManager; + + @Resource + private ChannelAgentService channelAgentService; private KeyOrder addKey(SubmitKeyInfo keyInfo, Long wxUid) throws KeyVerifyException, KeyOrderException, WxOrderCountException { @@ -146,12 +154,30 @@ } keyInfo.setIpInfo(ipInfoMap.get(ip)); - String citys = systemConfigService.getValueCache(SystemConfigKeyEnum.FORBIDDEN_SUBMIT_CITYS); - if (citys != null && ipInfoMap.get(ip) != null) { - List<String> cityList = Arrays.asList(citys.split(",")); - if (cityList.contains(ipInfoMap.get(ip).getCity())) { - LogUtil.loggerDebug.warn("鍖哄煙灞忚斀锛歿}-{}", ip, new Gson().toJson(ipInfoMap.get(ip))); - return JsonUtil.loadFalseResult("鏆傛椂鏃犳硶涓婁紶鍙d护"); + AntPathMatcher pathMatcher = new AntPathMatcher(); + + Map<String, String> paramsMap = HttpUtil.getPramsFromUrl(keyInfo.getReferer()); + if (paramsMap.containsKey("a") && ipInfoMap.get(ip) != null) { + String alias = paramsMap.get("a"); + ChannelAgent agent = channelAgentService.selectByAlias(alias); + if (!StringUtil.isNullOrEmpty(agent.getShieldedAreas())) { + String[] res = agent.getShieldedAreas().split(","); + String ipInfoStr = ipInfoMap.get(ip).getProvince() + "/" + ipInfoMap.get(ip).getCity(); + boolean shield = false; + for (String pattern : res) { + if (pathMatcher.match(pattern, ipInfoStr)) { + shield = true; + break; + } + } + if (shield) { + // 鍒ゆ柇鐢ㄦ埛鏄惁涓虹櫧鍚嶅崟 + if (user.getStatus() != WxUserInfo.STATUS_WHITE) { + // 涓嶆槸鐧藉悕鍗曟墠闄愬埗 + LogUtil.loggerDebug.warn("鍖哄煙灞忚斀锛歿}-{}", ip, new Gson().toJson(ipInfoMap.get(ip))); + return JsonUtil.loadFalseResult("鏆傛椂鏃犳硶涓婁紶鍙d护"); + } + } } } @@ -214,16 +240,43 @@ } + private WxUserInfo wxLogin(String code, HttpSession session) throws Exception { + WXAppInfoDto wxApp = systemConfigService.getWxAppInfoCache(); + WxApiUtil.WXAccessTokenInfo tokenInfo = WxApiUtil.getAcessTokenInfo(code, wxApp); + if (tokenInfo != null && !StringUtil.isNullOrEmpty(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("瑙f瀽缁撴灉", new Gson().toJson(wxUserInfo)); + } catch (Exception e) { + wxLogger.error("瑙f瀽鍑洪敊", 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()); + return user; + } + throw new Exception("鑾峰彇鎺堟潈淇℃伅寮傚父"); + } + @RequestMapping(value = "wxLogin") - public void wxLogin(String code, String state, HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException { + public void wxLogin(String code, String state, HttpServletRequest request, HttpServletResponse + response, HttpSession session) throws IOException { // 鏍规嵁code鑾峰彇openid SubmitKeyInfo alipayKeyInfo = (SubmitKeyInfo) session.getAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY); - wxLogger.info("寰俊鎺堟潈鍥炶皟锛歿} code-{} referer-{}", session.getId(), code, alipayKeyInfo.getReferer()); + if (alipayKeyInfo != null) { + wxLogger.info("寰俊鎺堟潈鍥炶皟锛歿} code-{} referer-{}", session.getId(), code, alipayKeyInfo.getReferer()); + } String failLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_LOGIN_FAIL_LINK); - String referer = alipayKeyInfo.getReferer(); + String referer = alipayKeyInfo != null ? alipayKeyInfo.getReferer() : ""; try { - WXAppInfoDto wxApp = systemConfigService.getWxAppInfoCache(); String successLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_LOGIN_SUCCESS_LINK); if (!StringUtil.isNullOrEmpty(referer)) { Map<String, String> params = HttpUtil.getPramsFromUrl(referer); @@ -231,41 +284,31 @@ successLink = HttpUtil.getWholeUrl(HttpUtil.getUrlWithoutParams(referer), params); } - WxApiUtil.WXAccessTokenInfo tokenInfo = WxApiUtil.getAcessTokenInfo(code, wxApp); - if (tokenInfo != null && !StringUtil.isNullOrEmpty(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("瑙f瀽缁撴灉", new Gson().toJson(wxUserInfo)); - } catch (Exception e) { - wxLogger.error("瑙f瀽鍑洪敊", 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()); - - wxLogger.info("浠巗ession璇诲彇鍒発ey锛歿}", alipayKeyInfo); - if (alipayKeyInfo != null) { - if (!ipInfoMap.containsKey(alipayKeyInfo.getIp())) { - try { - IPUtil.IPInfo ipInfo = IPUtil.getLocalIPInfo(alipayKeyInfo.getIp()); - ipInfoMap.put(alipayKeyInfo.getIp(), ipInfo); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - addKey(alipayKeyInfo, user.getId()); - } - response.sendRedirect(successLink); + WxUserInfo user = wxLogin(code, session); + if(alipayKeyInfo==null){ + // 鏅�氱櫥褰� + wxLogger.info("鏅�氱櫥褰曟垚鍔�"); + response.sendRedirect("/credit/index.html?state=SUCCESS"); return; } - } catch (Exception e) { + + wxLogger.info("浠巗ession璇诲彇鍒発ey锛歿}", alipayKeyInfo); + if (alipayKeyInfo != null) { + if (!ipInfoMap.containsKey(alipayKeyInfo.getIp())) { + try { + IPUtil.IPInfo ipInfo = IPUtil.getLocalIPInfo(alipayKeyInfo.getIp()); + ipInfoMap.put(alipayKeyInfo.getIp(), ipInfo); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + addKey(alipayKeyInfo, user.getId()); + } + response.sendRedirect(successLink); + return; + + } catch ( + Exception e) { wxLogger.error("鎺堟潈澶辫触锛歿}", e.getMessage()); if (!StringUtil.isNullOrEmpty(referer)) { Map<String, String> params = HttpUtil.getPramsFromUrl(referer); @@ -336,4 +379,5 @@ return JsonUtil.loadTrueResult(new Gson().toJson(map)); } + } -- Gitblit v1.8.0