123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- class PushwarnController extends Controller {
-
-
- public function s_curl($url){
- $ch = curl_init();
- curl_setopt ($ch, CURLOPT_URL, $url);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
- $file_contents = curl_exec($ch);
- curl_close($ch);
- $arr = json_decode($file_contents,true);
- return $arr;
- }
- public function curl($url,$data=''){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $info = curl_exec($ch);
- if (curl_errno($ch)) {return 'Errno'.curl_error($ch);}else{ return $info;}
- curl_close($ch);
- }
-
- /**
- * [array_column1 ] 多维数组改成关联数组转字符串,
- * @param $rows [description]必需。多维数组。
- * @param [type] $column_key [description]必需。可以是索引数组的列的整数索引,或者是关联数组的列的字符串键值。
- * @param [type] $index_key [description]可选。用作返回数组的索引/键的列。
- * @return [type] [description](两个参数)返回用逗号分割的字符串,(三个参数)返回以第三个参数为列的索引数组
- */
- public function array_column1($rows, $column_key, $index_key = null) {
- $data = array();
- if (empty($index_key)) {
- foreach ($rows as $row) {
- $data[] = $row[$column_key];
- }
- $data=implode(",",$data);
- } else {
- foreach ($rows as $row) {
- $data[$row[$index_key]] = $row[$column_key];
- }
- }
- return $data;
- }
- public function SendDeviceAlarm($access_token,$openid,$address,$deviceid,$type,$time,$remark,$ljurl,$url){
- $data = array(
- "touser"=> $openid,
- "template_id"=>"9cYn9IdoLE7NhCAPTIc1Ip4dV5JPrbbATxQT-v944Vw",
- "url" =>$ljurl,
- //"url" =>"http://zt-iot.com/ztxf/weixin.php/Home/Fire/water",
- "data"=> array(
- "first"=> array(
- "value"=> $address,
- "color"=>"#44b549"
- ),
- "keyword1"=>array(
- "value"=> $deviceid,
- "color"=>"#173177"
- ),
- "keyword2"=> array(
- "value"=> $type,
- "color"=>"#173177"
- ),
- "keyword3"=> array(
- "value"=> $time,
- "color"=>"#173177"
- ),
- "remark"=>array(
- "value"=> $remark,
- "color"=>"#aaaaaa"
- )
- )
- );
- //{{first.DATA}}
- //设备号:{{keyword1.DATA}}
- //报警类型:{{keyword2.DATA}}
- //时间:{{keyword3.DATA}}
- //{{remark.DATA}}
- $data = json_encode($data);
- $QUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
- $res = $this->curl($QUEST_URL,$data);
- return json_decode($res,true);
- }
- public function SendDeviceAlarm1($access_token,$openid,$content,$type,$title,$people,$remark,$url){
- $data = array(
- "touser"=> $openid,
- "template_id"=>"N4PQZ9AmO2mjWVRjfZzYgLFrNq69WcLBW1KKjP1jbDs",
- "url" =>$url,
- "data"=> array(
- "first"=> array(
- "value"=> $content,
- "color"=>"#44b549"
- ),
- "keyword1"=>array(
- "value"=> $type,
- "color"=>"#173177"
- ),
- "keyword2"=> array(
- "value"=> $title,
- "color"=>"#173177"
- ),
- "keyword3"=> array(
- "value"=> $people,
- "color"=>"#173177"
- ),
- "remark"=>array(
- "value"=> $remark,
- "color"=>"#173177"
- )
- )
- );
- //{{first.DATA}}
- //设备号:{{keyword1.DATA}}
- //报警类型:{{keyword2.DATA}}
- //时间:{{keyword3.DATA}}
- //{{remark.DATA}}
- $data = json_encode($data);
- $QUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
- $res = $this->curl($QUEST_URL,$data);
- return json_decode($res,true);
- // return "ceshi";
- }
- public function SendDeviceAlarm3($access_token,$openid,$address,$deviceid,$type,$time,$remark,$url){
- $data = array(
- "touser"=> $openid,
- "template_id"=>"kMIOm99qgqAQ-nqsSxWlUToz4Krm-_TopRBJolXNBB8",
- "url" =>$url,
- //"url" =>"http://zt-iot.com/ztxf/weixin.php/Home/Fire/water",
- "data"=> array(
- "first"=> array(
- "value"=> $address,
- "color"=>"#44b549"
- ),
- "keyword1"=>array(
- "value"=> $deviceid,
- "color"=>"#173177"
- ),
- "keyword2"=> array(
- "value"=> $type,
- "color"=>"#173177"
- ),
- "keyword3"=> array(
- "value"=> $time,
- "color"=>"#173177"
- ),
- "remark"=>array(
- "value"=> $remark,
- "color"=>"#aaaaaa"
- )
- )
- );
- //{{first.DATA}}
- //设备号:{{keyword1.DATA}}
- //报警类型:{{keyword2.DATA}}
- //时间:{{keyword3.DATA}}
- //{{remark.DATA}}
- $data = json_encode($data);
- $QUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
- $res = $this->curl($QUEST_URL,$data);
- return json_decode($res,true);
- }
- public function SendDeviceAlarm2($access_token,$openid,$address,$deviceid,$type,$time,$remark,$url){
- $data = array(
- "touser"=> $openid,
- "template_id"=>" kMIOm99qgqAQ-nqsSxWlUToz4Krm-_TopRBJolXNBB8",
- "url" =>$url,
- //"url" =>"http://zt-iot.com/ztxf/weixin.php/Home/Fire/water",
- "data"=> array(
- "first"=> array(
- "value"=> $address,
- "color"=>"#44b549"
- ),
- "keyword1"=>array(
- "value"=> $deviceid,
- "color"=>"#173177"
- ),
- "keyword2"=> array(
- "value"=> $type,
- "color"=>"#173177"
- ),
- "keyword3"=> array(
- "value"=> $time,
- "color"=>"#173177"
- ),
- "remark"=>array(
- "value"=> $remark,
- "color"=>"#aaaaaa"
- )
- )
- );
- //{{first.DATA}}
- //设备号:{{keyword1.DATA}}
- //报警类型:{{keyword2.DATA}}
- //时间:{{keyword3.DATA}}
- //{{remark.DATA}}
- $data = json_encode($data);
- $QUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
- $res = $this->curl($QUEST_URL,$data);
- return json_decode($res,true);
- }
- }
|