文档管理中心
我的

验证码申请

功能介绍

此接口用于用户注册、登录或者重置密码时验证码申请。

接口原型

承载协议

HTTPS POST

接口方向

应用客户端 -> 华为认证服务器

接口URL

https://connect-drcn.dbankcloud.cn/agc/apigw/oauth2/third/v1/verify-code

注意

调用获取Token接口时使用的域名必须与本接口域名保持一致,例如本接口使用“connect-drcn.dbankcloud.cn”,则调用获取Token接口必须使用“https://connect-drcn.dbankcloud.cn/agc/apigw/oauth2/v1/token”。

数据格式

请求:Content-Type: application/json

响应:Content-Type: application/json

请求参数

Query

展开

参数名称

必选(M)/可选(O)

类型

参数说明

productId

M

String

项目ID,查询方法可参见查询项目ID。

Header

展开

参数名称

必选(M)/可选(O)

类型

参数说明

client_id

M

String

客户端ID,获取方法参考获取客户端API授权。

Authorization

M

String

认证信息,格式为“Authorization: Bearer ${access_token}”。access_token为获取Token中获取的access_token。

Body

展开

参数名称

必选(M)/可选(O)

参数类型

参数说明

phone

O

String

手机号。需包含国家码,以“+”开头,国家码和手机号之间以“-”连接,例如中国大陆手机号“+86-150xxxxxxxx”。

email

O

String

电子邮箱。

电子邮箱和手机号码二者必填一个。

action

O

integer

验证码行为,取值如下:

  • 1001:注册登录时申请验证码。
  • 1002:重置密码时申请验证码。

lang

O

String

语言,格式为“zh_CN”。所有支持的语言类型请参考认证服务验证码语言类型。

sendInterval

O

integer

验证码发送间隔,30s到120s之间。

请求示例

POST /agc/apigw/oauth2/third/v1/verify-code
Content-Type: application/json
productId: 99************83
client_id: 680************560
Authorization: Bearer ***
Host: connect-drcn.dbankcloud.cn
{
	"phone": "string",
	"email": "string",
	"action": 0,
	"lang": "string",
	"sendInterval": 0
}

响应参数

展开

参数

必选(M)/可选(O)

参数类型

描述

ret

O

String(100)

包含返回码及描述信息的JSON字符串,格式为{"code":retcode, "msg": "description"},retcode为返回码,description为返回码描述信息。返回码请参见错误码。

shortestInterval

O

String

发送下一条验证码最短间隔,单位秒。

validityPeriod

O

String

验证码有效期,单位秒。

响应示例

{
	"ret": {
		"code": 0,
		"msg": "string"
	},
	"shortestInterval": "string",
	"validityPeriod": "string"
}

调用示例

Java
    /**
     * 验证码申请
     *
     * @param token access_token 认证凭据
     * @param clientId 客户端ID
     * @param productId 项目ID
     * @param action action 验证码行为
     * @param sendInterval 发送间隔30s到120s之间,短于这个间隔不发送下一条验证码
     * @param phoneOrEmail 电子邮箱,与手机号码二选一
     * @return 申请验证码结果
     */
    public static GetVerifyCodeRsp getVerifyCode(String token, String clientId, String productId, Integer action, 
        Integer sendInterval, String phoneOrEmail) throws IOException {
        GetVerifyCodeReq getVerifyCodeReq = new GetVerifyCodeReq();
        // 1001注册登录 1002重置密码
        getVerifyCodeReq.setAction(action);
        getVerifyCodeReq.setLang("zh_CN");
        getVerifyCodeReq.setSendInterval(sendInterval);
        getVerifyCodeReq.setPhone(phoneOrEmail);
        // getVerifyCodeReq.setEmail("your email");

        HttpClient client = HttpClients.createDefault();

        HttpPost httpPost = new HttpPost("https://connect-drcn.dbankcloud.cn/agc/apigw/oauth2/third/v1/verify-code?productId=" + productId);

        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-Type", "application/json;charset=utf-8");
        httpPost.setHeader("client_id", clientId);
        httpPost.setHeader("Authorization", "Bearer " + token);

        httpPost.setEntity(new StringEntity(JSON.toJSONString(getVerifyCodeReq), Charset.forName("UTF-8")));


        HttpResponse response = client.execute(httpPost);;
        return JSON.parseObject(IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8),
            GetVerifyCodeRsp.class);
    }