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("登录失败"); - }