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

阿里云文档:号码认证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>
相关推荐
为思念酝酿的痛5 分钟前
MySQL数据类型
数据库·mysql
benchmark_cc26 分钟前
QuantDash 安装成功后,如何验证 Python 环境可以正常导入 SDK?
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
泡海椒1 小时前
JQuick-SQL 与关系型数据库集成:应用层读取后注册查询
数据库·sql
Carol06301 小时前
上肢及肩肘关节
java·服务器·数据库
鸽芷咕1 小时前
数据孤岛怎么拆?金仓KFS数据集成软件从原理到落地
数据库
一世繁华行1 小时前
CAPL浏览器(翻译自官方文档)
运维·服务器·数据库
zh路西法1 小时前
【模型式强化学习】(二)PETS——从概率动力学模型到模型预测控制(MPC)
pytorch·python·强化学习·pe·mpc·ces·pets
得助智能-垂类大模型1 小时前
多Agent平台哪家做得好?2026年企业级多智能体平台选型指南
大数据·数据库
为思念酝酿的痛2 小时前
MySQL数据库基础
数据库·mysql
瀚高PG实验室2 小时前
数据库使用psql及jdbc进行远程连接,不定时自动断开的解决办法
数据库·postgresql·瀚高数据库