跳到主要内容

快速开始

用企企 OpenAPI 按开放对象读写业务数据。本文走 v1(Open-Id)完成一次客户列表查询;细节链到对应文档,不必在本页全部展开。

默认接口域名:https://api2.77hub.com。本地化部署时以实际配置为准,见 公告

1. 选择接入方式

方式适用鉴权
v1 / Open-Id大多数对接,本文默认Header 带 Access-Key-IdOpen-Id,并做 AWS 签名;使用 Java SDK 时无需自己签名
v2 / OAuth2已有 IDPS 自建应用Header 带 Authorization(id_token / access_token)

完整流程见 接入流程

2. 获取凭证

  1. 密钥:把应用名称提供给企企管理员,线下拿到 accessKeyIdsecretAccessKey。详见 获取密钥
  2. Open-Id:用户授权一次即可,长期有效。授权带截图的步骤见 openapi 准备工作,参数说明见 获取 openid

3. 获取 SDK

对象标准接口的请求 body 固定为 {"json":"<接口参数 JSON 字符串>"}。字段与示例见 接口列表 v1数据字典

4. 第一次调用:查询客户列表

调用 POST /v1/list,查询客户,并带出客户分类的 id、名称。

将下面示例中的 your access key idyour open idaccessKeyaccessSecret 换成第 2 步拿到的值。

public class OpenapiRequestDemo {
private static Openapi client;

public static void main(String[] args) {
testList();
}

public static void testList() {
PostListRequest request = new PostListRequest();
ApiParams apiParams = new ApiParams();
apiParams.setJson("{\n" +
" \"objectType\":\"Customer\",\n" +
" \"criteriaStr\": \"id is not null\",\n" +
" \"fields\": [\n" +
" \"id\",\n" +
" \"name\",\n" +
" {\n" +
" \"fieldName\": \"category\",\n" +
" \"fields\": [\n" +
" \"id\",\n" +
" \"name\"" +
" ]\n" +
" },\n" +
" \"code\"\n" +
" ]\n" +
"}");
SdkRequestConfig build = request.sdkRequestConfig().copyBuilder()
.customHeader("Content-Type", "application/json")
.customHeader("Access-Key-Id", "your access key id")
.customHeader("Open-Id", "your open id")
.build();
request.sdkRequestConfig(build);
request.setApiParams(apiParams);
PostListResult postListResult = getClient().postList(request);
ApiResponse apiResponse = postListResult.getApiResponse();
System.out.println(apiResponse.getJson());
}

public static Openapi getClient() {
if (client == null) {
String accessKey = "accessKey";
String accessSecret = "accessSecret";
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, accessSecret);
client = Openapi.builder()
.connectionConfiguration(new ConnectionConfiguration()
.maxConnections(100)
.connectionMaxIdleMillis(1000))
.timeoutConfiguration(new TimeoutConfiguration()
.httpRequestTimeout(3000)
.totalExecutionTimeout(10000)
.socketTimeout(2000))
.iamCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}
return client;
}
}

响应示例:

{
"data": {
"list": [
{
"id": "5FRANP5010L0001",
"name": "客户A",
"category": {
"id": "X9P0AP5025L0001",
"name": "A"
},
"code": "0010000005"
},
{
"id": "7N94JP501AR0001",
"name": "客户B",
"category": {
"id": "X9P0AP5025L0001",
"name": "A"
},
"code": "0010000004"
},
{
"id": "DBP0AP5025L0001",
"name": "客户C",
"category": {
"id": "W27RAP5021A0001",
"name": "B类"
},
"code": "0010000001"
}
]
},
"errors": []
}

不使用 SDK 时,签名与裸 HTTP 示例见 接口签名

5. 下一步