文档首页/ 云客服/ API参考/ Adapter类接口参考/ 接口说明/ 数据访问接口/ line渠道/ 接收并处理line平台发送的消息接口
更新时间:2025-11-13 GMT+08:00
分享

接收并处理line平台发送的消息接口

接口功能

接收并处理line平台发送的消息。

使用说明

  • 前提条件

    AICC测正确创建line渠道,在line开发者平台正确填写AICC测回调地址。

接口鉴权

将请求体,渠道配置里的appSecret,通过sha256算法生成认证字符串,与Line请求头x-line-signature里面字符串进行比较。

/**
     * 校验line签名信息
     *
     * @param signature line发送携带的签名信息
     * @param requestBody 请求体参数
     * @param channelSecret 加密密钥
     * @return 校验结果, true:校验通过 false:校验不通过
     */
    private boolean validateSignature(String signature, String requestBody, String channelSecret) {
        try {
            SecretKeySpec key = new SecretKeySpec(channelSecret.getBytes(StandardCharsets.UTF_8), privateKeyAlgorithm);
            Mac mac = Mac.getInstance(privateKeyAlgorithm);
            mac.init(key);
            byte[] source = requestBody.getBytes(StandardCharsets.UTF_8);
            String encodeResult = Base64.encodeBase64String(mac.doFinal(source));
            return signature.equals(encodeResult);
        } catch (Exception e) {
            log.error("line signature validate exception.", e);
            return false;
        }
    }

接口原型

表1 接口原型说明

请求方法

POST

请求URL

https://ip:port/social/on/line/{channelId}

其中,ip:port为对外暴露的nslb的ip和port,

channelId为渠道id

请求参数

表2 请求Headers参数说明

参数名称

选取原则

参数类型

默认值

说明

Content-Type

必选

String

固定填 application/json; charset=UTF-8。

X-Forwarded-For

必选

String

发送消息IP

x-line-signature

必选

String

请求头签名校验

表3 请求Body中参数说明

参数名称

选取原则

参数类型

默认值

说明

events

必选

JSONArray

events中包含事件数据表4

表4 events中参数说明

参数名称

选取原则

参数类型

默认值

说明

type

必选

String

消息类型。

mode

必选

String

active

消息模式,

source

必选

JSONObject

消息来源。表5

message

必选

JSONObject

具体消息。表6

表5 source中的参数说明

参数名称

选取原则

参数类型

默认值

说明

type

必选

String

user

消息来源。

userId

必选

String

用户ID

表6 message中的参数说明

参数名称

选取原则

参数类型

默认值

说明

id

必选

String

用户消息唯一编码。

type

必选

String

消息类型:text(文本),audio(音频),image(图片),video(视频),location(位置)

latitude

可选

BigDecimal

经度。

longitude

可选

BigDecimal

纬度。

text

可选

String

文本消息。

contentProvider

可选

JSONObject

多媒体内容提供方。表7

表7 contentProvider中的参数说明

参数名称

选取原则

参数类型

默认值

说明

type

必选

String

提供方类型

originalContentUrl

必选

String

原始多媒体url

previewImageUrl

可选

String

缩略图url

响应参数

无响应参数

接口示例

  • 请求示例
    POST 
    /********************
    Accept: */*
    Host: 10.154.198.164
    Content-Type: application/json;charset=UTF-8
    Content-Length: 185
    {
    	"events": [
    		{
    			"type": "",
    			"mode": "active",
    			"source": 
    				{"type": "user",
    				"userId": "8615897042502"	
    				},
    			"message": {
    				"id":"asdwe145FFUfj",
    				"type": "TEXT",
    				"text": "hello"
    			}
    		}
    		]
    }

相关文档