服务端订阅
位置
/www/wwwroot/v1
要使用命令行 启动php运行
php /www/wwwroot/v1/sub.php
tp调用发布消息
位置
/www/wwwroot/wl.zdlweixin.cn/sm.my/application/index/controller
User.php
使用 直接访问
http://wl.zdlweixin.cn/index/user/login.html
代码
$text = <<<here
{
"id": "7788",
"version": "1.0",
"sys":{
"ack":0
},
"params": {
"value": {
"Power": "on",
"WF": "27777"
},
"time": 1524448722000
},
"method": "thing.event.1111.post"
}
here;
$url= 'http://127.0.0.1:8000/';
$headerArray =array("Content-Type: multipart/form-data;","Accept:application/json");
/*
$data=array(
"topic" => "/sys/a19NhfFNnNb/1111/thing/event/property/post",
"msg" => $text
);
*/
//---------------
$data=array(
"IotInstanceId" => "iot-06z00dor33fumoq",
"ProductKey" => "gw7dZ8qRLAS",
"Topic" => "/sys/gw7dZ8qRLAS/fxx111/thing/event/property/post",
"Msg" => $text
);
$data = json_encode($data);
$ch = curl_init(); //初始化CURL句柄
curl_setopt($ch, CURLOPT_URL, $url); //设置请求的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //设为TRUE把curl_exec()结果转化为字串,而不是直接输出
curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST"); //设置请求方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置提交的字符串
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
return "--";
服务端发布消息
位置
/www/wwwroot/main
后台运行
nohup /www/wwwroot/main/mymain > /www/wwwroot/main/mymain.log 2>&1 &
运行
/www/wwwroot/main/mymain
关闭
查看运行中的程序 PID
ps -aux | grep "mymain"
杀死进程
kill -9 对应PID