You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

178 regels
5.7 KiB

  1. <?php
  2. /*
  3. Author:XM
  4. Compeny:Spiders Travel
  5. */
  6. function writeLog($log){
  7. $dir=__DIR__."/../Log/";
  8. if (!is_dir($dir)){
  9. mkdir($dir);
  10. }
  11. $filename=$dir.date("Y-m-d").".log";
  12. file_put_contents($filename, date("Y-m-d H:i:s")."\t".$log.PHP_EOL,FILE_APPEND);
  13. }
  14. function makeSign($array){
  15. $str='';
  16. foreach ($array as $v){
  17. $str.=$v;
  18. }
  19. return sha1($str.TOKEN);
  20. }
  21. //获取唯一的id
  22. function getUniqeId(){
  23. $pdo= conn();
  24. $result=$pdo->query("select FUNC_GET_UNIQUE_ID('1','1') id");
  25. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  26. $pdo=NULL;
  27. return $rowset[0]['id'];
  28. }
  29. function getUserId(){
  30. if (isset($_COOKIE['xm_data'])){
  31. $xm_data=$_COOKIE['xm_data'];
  32. $data=unserialize($xm_data);
  33. $id=$data['id'];
  34. $user=$data['user'];
  35. $checkToken=$data['token'];
  36. $list=$data['list'];
  37. $token=makeSign(array($id,$user,serialize($list)));
  38. if ($checkToken == $token){
  39. return $id;
  40. }else{
  41. return false;
  42. }
  43. }else{
  44. return false;
  45. }
  46. }
  47. function httpRequest($url,$data=null){
  48. $ch=curl_init();
  49. curl_setopt($ch, CURLOPT_URL, $url);
  50. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  51. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  52. if (!empty($data)){
  53. curl_setopt($ch, CURLOPT_POST, 1);
  54. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  55. }
  56. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  57. $output=curl_exec($ch);
  58. curl_close($ch);
  59. return $output;
  60. }
  61. //function sendTelMessage($phones,$user_name,$content,$order_id){
  62. // if (SEND_MESSAGE ==true){
  63. // //$url='http://www.mxtong.net.cn/GateWay/Services.asmx/DirectSend?UserID=995596&Account=alert&Password=zzcx8888&Phones='.$phones.'&Content='.$content.'【蜘蛛行】&SendTime=&SendType=1&PostFixNumber=';
  64. // $url='http://hprpt2.eucp.b2m.cn:8080/sdkproxy/sendsms.action?cdkey=8SDK-EMY-6699-RISUM&password=175348&phone='.$phones.'&message=【蜘蛛行】'.$content;
  65. // $response=httpRequest($url);
  66. // writeLog('url'.$url."返回值".$response);
  67. // }else{
  68. // return array("未开启短信通知");
  69. // }
  70. // return $response;
  71. //}
  72. function sendTelMessage($phones,$user_name,$content,$order_id){
  73. $send_data = array();
  74. $send_data["cdkey"] = "8SDK-EMY-6699-RISUM";
  75. $send_data["password"] = "175348";
  76. $send_data["phone"] = $phones;
  77. $send_data["message"] = '【蜘蛛行】'.$content;
  78. if (SEND_MESSAGE ==true){
  79. //$url='http://www.mxtong.net.cn/GateWay/Services.asmx/DirectSend?UserID=995596&Account=alert&Password=zzcx8888&Phones='.$phones.'&Content='.$content.'【蜘蛛行】&SendTime=&SendType=1&PostFixNumber=';
  80. $url='http://hprpt2.eucp.b2m.cn:8080/sdkproxy/sendsms.action';
  81. //echo $url;
  82. $response=httpRequest($url,$send_data);
  83. // echo $response;die();
  84. writeLog('url'.$url."返回值".$response);
  85. }else{
  86. return array("未开启短信通知");
  87. }
  88. return $response;
  89. }
  90. function getDispAreaNameForCtrip( $city_name ) {
  91. $suzhou_array = array("拙政园","观前街");
  92. if( in_array($city_name, $suzhou_array) ) {
  93. return "苏州";
  94. }
  95. if( mb_strlen($city_name) <= 2 ) { return $city_name;}
  96. $last_word = mb_substr($city_name,-1,1);
  97. $cut_word = array("市","区","镇");
  98. if( in_array($last_word,$cut_word) ) {
  99. return mb_substr($city_name,0,mb_strlen($city_name)-1);
  100. }
  101. return $city_name;
  102. }
  103. function set_memcache( $key, $value ) {
  104. $mem = new Memcache;
  105. $mem->connect( MEMCACHE_HOST, MEMCACHE_PORT );
  106. $mem->set( $key, $value, 0, 3600*24*7 );
  107. }
  108. function get_memcache( $key ) {
  109. $mem = new Memcache;
  110. $mem->connect( MEMCACHE_HOST, MEMCACHE_PORT );
  111. $value = $mem->get( $key );
  112. return $value;
  113. }
  114. function clear_memcache() {
  115. $mem = new Memcache;
  116. $mem->connect( MEMCACHE_HOST, MEMCACHE_PORT );
  117. $mem->flush();
  118. }
  119. function get_position($imeis){
  120. $unix_time = time();
  121. $signature = md5(md5(API_GPS_PASSWORD).$unix_time);
  122. $url='http://api.gpsoo.net/1/auth/access_token?account='.API_GPS_ACCOUNT.'&time='.$unix_time.'&signature='.$signature;
  123. $html = file_get_contents($url);
  124. $return_array = json_decode($html,true);
  125. $access_token = $return_array["access_token"];
  126. //获取经纬度等
  127. $common_url = 'access_token='.$access_token.'&account='.API_GPS_ACCOUNT.'&time='.$unix_time;
  128. $url1 = 'http://api.gpsoo.net/1/devices/tracking?'.$common_url.'&map_type=BAIDU&target='.API_GPS_ACCOUNT.'&imeis='.$imeis;
  129. $html1 = file_get_contents($url1);
  130. $return_array1 = json_decode($html1,true);
  131. $j = $return_array1['data'][0]['lng'];
  132. $w = $return_array1['data'][0]['lat'];
  133. $speed =$return_array1['data'][0]['speed'];
  134. //convert_baidumap_to_tencentmap($w,$j);
  135. return array('j'=>$j,'w'=>$w,'speed'=>$speed);
  136. }
  137. //$test_time = date("Y-m-d H:i:s", 1924912800);echo $test_time."<hr />";
  138. //获取账户信息
  139. function convert_baidumap_to_tencentmap( &$lat, &$lng ) {
  140. $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  141. $x = $lng - 0.0065;
  142. $y = $lat - 0.006;
  143. $z = sqrt(($x*$x+$y*$y)) - 0.00002 * sin($y * $x_pi);
  144. $theta = atan2($y,$x) - 0.000003 * cos($x * $x_pi);
  145. $lng = $z * cos($theta);
  146. $lat = $z * sin($theta);
  147. }
  148. function getposition($busno){
  149. $base_url = "http://test.hstsp.cn:8077/data/";
  150. $account_id = "hdgps";
  151. $account_pwd = md5("123456");
  152. $login_url = $base_url."login/tokenDuration.do?account={$account_id}&passwd={$account_pwd}";
  153. $result = httpRequest( $login_url );
  154. $result_array = json_decode($result,true);
  155. $token_str = $result_array["tokenStr"];
  156. $check_car_no = urlencode($busno);
  157. $get_car_id_url = $base_url."LogisticalCar/queryCarId.do?tokenStr={$token_str}&plateCodes={$check_car_no}";
  158. $result =httpRequest( $get_car_id_url );
  159. $result_array = json_decode($result,true);
  160. $car_id =$result_array["Data"][0]["id"];
  161. $get_car_info_url = $base_url."VehicleMonitor/queryMultiVehicleLocation.do?tokenStr={$token_str}&vehicleIds=". $car_id."&mapType=1";
  162. $result = httpRequest( $get_car_info_url );
  163. $result_array = json_decode($result,true);
  164. return $result_array;
  165. }