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

阿里云文档:号码认证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>
相关推荐
__风__11 小时前
PostgreSQL 约束延迟触发
数据库·postgresql
月明长歌11 小时前
MySQL数据库约束:把“能插入”升级成“插入就对”
数据库·mysql·oracle
.似水11 小时前
Python Socket
开发语言·python
宁大小白11 小时前
pythonstudy Day45
开发语言·python·深度学习
·云扬·11 小时前
InnoDB Cluster 常见管理命令
数据库·mysql
筵陌11 小时前
MySQL内置函数
数据库·mysql
AI手记叨叨11 小时前
Python数学:统计运算
python·数学·统计运算·描述统计·概率运算
Brian Xia11 小时前
从0开始手写AI Agent框架:nano-agentscope(一)项目介绍
人工智能·python·ai
黎明破晓.12 小时前
MySQL基础
数据库·mysql
电商API&Tina12 小时前
【电商API接口】多电商平台数据API接入方案(附带实例)
运维·开发语言·数据库·chrome·爬虫·python·jenkins