forked from numpapickmaker/LINE-BOT-PHP-NUMPAPICK-STARTER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpub.php
40 lines (35 loc) · 1.11 KB
/
pub.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
function pubMqtt($topic,$msg) {
$APPID= "project584281037/"; //PUT NETPIE APPID Name end with "/"
$KEY = "6GzDV9BuYqUhPCZ"; //PUT NETPIE Key ID
$SECRET = "7LI4n6JxXl78KU40Gm33ZI4XP"; //PUT NETPIE Secret ID
$Topic = "$topic";
put("https://api.netpie.io/microgear/".$APPID.$Topic."?retain&auth=".$KEY.":".$SECRET,$msg);
}
function getMqttfromlineMsg($Topic,$lineMsg) {
$pos = strpos($lineMsg, ":");
if($pos) {
$splitMsg = explode(":", $lineMsg);
$topic = $splitMsg[0];
$msg = $splitMsg[1];
pubMqtt($topic,$msg);
}
else {
$topic = $Topic;
$msg = $lineMsg;
pubMqtt($topic,$msg);
}
}
function put($url,$tmsg) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $tmsg);
$response = curl_exec($ch);
curl_close($ch);
echo $response . "\r\n";
return $response;
}
?>