需要获取三个参数
appid,appSecret和回调域名
在自己服务中
直接调用render接口就行
@RestController
@RequestMapping("/oauth")
public class DingDingLoginController {
@RequestMapping("/render")
public void renderAuth(HttpServletResponse response) throws IOException {
AuthRequest authRequest = getAuthRequest();
response.sendRedirect(authRequest.authorize(AuthStateUtils.createState()));//会显示登录的二维码
}
@RequestMapping("/callback")
public Object login(AuthCallback callback) {
AuthRequest authRequest = getAuthRequest();
return authRequest.login(callback);
}
private AuthRequest getAuthRequest() {
return new AuthDingTalkRequest(AuthConfig.builder()
.clientId("dingoarg8xwz0o2iurhmsz")
.clientSecret("hSlZNiq3jIEnwsMuWwsTdymUruPgc_cjXjMB4lERAAHTnz1Lh257kdu38yIJmmyE")
.redirectUri("http://localhost:20021/oauth/callback")
.build());
}
}
返回值是
{
"code": 2000,
"msg": null,
"data": {
"uuid": "ebxJIZiPqeiPoeINHnTH2bRwiEiE",
"username": "王xx",
"nickname": "王xx",
"avatar": null,
"blog": null,
"company": null,
"location": null,
"email": null,
"remark": null,
"gender": "UNKNOWN",
"source": "DINGTALK",
"token": {
"accessToken": null,
"expireIn": 0,
"refreshToken": null,
"refreshTokenExpireIn": 0,
"uid": null,
"openId": "WS6t4WUY1b79TFUVKlUc5QiEiE",
"accessCode": null,
"unionId": "ebxJIZiPqeiPoeINHnTH2bRwiEiE",
"scope": null,
"tokenType": null,
"idToken": null,
"macAlgorithm": null,
"macKey": null,
"code": null,
"oauthToken": null,
"oauthTokenSecret": null,
"userId": null,
"screenName": null,
"oauthCallbackConfirmed": null
},
"rawUserInfo": {
"nick": "王xx",
"unionid": "ebxJIZiPqeiPoeINHnTH2bRwiEiE",
"dingId": "$:LWCP_v1:$6h5ewoOME66PPLzmNpXts3/PN/1BM5nG",
"openid": "WS6t4WUY1b79TFUVKlUc5QiEiE",
"main_org_auth_high_level": true
}
}
}