接口调用demo 最后更新时间: 2023年06月26日
以下示例 : 表达传参方式和签名组装规则,可根据实际情况选用不同的调用方式
工作地图其他接口调用方式类似,不再一一列举
domo中使用的jar包httpclient:4.5.11 httpcore:4.4.13
示例为java语言:
public static String post(String httpUrl, List<NameValuePair> list) {
String result = "";
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
HttpPost request = new HttpPost(httpUrl);
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(list,StandardCharsets.UTF_8);
request.setEntity(formEntity);
try (CloseableHttpResponse response = httpClient.execute(request)) {
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null){
result = EntityUtils.toString(responseEntity,,StandardCharsets.UTF_8);
System.out.println("响应内容:" + result);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
1.获取帐号开放数据(手机号对应的openId)
public static void main(String[] args) {
List<NameValuePair> list = new ArrayList<NameValuePair>();
BasicNameValuePair basicNameValuePair = new BasicNameValuePair("mobile", "手机号");
BasicNameValuePair basicNameValuePair2 = new BasicNameValuePair("bizToken", "用户申请的工作地图身份token,一个企业一个token");
//签名计算规则见:https://lbs.amap.com/api/wia-openapi/guide/tools/biz-token-sign
//签名字段值,严格按照接口文档上签名字段的顺序
//接口对应有几个签名字段就填写几个对应的签名字段值
String[] argValues = {"该接口对应签名字段1的值","该接口对应签名字段2的值"};
//签名计算规则见:https://lbs.amap.com/api/wia-openapi/guide/tools/biz-token-sign (SignatureHelper见签名规则文档)
String bizSign = SignatureHelper.calcSign("高德申请企业对应的bizSecret", argValues);
BasicNameValuePair basicNameValuePair3 = new BasicNameValuePair("bizSign", bizSign);
list.add(basicNameValuePair);
list.add(basicNameValuePair2);
list.add(basicNameValuePair3);
//高德key拼在url后面
String result = post(
"https://restwia.amap.com/api/v1/wia/account/get?key=用户在高德地图官网申请Web服务API类型Key",
list);
System.out.println(result);
}
2.修改组织信息
public static void main(String[] args) {
List<NameValuePair> list = new ArrayList<NameValuePair>();
BasicNameValuePair basicNameValuePair = new BasicNameValuePair("openId", "用户在高德的身份ID(可通过获取帐号开放数据接口获取)");
BasicNameValuePair basicNameValuePair2 = new BasicNameValuePair("bizToken", "用户申请的工作地图身份token,一个企业一个token");
BasicNameValuePair basicNameValuePair3 = new BasicNameValuePair("orgName", "组织名称");
BasicNameValuePair basicNameValuePair4 = new BasicNameValuePair("orgIcon", "组织头像");
//签名计算规则见:https://lbs.amap.com/api/wia-openapi/guide/tools/biz-token-sign
//签名字段值,严格按照接口文档上签名字段的顺序
//接口对应有几个签名字段就填写几个对应的签名字段值
String[] argValues = {"该接口对应签名字段1的值","该接口对应签名字段2的值"};
//签名计算规则见:https://lbs.amap.com/api/wia-openapi/guide/tools/biz-token-sign (SignatureHelper见签名规则文档)
String bizSign = SignatureHelper.calcSign("高德申请企业对应的bizSecret", argValues);
BasicNameValuePair basicNameValuePair5 = new BasicNameValuePair("bizSign", bizSign);
list.add(basicNameValuePair);
list.add(basicNameValuePair2);
list.add(basicNameValuePair3);
list.add(basicNameValuePair4);
list.add(basicNameValuePair5);
//高德key拼在url后面
String result = post(
"https://restwia.amap.com/api/v1/wia/org/update?key=用户在高德地图官网申请Web服务API类型Key",
list);
System.out.println(result);
}
3.新建地图
public static void main(String[] args) {
List<NameValuePair> list = new ArrayList<NameValuePair>();
BasicNameValuePair basicNameValuePair = new BasicNameValuePair("openId", "用户在高德的身份ID(可通过获取帐号开放数据接口获取)");
BasicNameValuePair basicNameValuePair2 = new BasicNameValuePair("bizToken", "用户申请的工作地图身份token,一个企业一个token");
//签名计算规则见:https://lbs.amap.com/api/wia-openapi/guide/tools/biz-token-sign
//签名字段值,严格按照接口文档上签名字段的顺序
//接口对应有几个签名字段就填写几个对应的签名字段值
String[] argValues = {"该接口对应签名字段1的值","该接口对应签名字段2的值"};
//签名计算规则见:https://lbs.amap.com/api/wia-openapi/guide/tools/biz-token-sign (SignatureHelper见签名规则文档)
String bizSign = SignatureHelper.calcSign("高德申请企业对应的bizSecret", argValues);
BasicNameValuePair basicNameValuePair3 = new BasicNameValuePair("bizSign", bizSign);
BasicNameValuePair basicNameValuePair4 = new BasicNameValuePair("workMapName", "地图名称");
list.add(basicNameValuePair);
list.add(basicNameValuePair2);
list.add(basicNameValuePair3);
list.add(basicNameValuePair4);
//高德key拼在url后面
String result = post(
"https://restwia.amap.com/api/v1/wia/core/create?key=用户在高德地图官网申请Web服务API类型Key",
list);
System.out.println(result);
}
4.新建地点
public static void main(String[] args) {
List<NameValuePair> list = new ArrayList<NameValuePair>();
BasicNameValuePair basicNameValuePair = new BasicNameValuePair("openId", "用户在高德的身份ID(可通过获取帐号开放数据接口获取)");
BasicNameValuePair basicNameValuePair2 = new BasicNameValuePair("bizToken", "用户申请的工作地图身份token,一个企业一个token");
//签名计算规则见:https://lbs.amap.com/api/wia-openapi/guide/tools/biz-token-sign
//签名字段值,严格按照接口文档上签名字段的顺序
//接口对应有几个签名字段就填写几个对应的签名字段值
String[] argValues = {"该接口对应签名字段1的值","该接口对应签名字段2的值"};
//签名计算规则见:https://lbs.amap.com/api/wia-openapi/guide/tools/biz-token-sign (SignatureHelper见签名规则文档)
String bizSign = SignatureHelper.calcSign("高德申请企业对应的bizSecret", argValues);
BasicNameValuePair basicNameValuePair3 = new BasicNameValuePair("bizSign", bizSign);
//接口选填参数,可根据接口文档和自身需求填写
BasicNameValuePair basicNameValuePair4 = new BasicNameValuePair("workMapId", "新建地图接口返回的workMapId");
BasicNameValuePair basicNameValuePair5 = new BasicNameValuePair("title", "地点名称(必填)");
BasicNameValuePair basicNameValuePair6 = new BasicNameValuePair("desc", "地点描述(选填)");
BasicNameValuePair basicNameValuePair7 = new BasicNameValuePair("pointInfoStr","标准poi信息,可以从高德地理位置编码接口获取(必填)");
list.add(basicNameValuePair);
list.add(basicNameValuePair2);
list.add(basicNameValuePair3);
list.add(basicNameValuePair4);
list.add(basicNameValuePair5);
list.add(basicNameValuePair6);
list.add(basicNameValuePair7);
//高德key拼在url后面
String result = post(
"https://restwia.amap.com/api/v1/wia/point/create?key=用户在高德地图官网申请Web服务API类型Key",
list);
System.out.println(result);
}