服务端屏蔽字接口文档
1. 背景说明
背景:网安要求,公司决定每个游戏必须对接的敏感词检测、屏蔽功能。
2. 接口说明
2.1 敏感词替换
- URL :
- Production: https://lcmx-green.mobage.cn
- Sandbox : https://lcmx-green-sand.mobage.cn
- Path: URL/text/scan3rd
- Method: POST
- Request Header:
key | value |
---|---|
signature | 参见附录 |
Accept | application/json |
Content-Type | application/json; charset = utf-8 |
- Request Body :
Name | Type | Description | Must | Signature Needed |
---|---|---|---|---|
key | String | lcm游戏标识,区分调用游戏 | Y | Y |
openId | String | 用户身份标识 | Y | Y |
eventId | Integer | 区分内容场景(1:世界聊天,2:私聊,3:昵称,4:公会名,5:群聊,6:默认) | Y | Y |
content | String | 文本内容 (长度小于100) | Y | Y |
ip | String | 客户端ip | Y | Y |
port | String | 客户端port | Y | Y |
receiveOpenId | String | eventId为2(私聊)时必传入消息接受者openId | N | Y |
room | String | eventId为5(群聊)时必传入群id | N | Y |
ext | String | 拓展字段 | N | Y |
- Response :
Name | Type | Description |
---|---|---|
code | Integer | 成功:1000,失败:1005 |
msg | String | 响应描述信息 |
data | json_object | 结果信息 |
其中data结构如下
Name | Type | Description |
---|---|---|
decision | String | 结果 'ACCEPT', 'REJECT' |
resultText | String | 屏蔽了敏感信息的结果 |
riskType | Array | 文本命中的风险类型,候选值如下:敏感词 ,广告 ,涉政 ,涉黄 ,暴恐 ,违禁 ,灌水 ,辱骂 ,其他 |
- Status Code :
Code | Description | Note |
---|---|---|
200 | OK | 请求成功 |
400 | Bad Request | 请求参数不合法 |
401 | Unauthorized | 网关验证签名失败 |
500 | Internal Server error | 服务器内部错误,可能原因有JSON解析错误等 |
- Example :
请求示例
{
"key": "13002010",
"openId": "123456",
"eventId": 1,
"content": "销售54式手枪配件",
"ip": "127.0.0.1",
"port": "3306"
}
响应示例
1. normal response
- REJECT
Http/1.1 200 Content-Type: application/json
{
"code": 1000,
"msg": "",
"data": {
"decision": "REJECT",
"resultText": "销售*****配件",
"riskType": [
"敏感词"
]
}
}
- ACCEPT
Http/1.1 200 Content-Type: application/json
{
"code": 1000,
"msg": "",
"data": {
"decision" : "ACCEPT",
"resultText": "输入的原文信息",
"riskType": null
}
}
2. common abnormal response
- 参数校验失败:
Http/1.1 400 Content-Type: application/json
{
"timestamp": "2021-06-09T10:03:28.228+00:00",
"status": 400,
"error": "Bad Request",
"message": "",
"path": "/green/text/scan3rd"
}
- 签名错误:
Http/1.1 401 Content-Type: application/json
{
"trace": null,
"code": 2002,
"catalog": 1,
"message": "签名错误",
"internalMessage": "sig: 2895bc4517da37e419804717c0ce82bd",
"status": 401
}
- 服务器错误:
Http/1.1 500 Content-Type: application/json
{
"trace": "",
"code": 1,
"catalog": 1,
"message": "服务器发生错误",
"internalMessage": "com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line 5 column 21 path $.content\ncom.google.gson.internal.Streams.parse(Streams.java:60)",
"status": 500
}
3. 附录
游戏服务端与LCMX服务端交互(GS vs LS)
接口签名验证:
- Game Server和LCMX Server之间使用MD5延签。
- LCMX系统事先线下发行consumer key和consumer secret给Game Server方,每一次Game Server通过Web API调用LCMX Server的时候,都需要在Http的header里面加入 signature 头 - 以下为 signature 头部的生成方法:
1. 以method=post,接受参数为json为例;原始body参数
{
"key": "10000000", // key -> LCM 下发的consumer key
"b":"b",
"d":["a","b","c"],
"a":"a",
"c":"c",
"g":{"g":"g","f":"f"}
}
2. 将secret添加到参数中原始body参数
{
"key": "10000000",
"b":"b",
"d":["a","b","c"],
"a":"a",
"c":"c",
"secret":"dena-dev", // secret -> LCM 下发的consumer secret
"g":{"g":"g","f":"f"}
}
3. 将参数按照key升序排序,依次将key value合并; 如果value是list或者object,则递归
sign_string = aabbccdabcgffggkey10000000secretdena-dev
4. 将得到的字符串md5
md5(sign_string) = 9d1a8070bb9735c203f5e348e4c27abf
5. 将md5串作为signature字段添加到header中