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

阿里云文档:号码认证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 小时前
SSM智慧社区信息化服务平台4v5hv(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
数据库·ssm 框架·智慧社区、·信息化平台
0思必得01 小时前
[Web自动化] Selenium处理滚动条
前端·爬虫·python·selenium·自动化
麦聪聊数据1 小时前
为何通用堡垒机无法在数据库运维中实现精准风控?
数据库·sql·安全·低代码·架构
沈浩(种子思维作者)1 小时前
系统要活起来就必须开放包容去中心化
人工智能·python·flask·量子计算
2301_790300962 小时前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
m0_736919102 小时前
用Pandas处理时间序列数据(Time Series)
jvm·数据库·python
亓才孓2 小时前
[JDBC]PreparedStatement替代Statement
java·数据库
getapi2 小时前
实时音视频传输与屏幕共享(投屏)
python
m0_466525292 小时前
绿盟科技风云卫AI安全能力平台成果重磅发布
大数据·数据库·人工智能·安全
java干货2 小时前
为什么 “File 10“ 排在 “File 2“ 前面?解决文件名排序的终极算法:自然排序
开发语言·python·算法