選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

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