阿里云一键登录号码认证服务

阿里云文档:号码认证SDK_号码认证服务(PNVS)-阿里云帮助中心

对于后端大概流程 前端App会传一个token过来 后端通过下面方法解析 如果解析可以获得号码,说明号码认证成功,如果无法正确解析则认证失败

复制代码
/**
     * actoken来换取电话号码
     * @param token app端用户授权actoken
     * @return
     */
    public static String getPhone(String token) {
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyID, accessKeySecret);//自己阿里云的配置
        IAcsClient client =new DefaultAcsClient(profile);
        GetMobileRequest request = new GetMobileRequest();
        request.setAccessToken(token);//app端传过来的,需要用户授权拿到
        request.setSysRegionId(regionId);
        String phone = null;
        try {
            GetMobileResponse response = client.getAcsResponse(request);
            if("OK".equals(response.getCode())) {
                System.out.println(response.toString());
                phone = response.getGetMobileResultDTO().getMobile();
            };
            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 phone;
    }

依赖

复制代码
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.4.4</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-dypnsapi</artifactId>
    <version>1.0.4</version>
</dependency>
相关推荐
原来是猿1 分钟前
MySQL【用户管理】
数据库·mysql
唐叔在学习10 分钟前
Python桌面端应用最小化托盘开发实践
后端·python·程序员
2501_9454235411 分钟前
使用Fabric自动化你的部署流程
jvm·数据库·python
2401_8463416513 分钟前
用Pandas处理时间序列数据(Time Series)
jvm·数据库·python
未知鱼23 分钟前
Python安全开发之子域名扫描器(含详细注释)
网络·python·安全·web安全·网络安全
2401_8318249626 分钟前
编写一个Python脚本自动下载壁纸
jvm·数据库·python
2401_8579182936 分钟前
Python在2024年的主要趋势与发展方向
jvm·数据库·python
今儿敲了吗39 分钟前
python基础学习笔记第九章——模块、包
开发语言·python
IvorySQL1 小时前
PostgreSQL 19 重磅新语法终于补齐这个缺口
数据库·postgresql·开源
二闹1 小时前
Python文件读取三巨头你该选择哪一个?
后端·python