|
|
@@ -2,6 +2,7 @@ package com.skyversation.xjcy.oauth;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.skyversation.xjcy.util.HttpUtil;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
import lombok.Getter;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -12,11 +13,12 @@ import org.springframework.util.MultiValueMap;
|
|
|
@Service
|
|
|
public class WxAuthService {
|
|
|
@Getter
|
|
|
+ @AllArgsConstructor
|
|
|
public static class Result {
|
|
|
- private boolean success;
|
|
|
- private String error;
|
|
|
- private String wxOpenId;
|
|
|
- private String wxSessionKey;
|
|
|
+ private final boolean success;
|
|
|
+ private final String error;
|
|
|
+ private final String wxOpenId;
|
|
|
+ private final String wxSessionKey;
|
|
|
}
|
|
|
@Value("${app.wechat.secret-key}")
|
|
|
private String secretKey;
|
|
|
@@ -37,24 +39,13 @@ public class WxAuthService {
|
|
|
String sessionKey = jsonObject.getString("session_key");
|
|
|
Integer errcode = jsonObject.getInteger("errcode");
|
|
|
if (errcode == 0) {
|
|
|
- Result result = new Result();
|
|
|
- result.wxSessionKey = sessionKey;
|
|
|
- result.wxOpenId = openId;
|
|
|
- result.success = true;
|
|
|
- return result;
|
|
|
+ return new Result(true,null,openId,sessionKey);
|
|
|
}else {
|
|
|
- Result result = new Result();
|
|
|
- if (errcode ==40029){
|
|
|
- result.error = "提供的code无效";
|
|
|
- }else {
|
|
|
- result.error = "微信鉴权异常"+errcode;
|
|
|
- }
|
|
|
- return result;
|
|
|
+ return new Result(false,errcode ==40029?"提供的code无效":"微信鉴权异常"+errcode,null,null);
|
|
|
}
|
|
|
} catch (NullPointerException e) {
|
|
|
- Result result = new Result();
|
|
|
- result.error = "无法访问wx鉴权接口";
|
|
|
- return result;
|
|
|
+ return new Result(false,"无法访问wx鉴权接口",null,null);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|