Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. function http_request($url,$data=null){
  3. $ch=curl_init();
  4. curl_setopt($ch, CURLOPT_URL, $url);
  5. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  7. if (!empty($data)){
  8. curl_setopt($ch, CURLOPT_POST, 1);
  9. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  10. }
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12. $output=curl_exec($ch);
  13. curl_close($ch);
  14. return $output;
  15. }
  16. function write_log($activation){
  17. $dir=CONFIG_ADDR."/../Log";
  18. if (!is_dir($dir)){
  19. mkdir($dir);
  20. }
  21. $open=fopen($dir."/Function_log.txt","a");
  22. fwrite($open,date("Y-m-d H:i:s")."\t".$activation."\r\n");
  23. fclose($open);
  24. }
  25. function downloadImageFromWeiXin($url){
  26. $ch=curl_init();
  27. curl_setopt($ch, CURLOPT_URL, $url);
  28. curl_setopt($ch, CURLOPT_HEADER, 0);
  29. curl_setopt($ch, CURLOPT_NOBODY, 0);
  30. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  31. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  33. $body=curl_exec($ch);
  34. $header=curl_getinfo($ch);
  35. curl_close($ch);
  36. return array_merge(array('body'=>$body),array('header'=>$header));
  37. }
  38. function downfile($file)
  39. {
  40. $date=basename($file);
  41. Header( "Content-type: image/png");
  42. Header( "Accept-Ranges: bytes ");
  43. Header( "Accept-Length: " .filesize($file));
  44. header( "Content-Disposition: attachment; filename= {$date}");
  45. readfile($file);
  46. }
  47. function getAccesstoken(){
  48. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  49. $data = json_decode(get_php_file("access_token.php"));
  50. if ($data->expire_time < time()) {
  51. // 如果是企业号用以下URL获取access_token
  52. // $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  53. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".APPSECRET;
  54. $res = json_decode(http_request($url));
  55. $access_token = $res->access_token;
  56. write_log("url获取的token:".$access_token);
  57. if ($access_token) {
  58. $data->expire_time = time() + 3600;
  59. $data->access_token = $access_token;
  60. set_php_file("access_token.php", json_encode($data));
  61. write_log("生成access_token:".$access_token);
  62. }
  63. } else {
  64. $access_token = $data->access_token;
  65. write_log("文件中读取的token:".$access_token);
  66. }
  67. /* $dir=__DIR__."/../Log/";
  68. if (!is_dir($dir)){
  69. mkdir($dir);
  70. }
  71. $token_file=$dir.'/access_token';
  72. if (file_exists($token_file) && time()-filemtime($token_file)<4800){
  73. write_log("menu--文件中读取的token:".file_get_contents($token_file));
  74. $access_token= file_get_contents($token_file);
  75. }else{
  76. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".APPSECRET;
  77. $result=http_request($url);
  78. if(!$result){
  79. write_log("menu-获取token出错");
  80. echo "menu-获取token出错";
  81. exit;
  82. }
  83. $result_obj=json_decode($result);
  84. file_put_contents($token_file, $result_obj->access_token);
  85. write_log("menu-url获取的token:".$result_obj->access_token);
  86. $access_token= $result_obj->access_token;
  87. } */
  88. return $access_token;
  89. }
  90. function get_php_file($filename) {
  91. $dir=__DIR__."/../Log/";
  92. if (!is_dir($dir)){
  93. mkdir($dir);
  94. }
  95. $token_file=$dir.$filename;
  96. return trim(substr(file_get_contents($token_file), 15));
  97. }
  98. function set_php_file($filename, $content) {
  99. $dir=__DIR__."/../Log/";
  100. if (!is_dir($dir)){
  101. mkdir($dir);
  102. }
  103. $token_file=$dir.$filename;
  104. $fp = fopen($token_file, "w");
  105. fwrite($fp, "<?php exit();?>" . $content);
  106. fclose($fp);
  107. }
  108. function convert_baidumap_to_tencentmap( &$lat, &$lng ) {
  109. $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  110. $x = $lng - 0.0065;
  111. $y = $lat - 0.006;
  112. $z = sqrt(($x*$x+$y*$y)) - 0.00002 * sin($y * $x_pi);
  113. $theta = atan2($y,$x) - 0.000003 * cos($x * $x_pi);
  114. $lng = $z * cos($theta);
  115. $lat = $z * sin($theta);
  116. }