Receiving and Processing Messages Sent on LINE
Function
This interface is invoked to receive and process messages sent on LINE.
Usage Description
Interface Authentication
Use the SHA256 algorithm to generate an authentication character string based on the request body and the value of appSecret in the channel configuration, and compare the character string with that in the LINE request header x-line-signature.
/**
* Verify the LINE signature information.
*
* @param signature Signature information carried in the message sent on LINE.
* @param requestBody Request body parameters.
* @param channelSecret Encrypted key.
* @return Verification result. The value true indicates that the verification is successful, and the value false indicates that the verification fails.
*/
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;
}
}
Interface Prototype
|
Method |
POST |
|
|---|---|---|
|
URL |
https://{IP address}:{Port number}/social/on/line/{channelId} |
{IP address}:{Port number} indicates the IP address and port number of the NSLB exposed externally. {channelId} indicates the channel ID. |
Request Parameters
|
Parameter |
Mandatory or Not |
Type |
Default Value |
Description |
|---|---|---|---|---|
|
Content-Type |
Yes |
String |
None |
The value is fixed at application/json; charset=UTF-8. |
|
X-Forwarded-For |
Yes |
String |
None |
IP address for sending messages. |
|
x-line-signature |
Yes |
String |
None |
Request header signature verification. |
|
Parameter |
Mandatory or Not |
Type |
Default Value |
Description |
|---|---|---|---|---|
|
events |
Yes |
JSON array |
None |
Event data in events. For details, see Table 4. |
|
Parameter |
Mandatory or Not |
Type |
Default Value |
Description |
|---|---|---|---|---|
|
type |
Yes |
String |
None |
Message type. |
|
mode |
Yes |
String |
active |
Message mode. |
|
source |
Yes |
JSON object |
None |
Message source. For details, see Table 5. |
|
message |
Yes |
JSON object |
None |
Specific message. For details, see Table 6. |
|
Parameter |
Mandatory or Not |
Type |
Default Value |
Description |
|---|---|---|---|---|
|
type |
Yes |
String |
user |
Message source. |
|
userId |
Yes |
String |
None |
User ID. |
|
Parameter |
Mandatory or Not |
Type |
Default Value |
Description |
|---|---|---|---|---|
|
id |
Yes |
String |
None |
Unique code of a user message. |
|
type |
Yes |
String |
None |
Message type. The value can be text, audio, image, video, or location. |
|
latitude |
No |
BigDecimal |
None |
Longitude. |
|
longitude |
No |
BigDecimal |
None |
Latitude. |
|
text |
No |
String |
None |
Text message. |
|
contentProvider |
No |
JSON object |
None |
Multimedia content provider. For details, see Table 7. |
Response Parameters
None
Example
- Request
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" } } ] }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot