
# 接收并处理5G CSP平台发送的上行消息接口
#### 接口功能
接收并处理5G CSP平台发送的上行消息。
#### 使用说明
- 前提条件 在AICC侧测正确创建5G渠道。
  
 
#### 接口鉴权
通过5G消息请求头中Authorization进行鉴权认证。
Authorization中字符串截取出appId、appSecret，从渠道配置的获取appId、appSecret，进行对比。
```
private boolean checkPostFromCsp(HttpServletRequest request, ChannelConfig channelConfig) {
        if (StringUtils.isEmpty(request.getHeader(CommonConstants.CSP_AUTHORIZATION_NAME))) {
            log.error("Authorization is null, tenantId:{}, channelId:{}", channelConfig.getTenantId(), channelConfig.getId());
            return false;
        }
        String authorization = request.getHeader(CommonConstants.CSP_AUTHORIZATION_NAME);
        String[] authorizations = authorization.split(",");
        String username = authorizations[0].substring(authorizations[0].indexOf("\"") + 1, authorizations[0].lastIndexOf("\""));
        String password = authorizations[1].substring(authorizations[1].indexOf("\"") + 1, authorizations[1].lastIndexOf("\""));
        if (!username.equals(channelConfig.getAppId()) || !password.equals(channelConfig.getAppSecret())) {
            log.error("Authorization is not match, tenantId:{}, channelId:{}", channelConfig.getTenantId(), channelConfig.getId());
            return false;
        }
        return true;
    }
```
#### 接口原型
表1接口原型说明 
|   请求方法    |                                                                                              POST                                                                                               ||
|---|---|---|
| **请求URL** | https://ip:port/social/on/5G/{channelId} | 其中，ip:port为对外暴露的nslb的ip和port， channelId为渠道id |
   
#### 请求参数
表2请求Headers参数说明 
| 参数名称          | 选取原则    | 参数类型   | 默认值 | 说明                                                                                                                          |
|:---|:---|:---|:---|:---|
| Content-Type  | 必选      | String | 无   | 固定填 application/json;charset=UTF-8。                                                                                         |
| Authorization | 必选      | String | 无   | 请求headers中鉴权参数。                                                                                                             |
| Tid           | 可选      | String | 无   | 媒体审核结果。[表3]    |
| Authstatus    | 有Tid时必选 | String | 无   | 媒体审核结果。[表3]    |
| Address       | 可选      | String | 无   | 5G消息到达时必有。[表6] |
   
 表3媒体审核结果参数说明（XML，Authstatus为0） 
| 参数名称      | 选取原则 | 参数类型      | 默认值 | 说明       |
|:---|:---|:---|:---|:---|
| file-info | 必选   | JSONArray | 无   | 多媒体文件详情。 |
   
表4file-info参数说明 
| 参数名称         | 选取原则 | 参数类型      | 默认值 | 说明                                                                                                                      |
|:---|:---|:---|:---|:---|
| type         | 必选   | String    | 无   | 多媒体文件详情。                                                                                                                |
| file-size    | 必选   | String    | 无   | 文件大小。                                                                                                                   |
| file-name    | 可选   | String    | 无   | 文件名称，type为file存在。                                                                                                       |
| content-type | 必选   | String    | 无   | 文件响应格式。                                                                                                                 |
| data         | 必选   | JSONArray | 无   | 文件详细信息。[表5] |
   
 表5data的参数说明 
| 参数名称  | 选取原则 | 参数类型   | 默认值 | 说明                  |
|:---|:---|:---|:---|:---|
| url   | 必选   | String | 无   | 多媒体文件详情。            |
| until | 可选   | String | 无   | 文件有效期，type为file时存在。 |
   
 表65G消息参数说明（XML） 
| 参数名称           | 选取原则 | 参数类型      | 默认值 | 说明    |
|:---|:---|:---|:---|:---|
| inboundMessage | 必选   | JSONArray | 无   | 消息列表。 |
   
表7inboundMessage参数说明 
| 参数名称          | 选取原则 | 参数类型       | 默认值 | 说明                        |
|:---|:---|:---|:---|:---|
| senderAddress | 必选   | String     | 无   | 消息回调地址。                   |
| sender        | 必选   | JSONObject | 无   | messaging事件 level3 sender |
   
#### 接口示例
- 请求示例
  ```
  POST /social/on/5G/{channelId} HTTP/1.1
  ****************
  Accept: */*
  Content-Type: application/xml;charset=UTF-8
  {
  "file_info": [
  "type" : "mp4",
  "file-size" :"2M",
  "file-name" : "1.mp4",
  "content-type": "",
  "data": [
  "url" : "https://www.5G/xxxx",
  "util": ""]
  ],
  "inboundMessage" : [
  "senderAddress": "",
  "sender": ""
  ]
  }
  ```
  
 
