跳转至

代理商同步账号到云平台

1. 接口描述

接口请求路径:POST /prod-api/auth/token/syncAccount

syncAccount 用于把代理商自有平台的用户注册信息同步到云防护平台。同一 agent-code 下,usernameemailphone 不能与已有账号重复。

本接口不使用 密钥鉴权 的 Bearer Token。请在请求头携带平台分配的 agent-codeagent-api-key。服务端以请求头中的 agent-code 覆盖请求体中的 agentCode,再校验 agent-api-key。获取方式见 自有平台接入一键登录

接入流程见 自有平台接入一键登录

注意emailphone 至少填写一项。请传入真实有效的手机号,否则短信等能力可能不可用。password 须使用平台 RSA 公钥按 PKCS#1 加密,密文为 URL-Safe Base64。

平台 RSA 公钥:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC9kMNVuFE+2qnb1vXjlRmjKhd
HR0AEe3i/p0iQNwB082raTulbM2NNdlstG+otWweScbfxwdIj2zylVm31kdEt5yp
wOD4rzDq8MEK51R9wXLzPxPAbJK48occlTdfuh6hX2nK11Toe4D0GaMsE++SanE5
6/d49uXc/ZOrQeAk3QIDAQAB
-----END PUBLIC KEY-----

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。本接口请使用 agent-codeagent-api-key,不要携带 Bearer Token。

参数名称 必选 类型 描述
agent-code String Header 参数。代理商唯一码。开通时由平台分配,总后台代理商列表 AgentCode 列可查看。示例值:{agent-code}
agent-api-key String Header 参数。代理商 API 密钥。在总后台该代理商的 代理商账号 页签单击 查看 获取。示例值:{agent-api-key}
username String 用户名,长度 2~20,同一代理商下不可重复。示例值:demoUser
password String 密码密文。解密后明文长度 5~30。采用 RSA PKCS#1 加密,URL-Safe Base64。示例值:{RSA密文}
email String 邮箱,格式须合法。与 phone 至少填一项。示例值:user@example.com
phone String 手机号,最长 20 位。与 email 至少填一项。示例值:13800138000
agentCode String 请求体中的代理商编号,校验非空后会被请求头 agent-code 覆盖。示例值:{agent-code}

3. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:注册成功

4. 示例

示例1 同步新用户

输入示例

{
  "username": "demoUser",
  "password": "{RSA密文}",
  "email": "user@example.com",
  "phone": "13800138000",
  "agentCode": "{agent-code}"
}

代码调用

请将 {登录域名}{agent-code}{agent-api-key}{RSA密文} 替换为实际值。

curl -X POST 'https://{登录域名}/prod-api/auth/token/syncAccount' \
  -H 'agent-code: {agent-code}' \
  -H 'agent-api-key: {agent-api-key}' \
  -H 'Content-Type: application/json' \
  -d '{
  "username": "demoUser",
  "password": "{RSA密文}",
  "email": "user@example.com",
  "phone": "13800138000",
  "agentCode": "{agent-code}"
}'
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class SyncAccountTest {

    public static void main(String[] args) throws Exception {
        String url = "https://{登录域名}/prod-api/auth/token/syncAccount";

        String requestBody = "{"
                + "\"username\":\"demoUser\","
                + "\"password\":\"{RSA密文}\","
                + "\"email\":\"user@example.com\","
                + "\"phone\":\"13800138000\","
                + "\"agentCode\":\"{agent-code}\""
                + "}";

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpPost httpPost = new HttpPost(url);
            httpPost.setHeader("agent-code", "{agent-code}");
            httpPost.setHeader("agent-api-key", "{agent-api-key}");
            httpPost.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                int statusCode = response.getStatusLine().getStatusCode();
                String body = EntityUtils.toString(response.getEntity(), "UTF-8");
                System.out.println("Status Code: " + statusCode);
                System.out.println("Body: " + body);
            }
        }
    }
}
package main

import (
    "bytes"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://{登录域名}/prod-api/auth/token/syncAccount"

    requestBody := []byte(`{
  "username": "demoUser",
  "password": "{RSA密文}",
  "email": "user@example.com",
  "phone": "13800138000",
  "agentCode": "{agent-code}"
}`)

    req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(requestBody))
    if err != nil {
        panic(err)
    }
    req.Header.Set("agent-code", "{agent-code}")
    req.Header.Set("agent-api-key", "{agent-api-key}")
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }
    fmt.Println("Status Code:", resp.StatusCode)
    fmt.Println("Body:", string(body))
}

输出示例

{
  "code": 200,
  "msg": "注册成功"
}

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
失败,查询的代理商信息不存在 请求头 agent-code 对应的代理商不存在
agent-api-key 验证不通过 请求头 agent-api-key 与代理商档案不一致
解析失败,请确认RSA公钥是否正确 密码密文无法用平台私钥解密
用户名不能为空 未传 username
密码不能为空 未传 password
agentCode不能为空 请求体 agentCode 为空
账户长度必须在2到20个字符之间 username 长度不在允许范围
密码长度必须在5到20个字符之间 解密后的明文密码长度不在 5~30
邮箱格式不正确 email 格式不合法
注册失败,账号不能为空 emailphone 都未填写
注册失败,手机号已经注册 同一代理商下该手机号已存在
注册失败,邮箱已经注册 同一代理商下该邮箱已存在
注册失败,注册用户名[x]已存在 同一代理商下该用户名已存在,x 为请求中的用户名