admin
2021-11-19 4daec329f36cc9d86911c08b8ec8e00270792189
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.ks.app.utils;
 
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dypnsapi.model.v20170525.GetMobileRequest;
import com.aliyuncs.dypnsapi.model.v20170525.GetMobileResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import org.yeshi.utils.StringUtil;
 
/**
 * @author hxh
 * @title: AliyunOneKeyLoginUtil
 * @description: 阿里云一键登录
 * @date 2021/11/15 11:03
 */
public class AliyunOneKeyLoginUtil {
 
    private final static String ACCESS_KEY = "LTAI4FwmTxVCuzTaoZtDiV8z";
    private final static String ACESS_SCRET = "ixWg90QbYFKP6ae5xpAo2P1qwIyll5";
 
    public static String getMobile(String accessToken, String outId,String acessKey,String acessSecret) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", acessKey, acessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
 
        GetMobileRequest request = new GetMobileRequest();
        request.setAccessToken(accessToken);
        if (!StringUtil.isNullOrEmpty(outId))
            request.setOutId(outId);
 
        try {
            GetMobileResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
            if (response.getGetMobileResultDTO() != null) {
                String mobile = response.getGetMobileResultDTO().getMobile();
                return mobile;
            }
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
        return null;
    }
 
}