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

作者 : admin 本文共1022个字,预计阅读时间需要3分钟 发布时间: 2024-06-9 共2人阅读

阿里云文档:号码认证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;
    }

依赖

    com.aliyun
    aliyun-java-sdk-core
    4.4.4


    com.aliyun
    aliyun-java-sdk-dypnsapi
    1.0.4
本站无任何商业行为
个人在线分享 » 阿里云一键登录号码认证服务
E-->