提交 43866062 编写于 作者: S skqing
上级 937fba37
......@@ -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,20 +39,22 @@ 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");
return AuthUser.builder()
.uuid(object.getStr("openid"))
.nickname(object.getStr("nick"))
.username(object.getStr("nick"))
.uuid(object.getString("openid"))
.nickname(object.getString("nick"))
.username(object.getString("nick"))
.source(AuthSource.DINGTALK)
.build();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册