From 525d753064b896e9e7e580faab94f872b40b09aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=87=AF?= Date: Tue, 24 Sep 2024 14:56:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=BE=AE=E4=BF=A1=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=92=8C=E6=94=AF=E4=BB=98=E5=AE=9D=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=99=BB=E5=BD=95=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/alipayUtil/AlipayUtil.java | 1 + .../controller/LoginContoller.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/alipayUtil/AlipayUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/alipayUtil/AlipayUtil.java index 2a22de2..1cf36e5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/alipayUtil/AlipayUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/alipayUtil/AlipayUtil.java @@ -80,6 +80,7 @@ public class AlipayUtil { log.error("获取支付宝用户信息失败,错误码:{},错误信息:{}", e.getErrCode(), e.getErrMsg()); throw e; } + log.info("获取支付宝用户信息成功,返回结果:{}", response.getBody()); //调用失败 if (!response.isSuccess()) { log.error("获取支付宝用户信息失败,错误码:{},错误信息:{}", response.getSubCode(), response.getSubMsg()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index b0eee31..3d9f75e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -23,7 +23,6 @@ import com.chaozhanggui.system.cashierservice.util.MD5Utils; import com.chaozhanggui.system.cashierservice.util.StringUtil; import com.chaozhanggui.system.cashierservice.util.TokenUtil; import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil; -import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -100,7 +99,6 @@ public class LoginContoller { * @return */ @RequestMapping("/auth/custom/login") - @SneakyThrows public Result authCustomLogin(HttpServletRequest request, @RequestBody Map map) { if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map) || !map.containsKey("code") || ObjectUtil.isEmpty(map.get("code"))) { Result.fail("code不能为空"); @@ -109,12 +107,17 @@ public class LoginContoller { String source = map.getOrDefault("source",AuthSource.WECHAT.getValue()); String code = map.get("code"); if(AuthSource.WECHAT.getValue().equals(source)){ - // 1.接收小程序发送的code - // 2.开发者服务器 登录凭证校验接口 appi + appsecret + code - JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, customAppId, customSecrete); - // 3.接收微信接口服务 获取返回的参数 - String openid = SessionKeyOpenId.getString("openid"); try { + // 1.接收小程序发送的code + // 2.开发者服务器 登录凭证校验接口 appi + appsecret + code + JSONObject wxResp = WechatUtil.getSessionKeyOrOpenId(code, customAppId, customSecrete); + Integer errCode = wxResp.getInteger("errcode"); + log.debug("微信获取openid响应报文:{}", wxResp.toJSONString()); + if (errCode.intValue() != 0) { + return Result.fail("登录失败:" + wxResp.getString("errmsg")); + } + // 3.接收微信接口服务 获取返回的参数 + String openid = wxResp.getString("openid"); return loginService.wxCustomLogin(openid, "", "", "", IpUtil.getIpAddr(request)); } catch (Exception e) { e.printStackTrace(); @@ -133,7 +136,6 @@ public class LoginContoller { } } return Result.fail("登录失败"); - }