Skip to content

Commit 3deb6d5

Browse files
committed
Merge branch 'develop' into feature/add-ci
2 parents dd28802 + 172e17c commit 3deb6d5

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

examples/create_signature.rs

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
extern crate line_bot_sdk_rust as line;
2+
3+
use line::webhook::validate_signature;
4+
15
use base64::encode;
26
use hmac::{Hmac, Mac};
37
use sha2::Sha256;
@@ -13,44 +17,51 @@ pub fn create_signature(channel_secret: &str, body: &str) -> String {
1317
}
1418

1519
fn main() {
20+
let channel_secret: &str = "channel_secret";
1621
let request_body: &str = r#"
17-
{
22+
{
1823
"destination": "xxxxxxxxxx",
1924
"events": [
20-
{
21-
"replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
22-
"type": "message",
23-
"mode": "active",
24-
"timestamp": 1462629479859,
25-
"source": {
26-
"type": "user",
27-
"userId": "U4af4980629..."
28-
},
29-
"message": {
30-
"id": "325708",
31-
"type": "text",
32-
"text": "@example Hello, world! (love)",
33-
"emojis": [
34-
{
35-
"index": 14,
36-
"length": 6,
37-
"productId": "5ac1bfd5040ab15980c9b435",
38-
"emojiId": "001"
25+
{
26+
"replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
27+
"type": "message",
28+
"mode": "active",
29+
"timestamp": 1462629479859,
30+
"source": {
31+
"type": "user",
32+
"userId": "U4af4980629..."
33+
},
34+
"message": {
35+
"id": "325708",
36+
"type": "text",
37+
"text": "@example Hello, world! (love)",
38+
"emojis": [
39+
{
40+
"index": 14,
41+
"length": 6,
42+
"productId": "5ac1bfd5040ab15980c9b435",
43+
"emojiId": "001"
44+
}
45+
],
46+
"mention": {
47+
"mentionees": [
48+
{
49+
"index": 0,
50+
"length": 8,
51+
"userId": "U850014438e..."
52+
}
53+
]
54+
}
3955
}
40-
],
41-
"mention": {
42-
"mentionees": [
43-
{
44-
"index": 0,
45-
"length": 8,
46-
"userId": "U850014438e..."
47-
}
48-
]
49-
}
5056
}
51-
}
5257
]
53-
}
54-
"#;
55-
println!("{}", create_signature("channel_secret", request_body));
58+
}
59+
"#;
60+
let signature: String = create_signature(channel_secret, request_body);
61+
62+
if validate_signature(channel_secret, &signature, request_body) {
63+
println!("Success: {}", signature);
64+
} else {
65+
println!("NG");
66+
}
5667
}

0 commit comments

Comments
 (0)