PushWarnController.class.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class PushwarnController extends Controller {
  5. public function s_curl($url){
  6. $ch = curl_init();
  7. curl_setopt ($ch, CURLOPT_URL, $url);
  8. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  9. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
  10. $file_contents = curl_exec($ch);
  11. curl_close($ch);
  12. $arr = json_decode($file_contents,true);
  13. return $arr;
  14. }
  15. public function curl($url,$data=''){
  16. $ch = curl_init();
  17. curl_setopt($ch, CURLOPT_URL, $url);
  18. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  19. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  20. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  21. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  22. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  23. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  24. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26. $info = curl_exec($ch);
  27. if (curl_errno($ch)) {return 'Errno'.curl_error($ch);}else{ return $info;}
  28. curl_close($ch);
  29. }
  30. /**
  31. * [array_column1 ] 多维数组改成关联数组转字符串,
  32. * @param $rows [description]必需。多维数组。
  33. * @param [type] $column_key [description]必需。可以是索引数组的列的整数索引,或者是关联数组的列的字符串键值。
  34. * @param [type] $index_key [description]可选。用作返回数组的索引/键的列。
  35. * @return [type] [description](两个参数)返回用逗号分割的字符串,(三个参数)返回以第三个参数为列的索引数组
  36. */
  37. public function array_column1($rows, $column_key, $index_key = null) {
  38. $data = array();
  39. if (empty($index_key)) {
  40. foreach ($rows as $row) {
  41. $data[] = $row[$column_key];
  42. }
  43. $data=implode(",",$data);
  44. } else {
  45. foreach ($rows as $row) {
  46. $data[$row[$index_key]] = $row[$column_key];
  47. }
  48. }
  49. return $data;
  50. }
  51. public function SendDeviceAlarm($access_token,$openid,$address,$deviceid,$type,$time,$remark,$ljurl,$url){
  52. $data = array(
  53. "touser"=> $openid,
  54. "template_id"=>"9cYn9IdoLE7NhCAPTIc1Ip4dV5JPrbbATxQT-v944Vw",
  55. "url" =>$ljurl,
  56. //"url" =>"http://zt-iot.com/ztxf/weixin.php/Home/Fire/water",
  57. "data"=> array(
  58. "first"=> array(
  59. "value"=> $address,
  60. "color"=>"#44b549"
  61. ),
  62. "keyword1"=>array(
  63. "value"=> $deviceid,
  64. "color"=>"#173177"
  65. ),
  66. "keyword2"=> array(
  67. "value"=> $type,
  68. "color"=>"#173177"
  69. ),
  70. "keyword3"=> array(
  71. "value"=> $time,
  72. "color"=>"#173177"
  73. ),
  74. "remark"=>array(
  75. "value"=> $remark,
  76. "color"=>"#aaaaaa"
  77. )
  78. )
  79. );
  80. //{{first.DATA}}
  81. //设备号:{{keyword1.DATA}}
  82. //报警类型:{{keyword2.DATA}}
  83. //时间:{{keyword3.DATA}}
  84. //{{remark.DATA}}
  85. $data = json_encode($data);
  86. $QUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
  87. $res = $this->curl($QUEST_URL,$data);
  88. return json_decode($res,true);
  89. }
  90. public function SendDeviceAlarm1($access_token,$openid,$content,$type,$title,$people,$remark,$url){
  91. $data = array(
  92. "touser"=> $openid,
  93. "template_id"=>"N4PQZ9AmO2mjWVRjfZzYgLFrNq69WcLBW1KKjP1jbDs",
  94. "url" =>$url,
  95. "data"=> array(
  96. "first"=> array(
  97. "value"=> $content,
  98. "color"=>"#44b549"
  99. ),
  100. "keyword1"=>array(
  101. "value"=> $type,
  102. "color"=>"#173177"
  103. ),
  104. "keyword2"=> array(
  105. "value"=> $title,
  106. "color"=>"#173177"
  107. ),
  108. "keyword3"=> array(
  109. "value"=> $people,
  110. "color"=>"#173177"
  111. ),
  112. "remark"=>array(
  113. "value"=> $remark,
  114. "color"=>"#173177"
  115. )
  116. )
  117. );
  118. //{{first.DATA}}
  119. //设备号:{{keyword1.DATA}}
  120. //报警类型:{{keyword2.DATA}}
  121. //时间:{{keyword3.DATA}}
  122. //{{remark.DATA}}
  123. $data = json_encode($data);
  124. $QUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
  125. $res = $this->curl($QUEST_URL,$data);
  126. return json_decode($res,true);
  127. // return "ceshi";
  128. }
  129. public function SendDeviceAlarm3($access_token,$openid,$address,$deviceid,$type,$time,$remark,$url){
  130. $data = array(
  131. "touser"=> $openid,
  132. "template_id"=>"kMIOm99qgqAQ-nqsSxWlUToz4Krm-_TopRBJolXNBB8",
  133. "url" =>$url,
  134. //"url" =>"http://zt-iot.com/ztxf/weixin.php/Home/Fire/water",
  135. "data"=> array(
  136. "first"=> array(
  137. "value"=> $address,
  138. "color"=>"#44b549"
  139. ),
  140. "keyword1"=>array(
  141. "value"=> $deviceid,
  142. "color"=>"#173177"
  143. ),
  144. "keyword2"=> array(
  145. "value"=> $type,
  146. "color"=>"#173177"
  147. ),
  148. "keyword3"=> array(
  149. "value"=> $time,
  150. "color"=>"#173177"
  151. ),
  152. "remark"=>array(
  153. "value"=> $remark,
  154. "color"=>"#aaaaaa"
  155. )
  156. )
  157. );
  158. //{{first.DATA}}
  159. //设备号:{{keyword1.DATA}}
  160. //报警类型:{{keyword2.DATA}}
  161. //时间:{{keyword3.DATA}}
  162. //{{remark.DATA}}
  163. $data = json_encode($data);
  164. $QUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
  165. $res = $this->curl($QUEST_URL,$data);
  166. return json_decode($res,true);
  167. }
  168. public function SendDeviceAlarm2($access_token,$openid,$address,$deviceid,$type,$time,$remark,$url){
  169. $data = array(
  170. "touser"=> $openid,
  171. "template_id"=>" kMIOm99qgqAQ-nqsSxWlUToz4Krm-_TopRBJolXNBB8",
  172. "url" =>$url,
  173. //"url" =>"http://zt-iot.com/ztxf/weixin.php/Home/Fire/water",
  174. "data"=> array(
  175. "first"=> array(
  176. "value"=> $address,
  177. "color"=>"#44b549"
  178. ),
  179. "keyword1"=>array(
  180. "value"=> $deviceid,
  181. "color"=>"#173177"
  182. ),
  183. "keyword2"=> array(
  184. "value"=> $type,
  185. "color"=>"#173177"
  186. ),
  187. "keyword3"=> array(
  188. "value"=> $time,
  189. "color"=>"#173177"
  190. ),
  191. "remark"=>array(
  192. "value"=> $remark,
  193. "color"=>"#aaaaaa"
  194. )
  195. )
  196. );
  197. //{{first.DATA}}
  198. //设备号:{{keyword1.DATA}}
  199. //报警类型:{{keyword2.DATA}}
  200. //时间:{{keyword3.DATA}}
  201. //{{remark.DATA}}
  202. $data = json_encode($data);
  203. $QUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
  204. $res = $this->curl($QUEST_URL,$data);
  205. return json_decode($res,true);
  206. }
  207. }