Log In

使用帐号密码登录 Application Portal。

请求格式

POST https://{apigw-address}/app-portal-service/v2.2/login

请求参数(Body)

名称 必需/可选 数据类型 描述
account 必需 String 用户名。
password 必需 String 登录密码。

响应参数

名称 数据类型 描述
data List<JSONObject> 用户信息。详见 用户信息结构体

用户信息结构体

名称 数据类型 描述
organizations List<JSONObject> 用户所在的组织列表,包含组织名称和ID。详见 IdNamePair结构体
user List<JSONObject> 用户信息,包含用户名称和ID。详见 IdNamePair结构体
accessToken String Access Token,以Bearer Token表示。

IdNamePair结构体

名称 数据类型 描述
id String 用户ID或组织ID。
name String 用户名称或组织名称。

错误码

代码 错误信息 描述
31400 The user name or password is wrong 用户账号密码不能为空或者填写错误
31429   密码或IP错误次数过多,请稍后重试

示例

请求示例

url: https://{apigw-address}/app-portal-service/v2.2/login

method: POST

requestBody:

{"account":"portal_demo","password":"Test1234"}

返回示例

{
  "code": 0,
  "data": {
    "accessToken": "APP_PORTAL_S_WX89rC4pqsMc478tyP6gb9zFmT9qYaW7",
    "organizations": [
      {
        "id": "yourOrgId_1",
        "name": "Portal Demo"
      },
      {
        "id": "yourOrgId_2",
        "name": "rm_0726_001"
      }
    ],
    "user": {
      "id": "yourUserId",
      "name": "portal_demo"
    }
  },
  "message": "OK"
}

Java SDK 调用示例

public class AppPortalSdkTest{
    @Test
    public void loginTest() {
        LoginRequest loginRequest = new LoginRequest("your_user_name", "your_password");
        loginResponse = Poseidon.config(PConfig.init().appKey("your_access_key").appSecret("your_secret_key").debug())
                .url("https://{apigw-address}").getResponse(loginRequest, LoginResponse.class);
        System.out.println("Login res: " + JSON.toJSONString(loginResponse));

        assertNotNull("Response should not be null", loginResponse);
        assertNotNull("Response data should not be null", loginResponse.data);

        assertNotNull("Access token should not be null", loginResponse.data.accessToken);
        assertNotNull("User object should not be null", loginResponse.data.user);
        assertNotNull("Organizations should not be null", loginResponse.data.organizations);
        assertThat("Organizations should not be empty", loginResponse.data.organizations, not(IsEmptyCollection.empty()));
        assertThat("First organization should not be null", loginResponse.data.organizations.get(0), notNullValue());
    }
}