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

阿里云文档:号码认证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. 阿里登录号码认证服务

    2024-06-08 18:38:04       21 阅读
  2. 通过idea插件将jar包发布到阿里服务器部署

    2024-06-08 18:38:04       16 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-08 18:38:04       5 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-08 18:38:04       5 阅读
  3. 在Django里面运行非项目文件

    2024-06-08 18:38:04       4 阅读
  4. Python语言-面向对象

    2024-06-08 18:38:04       7 阅读

热门阅读

  1. pytorch里面封装好的函数,如果要修改怎么办

    2024-06-08 18:38:04       24 阅读
  2. C语言——第五章习题

    2024-06-08 18:38:04       14 阅读
  3. 动手学深度学习——tensor

    2024-06-08 18:38:04       18 阅读
  4. MySQL 运算符以及优先级

    2024-06-08 18:38:04       21 阅读
  5. MATLAB 函数 function

    2024-06-08 18:38:04       18 阅读
  6. 源码编译OpenCV 启用cuda 加速

    2024-06-08 18:38:04       21 阅读
  7. 【Qt】Qt中的几种Timer

    2024-06-08 18:38:04       13 阅读
  8. 8*8LED点阵点亮一个点

    2024-06-08 18:38:04       17 阅读
  9. 系统安全及应用

    2024-06-08 18:38:04       15 阅读
  10. qt c++类继承QWidget和不继承有什么区别

    2024-06-08 18:38:04       21 阅读
  11. 常用sql

    2024-06-08 18:38:04       16 阅读
  12. QTGUI编程入门:解锁图形用户界面设计的奥秘

    2024-06-08 18:38:04       15 阅读