https:
https:
https:
http:
https:
http:
https:
https:
https:
https:
https:
Messaging API
Login
with
Line Account
พบ Welcome to the LINE Developers console.
Enter your information and select Create my account.
You can still change your developer information later.
> Create my account (thaiall)
> Create a
new
Provider (thaialldotcom)
> Create a Messanging API Channel
- Channel type = Messanging API
- Provider = thaialldotcom
- Channel icon = rspthaiall.png
- Channel name = thaiallbot
- Category = การศึกษา
- Email address = burin_ruj@mysite.com
ใน Messaging API settings ของ Channel
พบ QR Code และ Bot basic ID = @xxxxxx
Available APIs
- REPLY_MESSAGE
- PUSH_MESSAGE
Webhook settings
Webhook URL = https:
Webhook URL = http:
https:
https:
http:
heroku login
git clone https:
cd xxx
git add .
git commit -m
"hello"
git push origin master
http:
<?php
$myid =
""
;
$groupid =
""
;
$accessToken =
"xxxxxxxxxxxx"
;
$arrayJson = json_decode($content,
true
);
$arrayHeader = array();
$arrayHeader[] =
"Content-Type: application/json"
;
$arrayHeader[] =
"Authorization: Bearer {$accessToken}"
;
$message = $arrayJson[
'events'
][0][
'message'
][
'text'
];
$grouptype =
""
; $roomtype =
""
; $usertype =
""
; $room =
""
; $group =
""
;
if
(isset($arrayJson[
'events'
][0][
'source'
][
'groupId'
])){
$id = $arrayJson[
'events'
][0][
'source'
][
'groupId'
];
$group = $arrayJson[
'events'
][0][
'source'
][
'groupId'
];
$grouptype =
"group"
;
}
if
(isset($arrayJson[
'events'
][0][
'source'
][
'room'
])){
$id = $arrayJson[
'events'
][0][
'source'
][
'room'
];
$room = $arrayJson[
'events'
][0][
'source'
][
'room'
];
$roomtype =
"room"
;
}
if
(isset($arrayJson[
'events'
][0][
'source'
][
'userId'
])){
$id = $arrayJson[
'events'
][0][
'source'
][
'userId'
];
$usertype =
"user"
;
}
if
(isset($_GET[
"time"
]) && $_GET[
"time"
] ==
"now"
) $id = $myid;
if
($message ==
"สวัสดี"
|| strtolower($message) ==
"hello"
|| $message ==
"hi"
){
$arrayPostData[
'replyToken'
] = $arrayJson[
'events'
][0][
'replyToken'
];
$arrayPostData[
'messages'
][0][
'type'
] =
"text"
;
$arrayPostData[
'messages'
][0][
'text'
] =
"สวัสดีครับ สบายดีรึเปล่า"
;
replyMsg($arrayHeader,$arrayPostData);
}
else
if
($message ==
"สวัสดีครับ"
){
$arrayPostData[
'replyToken'
] = $arrayJson[
'events'
][0][
'replyToken'
];
$arrayPostData[
'messages'
][0][
'type'
] =
"text"
;
$arrayPostData[
'messages'
][0][
'text'
] =
"ยินดีต้อนรับ มีอะไรคุยกันได้นะ"
;
replyMsg($arrayHeader,$arrayPostData);
}
else
if
(strtolower($message) ==
"id"
|| strtolower($message) ==
"userid"
){
$arrayPostData[
'replyToken'
] = $arrayJson[
'events'
][0][
'replyToken'
];
$arrayPostData[
'messages'
][0][
'type'
] =
"text"
;
$arrayPostData[
'messages'
][0][
'text'
] =
"userId = $id"
;
replyMsg($arrayHeader,$arrayPostData);
}
if
(strlen($id) > 1 &&
false
) {
$arrayPostData[
'to'
] = $id;
$arrayPostData[
'messages'
][0][
'type'
] =
"sticker"
;
$arrayPostData[
'messages'
][0][
'packageId'
] = 11537;
$arrayPostData[
'messages'
][0][
'stickerId'
] = 52002740;
pushMsg($arrayHeader,$arrayPostData);
}
if
(strlen($myid) > 0) {
$arrayPostData[
'to'
] = $myid;
$arrayPostData[
'messages'
][0][
'type'
] =
"text"
;
$data =
"$usertype : $id "
;
if
(strlen($room) > 0) $data .=
"$roomtype : $room "
;
if
(strlen($group) > 0) $data .=
"$grouptype : $group "
;
$arrayPostData[
'messages'
][0][
'text'
] = $data;
pushMsg($arrayHeader,$arrayPostData);
}
if
(strlen($groupid) > 0 && $message ==
"boy"
) {
$arrayPostData[
'to'
] = $groupid;
$arrayPostData[
'messages'
][0][
'type'
] =
"sticker"
;
$arrayPostData[
'messages'
][0][
'packageId'
] = 11537;
$arrayPostData[
'messages'
][0][
'stickerId'
] = 52002739;
pushMsg($arrayHeader,$arrayPostData);
}
function
replyMsg($arrayHeader,$arrayPostData){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$strUrl);
curl_setopt($ch, CURLOPT_HEADER,
false
);
curl_setopt($ch, CURLOPT_POST,
true
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $arrayHeader);
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($arrayPostData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false
);
$result = curl_exec($ch);
curl_close ($ch);
}
function
pushMsg($arrayHeader,$arrayPostData){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$strUrl);
curl_setopt($ch, CURLOPT_HEADER,
false
);
curl_setopt($ch, CURLOPT_POST,
true
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $arrayHeader);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arrayPostData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false
);
$result = curl_exec($ch);
curl_close ($ch);
}
?>