維度表維度值添加或修改
更新時(shí)間:
身份驗(yàn)證
鑒權(quán)依據(jù)
API ID、API Secret
注:由于數(shù)據(jù)敏感,所以只在主賬號(hào)中可見(jiàn),具體展示位置為:
“管理控制臺(tái)”--〉“采集信息”
URL參數(shù)
http://{yourDomain}/api/{service}?api_id=abcdef&api_sign=abcdef&api_ts=123456
參數(shù)名 | 描述 | 備注 |
api_id | API ID | Quick Tracking后臺(tái)主賬號(hào)可查看 |
api_sign | 簽名 | 具體邏輯見(jiàn)“鑒權(quán)簽名” |
api_ts | 時(shí)間戳 | 毫秒 |
body參數(shù)
以下圖中的維度表為例:
{
"dimId": "24932301303965",
"dimensionValueParamList": [
{
"idValue": "huawei",
"level1": "華為"
"level2": "華為P60"
},
{
"idValue": "xiaomi",
"level1": "小米"
"level2": "小米10"
}
]
}
字段名稱 | 字段含義 | 是否必填 | 備注 |
dimId | 維度表id | 必填 | |
dimensionValueParamList | 需要添加后修改的緯度值 | 必填 | |
idValue | ID值 | 必填 | |
level1 | 層級(jí)1 | 必填 | 至少要有一個(gè)層級(jí) |
level2~n | 層級(jí)2~n | 非必填 |
注:
上傳的idValue已在維度表中存在,為覆蓋已經(jīng)存在的維度值;上傳的idValue不在維度表中存在,則為追加新的維度值。
目前dimId獲取方式如下
鑒權(quán)簽名
方法名 + 參數(shù)按照key進(jìn)行字母排序
/**
* Quick Tracking后臺(tái)主賬號(hào)可查看
*/
String secret = "abcdef";
/**
* 當(dāng)前要請(qǐng)求的服務(wù)名
*/
String service = "general.dimensionValue.addOrModify";
/**
* 1.獲取url參數(shù),如apiId=abcdef&sign=abcdef&ts=123456
* 2.按照key排序,移除sign,結(jié)果apiId=abcdef&ts=123456
*/
String queryString = sort("api_id=abcdef&api_ts=123456");
/**
* POST接口,body內(nèi)容
*/
String bodyString = "{
{
"dimId": "24932301303965",
"dimensionValueParamList": [
{
"idValue": "A001",
"level1": "1"
},
{
"idValue": "A002",
"level1": "2"
}
]
}";
String source = service
+ "\n"
+ queryString
+ "\n"
+ bodyString;
用API Secret對(duì)source進(jìn)行加密
String sign = new HmacUtils(HmacAlgorithms.HMAC_SHA_1, secret).hmacHex(source);
sign = 1cfc10a297397e91f1e50e1f41ac24b8c45fd53d
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.3.0</version>
</dependency>package com.alibaba.umeng.base.product.advanced.controller;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* @author mingpeng.spc
* @date 2022/01/07
*/
public class OpenApiControllerTest {
private static final MediaType APPLICATION_JSON = MediaType.parse("application/json; charset=utf-8");
private final static Logger LOGGER = LoggerFactory.getLogger(OpenApiControllerTest.class);
public static void main(String[] args) {
String url = "http://pre.aplus.emas-poc.com/api/";
String service = "general.dimensionValue.addOrModify";
String apiId = "avWYU24hvdl62V8p";
String apiSecret = "xezIgkcrtZ2yLQA4LYgBuyUo6Re2hCu8";
/**
* 構(gòu)造url參數(shù)
*/
String query = new StringBuilder()
.append("api_id=").append(apiId)
.append("&")
.append("api_ts=").append(System.currentTimeMillis())
.toString();
/**
* 構(gòu)造body參數(shù)
*/
JSONObject body = new JSONObject();
body.put("dimId", "24932301303965");
body.put("dimensionValueList", "xxx");
String bodyString = body.toJSONString();
/**
* service
* query
* body
*/
StringBuilder valueToDigest = new StringBuilder()
.append(service)
.append("\n")
.append(query)
.append("\n")
.append(bodyString);
String sign = new HmacUtils(HmacAlgorithms.HMAC_SHA_1, apiSecret).hmacHex(valueToDigest.toString());
try {
Response response = post(url + service + "?" + query + "&api_sign=" + sign, bodyString);
System.out.println(response.body().string());
} catch (Exception e) {
LOGGER.info("invoke post error", e);
}
}
/**
* HTTP Post
* @param url URL
* @param body 請(qǐng)求body
* @return
*/
private static Response post(String url, String body) throws IOException {
LOGGER.info("http post start, url = {}, body = {}", url, body);
RequestBody requestBody = RequestBody.create(APPLICATION_JSON, body);
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.build();
Response response = new OkHttpClient().newCall(request).execute();
LOGGER.info("http post success");
return response;
}
}
請(qǐng)求參數(shù)構(gòu)建
{
"dimId": "24932301303965",
"dimensionValueParamList": [
{
"idValue": "A001",
"level1": "1"
},
{
"idValue": "A002",
"level1": "2"
}
]
}
字段名稱 | 字段含義 | 是否必填 | 備注 |
dimId | 維度表id | 必填 | |
dimensionValueParamList | 需要添加后修改的緯度值 | 必填 | |
idValue | ID值 | 必填 | |
level1 | 層級(jí)1 | 必填 | 至少要有一個(gè)層級(jí) |
level2~n | 層級(jí)2~n | 非必填 |
返回結(jié)果
{
"code": 200,
"msg": "SUCCESS",
"sCode": 200,
"sMsg": "SUCCESS",
"traceId": "1ec5e2df16769551646401019d120f",
"success": true
}
文檔內(nèi)容是否對(duì)您有幫助?