diff --git a/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java b/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java index f2ac937a3e0d1cebdfb26623c031f50ce352cbb6..6470c50d79d84549dbc6108f3f2d2be1fa293059 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java @@ -2,7 +2,8 @@ package me.zhyd.oauth.request; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; -import cn.hutool.json.JSONObject; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.model.AuthDingTalkErrorCode; @@ -12,8 +13,6 @@ import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.utils.GlobalAuthUtil; import me.zhyd.oauth.utils.UrlBuilder; -import java.util.Objects; - /** * 钉钉登录 * @@ -40,21 +39,27 @@ public class AuthDingTalkRequest extends BaseAuthRequest { // 根据timestamp, appSecret计算签名值 String stringToSign = System.currentTimeMillis() + ""; String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), stringToSign); + JSONObject param = new JSONObject(); + param.put("tmp_auth_code", code); HttpResponse response = HttpRequest.post(UrlBuilder.getDingTalkUserInfoUrl(urlEncodeSignature, stringToSign, config.getClientId())) - .body(Objects.requireNonNull(new JSONObject().put("tmp_auth_code", code))) + .body(param.toJSONString()) .execute(); String userInfo = response.body(); - JSONObject object = new JSONObject(userInfo); - AuthDingTalkErrorCode errorCode = AuthDingTalkErrorCode.getErrorCode(object.getInt("errcode")); + JSONObject object = JSON.parseObject(userInfo); + AuthDingTalkErrorCode errorCode = AuthDingTalkErrorCode.getErrorCode(object.getIntValue("errcode")); if (!AuthDingTalkErrorCode.EC0.equals(errorCode)) { throw new AuthException(errorCode.getDesc()); } object = object.getJSONObject("user_info"); + AuthToken token = AuthToken.builder() + .openId(object.getString("openid")) + .build(); return AuthUser.builder() - .uuid(object.getStr("openid")) - .nickname(object.getStr("nick")) - .username(object.getStr("nick")) + .uuid(object.getString("unionid")) + .nickname(object.getString("nick")) + .username(object.getString("nick")) .source(AuthSource.DINGTALK) + .token(token) .build(); } }