本机号码一键登录

本机号码一键登录

1、背景

用户名密码方式的登录与注册繁琐,耗时长,用户体验差。

号码认证服务

https://www.aliyun.com/product/dypns?spm=5176.19720258.J_3207526240.79.e93976f4did2vi

2、原理

在这里插入图片描述

3、服务器

(1)前提条件

这里用阿里云作为第三方整合运营商的厂商

必须配置对应的accessKey ID和accessKey Secret

(2)流程

服务器需要拿到app从运营商获取到的认证token,请求运营商获取到手机号,并通过手机号进行注册登录,并返回登录相关信息。

流程:本机号码一键登录在服务端的业务流程图
本机号码一键登录在服务端的业务流程图
本机号码一键登录在服务端的业务流程图:
在这里插入图片描述

(3)代码示例

  • 添加依赖
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>dypnsapi20170525</artifactId>
  <version>1.0.6</version>
</dependency>
  • 获取本机号码代码示例
package com.aliyun.sample;
 
import com.aliyun.tea.*;
 
public class Sample {
 
    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dypnsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dypnsapi.aliyuncs.com";
        return new com.aliyun.dypnsapi20170525.Client(config);
    }
 
    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dypnsapi20170525.Client client = Sample.createClient("accessKeyId", "accessKeySecret");
        com.aliyun.dypnsapi20170525.models.GetMobileRequest getMobileRequest = new com.aliyun.dypnsapi20170525.models.GetMobileRequest();
        //app端请求的认证token(accessToken)
        getMobileRequest.setAccessToken("accessToken");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            client.getMobileWithOptions(getMobileRequest, runtime);
        } catch (TeaException error) {
            // 如有需要,请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要,请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }       
    }
}
  • 响应示例
{
  "Code": "OK",
  "Message": "请求成功",
  "RequestId": "8906582E-6722",
  "GetMobileResultDTO": {
    "Mobile": "13900001234"
  }
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值