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

阿里云文档:号码认证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>
相关推荐
2303_821287381 分钟前
怎么在MongoDB中追踪一个Document的具体流转路径_从Chunk分布到迁移历史日志分析
jvm·数据库·python
测试员周周2 分钟前
【Appium 系列】第08节-pytest 集成 — conftest.py 中的 fixture 与 hook
开发语言·人工智能·python·功能测试·appium·测试用例·pytest
SunnyDays10113 分钟前
如何使用 Python 删除 Word 文档密码和保护
python·删除 word 文档密码·移除 word 文档保护·解密 word 文档
重生之小比特5 分钟前
【MySQL 数据库】视图
数据库·mysql
weixin_459753945 分钟前
mysql如何批量重置数据库用户密码_MySQL批量修改密码Shell脚本
jvm·数据库·python
人道领域6 分钟前
【LeetCode刷题日记】递归与回溯实战 257.二叉树的所有路径——一篇文章彻底搞懂回溯
开发语言·python·算法·leetcode
AC赳赳老秦8 分钟前
OpenClaw与飞书多维表格联动:自动同步工作数据、生成统计图表,实现高效管理
java·数据库·python·信息可视化·飞书·deepseek·openclaw
黑贝是条狗10 分钟前
注册表破解chrome,edge阻止浏览器连接本地websocket
前端·javascript·数据库
sichuanwww10 分钟前
python中的websockets简单样例
python·websocket·asyncio·异步操作
爱喝水的鱼丶13 分钟前
SAP-ABAP:第二篇:实操避坑篇——ABAP Hello World程序创建、语法校验到调试运行全流程指南
运维·服务器·数据库·学习·sap·abap