文档中心 > 御城河

日志接入步骤

更新时间:2022/01/14 访问次数:48198

用户端日志接入(孔明锁)

参考用户端日志接入文档


后端日志API调用

建议采用异步的HTTP GET或POST(application/x-www-form-urlencoded)请求方式

设定合理的调用超时时间。如果在指定的时间内没有返回,结束HTTP请求


接入流程

获取appKey和appSecret

点击进入御城河,登陆后查看appkey 和appSecret

以解密日志接入示例,详细说明日志接入步骤

a.准备请求参数(以UTF-8格式编码)

appKey=your appKey

time=2022-01-14 10:10:10

userId=your userId

userIp=your userIp

ati=your ati

decryptTime=2022-01-14 10:10:10

logTime=2022-01-14 10:10:10

topAppKey=your topAppKey

appName"=your appName

action=your action

orderId=your orderId

topRequestId=your topRequestId

url=your url

b.针对上面准备的参数按照key进行排序(升序)然后拼接字符串

you appSecretactionyour actionappKeyyou appKeyappNameyour appNameatiyour atidecryptTime2022-01-14 10:10:10logTime2022-01-14 10:10:10orderIdyour orderIdtime2022-01-14 10:10:10topAppKeyyour topAppKeytopRequestIdyour topRequestIdurlyour urluserIdyour userIduserIpyour userIpyou appSecret

将上面字符串中的红色字体替换成自己对应的值。最前面和最后面的you appSecret替换为自己的appsecret.

c.获取拼接字符串的utf-8编码字节序列,采用md5方式加密,再把加密后的字节转化为16进制,得到sign字符串。签名算法请参考示例代码。并在请求参数中添加sign得到的请求参数中,完整的请求链接如下所示

http://gw-ose.aliyun.com/event/Decrypt?appKey=68757219&sign=328a7d9a1bce2dbdddc7962f6a4ec828&time=2022-01-14 10:10:10&userId=your userId&userIp=your userIp&ati=your ati&decryptTime=2022-01-14 10:10:10&logTime=2022-01-14 10:10:10&topAppKey=your topAppKey&appName=your appName&action=your action&orderId=your orderId&topRequestId=your topRequestId&url=your url

d.使用POST方法请求服务

POST请求的ContentType设置为:application/x-www-form-urlencoded

e.API返回值

所有API返回json字符串,表示调用成功与否,格式如下:

{

"result":"success",

"errMsg":""

}

JAVA签名获取示例

public static void main(String[] args) throws Exception {

Map<String, String> requestParameters = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);

requestParameters.put("appKey", "you appKey");

requestParameters.put("time", "2022-01-14 10:10:10");

requestParameters.put("userId", "your userId");

requestParameters.put("userIp", "your userIp");

requestParameters.put("ati", "your ati");

requestParameters.put("decryptTime", "2022-01-14 10:10:10");

requestParameters.put("logTime", "2022-01-14 10:10:10");

requestParameters.put("topAppKey", "your topAppKey");

requestParameters.put("appName", "your appName");

requestParameters.put("action", "your action");

requestParameters.put("orderId", "your orderId");

requestParameters.put("topRequestId", "your topRequestId");

requestParameters.put("url", "your url");

String appSecret = "you appSecret";

StringBuilder stringBuilder = new StringBuilder();

// 针对上面准备的参数按照key进行排序(升序)然后拼接字符串

stringBuilder.append(appSecret);

Set<Entry<String, String>> entrySet = requestParameters.entrySet();

for (Entry<String, String> entry : entrySet) {

String val = entry.getValue();

stringBuilder.append(entry.getKey() + val);

}

stringBuilder.append(appSecret);

// 获取拼接字符串的UTF-8编码字节序列

byte[] bytesOfMessage = stringBuilder.toString().getBytes("UTF-8");

// 采用MD5方式编码

MessageDigest messageDigest = MessageDigest.getInstance("MD5");

byte[] thedigest = messageDigest.digest(bytesOfMessage);

// 再把编码后的字节转化为16进制,得到sign字符串

StringBuffer stringBuffer = new StringBuffer();

for (int i = 0; i < thedigest.length; i++) {

String temp = Integer.toHexString(thedigest[i] & 0xff);

if (temp.length() == 1) {

// 得到的一位的进行补0操作

stringBuffer.append("0");

}

stringBuffer.append(temp);

}

// 计算得出sign

System.out.println(stringBuffer.toString());

}


FAQ

关于此文档暂时还没有FAQ
返回
顶部