From b6fdf185c7e8fb1f06da0e609e39aecaef6b66f5 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期日, 30 六月 2024 01:42:31 +0800 Subject: [PATCH] 微信强授权/后台管理 --- src/main/java/com/taoke/autopay/controller/WebApiController.java | 42 +++++++++++++++++++++++++++++++----------- 1 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/taoke/autopay/controller/WebApiController.java b/src/main/java/com/taoke/autopay/controller/WebApiController.java index 995f124..a01d79a 100644 --- a/src/main/java/com/taoke/autopay/controller/WebApiController.java +++ b/src/main/java/com/taoke/autopay/controller/WebApiController.java @@ -48,6 +48,9 @@ @ResponseBody @RequestMapping(value = "submitKey") public String submitKey(String key) { + if(1>0){ + return JsonUtil.loadFalseResult(0, "鎺ュ彛宸插叧闂�"); + } if (StringUtil.isNullOrEmpty(key)) { return JsonUtil.loadFalseResult(0, "璇蜂笂浼爇ey"); } @@ -74,6 +77,20 @@ } } + private void addKey(String key, Long wxUid) throws KeyOrderException, WxOrderCountException { + KeyOrder order = keyOrderService.addKeyOrder(key, wxUid, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd")); + Long uid = keyOrderService.getCanDistributeUid(); + if (uid != null) { + KeyOrder orderUpdate = new KeyOrder(); + orderUpdate.setId(order.getId()); + orderUpdate.setDistributeClientUid(uid); + orderUpdate.setDistributeTime(new Date()); + keyOrderService.update(orderUpdate); + } + + + } + @ResponseBody @RequestMapping(value = "submitKeyV2") public String submitKeyV2(String key, HttpSession session) { @@ -87,7 +104,10 @@ } if (user == null) { - wxLogger.info("寰俊娌℃湁鎺堟潈"); + // 鍏堜繚瀛楰EY +// SESSION_KEY_TEMP_ALIPAY_KEY + session.setAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY, key); + wxLogger.info("寰俊娌℃湁鎺堟潈:" + session.getId()); String redictLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_REDIRECT_LINK); if (StringUtil.isNullOrEmpty(redictLink)) { return JsonUtil.loadFalseResult("鏃犳硶鑾峰彇鍒版巿鏉冮摼鎺�"); @@ -97,29 +117,23 @@ root.put("link", redictLink); return JsonUtil.loadTrueResult(Constant.RESULT_CODE_NEED_LOGIN, root); } + wxLogger.info("寰俊鏈夋巿鏉�:" + session.getId()); try { - KeyOrder order = keyOrderService.addKeyOrder(key, user.getId(), TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd")); - Long uid = keyOrderService.getCanDistributeUid(); - if (uid != null) { - KeyOrder orderUpdate = new KeyOrder(); - orderUpdate.setId(order.getId()); - orderUpdate.setDistributeClientUid(uid); - orderUpdate.setDistributeTime(new Date()); - keyOrderService.update(orderUpdate); - } + addKey(key, user.getId()); return JsonUtil.loadTrueResult(""); } catch (KeyOrderException e) { e.printStackTrace(); return JsonUtil.loadFalseResult(e.getMessage()); } catch (WxOrderCountException e) { - return JsonUtil.loadFalseResult("浠婃棩瓒呰繃鏈�澶ф彁浜ゆ鏁�"); + return JsonUtil.loadFalseResult(e.getMessage()); } } @RequestMapping(value = "wxLogin") public void wxLogin(String code, String state, HttpServletResponse response, HttpSession session) throws IOException { // 鏍规嵁code鑾峰彇openid + wxLogger.info("寰俊鎺堟潈鍥炶皟锛歿} code-{}", session.getId(), code); String failLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_LOGIN_FAIL_LINK); try { WXAppInfoDto wxApp = systemConfigService.getWxAppInfoCache(); @@ -128,6 +142,12 @@ if (tokenInfo != null && !StringUtil.isNullOrEmpty(tokenInfo.getOpenid())) { WxUserInfo user = wxUserService.login(tokenInfo.getOpenid()); session.setAttribute(Constant.SESSION_KEY_USER, user); + wxLogger.info("寰俊淇濆瓨鐢ㄦ埛淇℃伅锛歿} id-{}", session.getId(), user.getId()); + String alipayKey = (String) session.getAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY); + wxLogger.info("浠巗ession璇诲彇鍒発ey锛歿}", alipayKey); + if (alipayKey != null) { + addKey(alipayKey, user.getId()); + } response.sendRedirect(successLink); return; } -- Gitblit v1.8.0