PushwarnContorller.class.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. 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. }