项目大纲
php
error_reporting(0);//屏蔽报错
$photo=$_GET["photo"];
$gps=$_GET["gps"];
if($gps==""){exit("GPS地址为空");}
$apiKey = 'xxxxxxxxxxxxxxxxxxx'; //高德API密钥
$html = file_get_contents("https://restapi.amap.com/v3/assistant/coordinate/convert?locations=".$gps."&coordsys=gps&output=json&key=".$apiKey.""); //高德坐标转换
$arr = json_decode($html, true); // 将获取到的 JSON 数据解析成数组
$status = $arr["status"];
$info = $arr["info"];
$infocode = $arr["infocode"];
$locations = $arr["locations"];
//https://restapi.amap.com/v3/staticmap?location=".$gps."&zoom=15&size=400*400&markers=mid,,A:".$gps."&key=".$apiKey."
if($photo == 1)
{
// 构建图片URL
$gps=$_GET["gps"];
if($gps==""){exit("GPS地址为空");}
$apiKey = 'xxxxxxxxxxxxxxxxxxx';
$ip = $location;
$savePath = 'gps_map.png'; // 例如 'images/map.png'
$imageUrl = "https://restapi.amap.com/v3/staticmap?location=".$locations."&zoom=15&size=400*400&markers=mid,,A:".$locations."&key=".$apiKey."";
// 使用file_get_contents获取图片内容
$imageContent = file_get_contents($imageUrl);
// 使用file_put_contents将图片内容保存到文件
$saveResult = file_put_contents($savePath, $imageContent);
$map = file_get_contents("http://api.xemowo.top/api/gaode/gps_map.png"); //保存图片
// 将图像数据转换为 Base64 编码
$base64 = base64_encode($map);
// 嵌入到 img 标签中
echo ''" width="400" height="400" />'; //给图片加上base64,让图片刷新
exit();
}
$data = array(
'status' => $status,
'info' => $info,
'infocode' => $infocode,
'locations' => $locations,
);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit();
php
error_reporting(0);//屏蔽报错
$photo=$_GET["photo"];
$address=$_GET["address"];
$apiKey = 'xxxxxxxxxxxxxxx';
if($address==""){exit("地址为空");}
$html = file_get_contents("https://restapi.amap.com/v3/geocode/geo?address=".$address."&output=json&key=".$apiKey."");
$arr = json_decode($html, true); // 将获取到的 JSON 数据解析成数组
$formatted_address = $arr["geocodes"][0]["formatted_address"];
$location = $arr["geocodes"][0]["location"];
$level = $arr["geocodes"][0]["level"];
$data = array(
'level' => $level,
'formatted_address' => $formatted_address,
'location' => $location,
);
if($photo == 1)
{
// 构建图片URL
$ip = $location;
$savePath = 'chakan_map.png'; // 例如 'images/map.png'
$apiKey = 'xxxxxxxxxxxxxxx';
$imageUrl = "https://restapi.amap.com/v3/staticmap?location=".$location."&zoom=15&size=400*400&markers=mid,,A:".$location."&key=".$apiKey."";
// 使用file_get_contents获取图片内容
$imageContent = file_get_contents($imageUrl);
// 使用file_put_contents将图片内容保存到文件
$saveResult = file_put_contents($savePath, $imageContent);
$map = file_get_contents("http://api.xemowo.top/api/gaode/chakan_map.png");
// 将图像数据转换为 Base64 编码
$base64 = base64_encode($map);
// 嵌入到 img 标签中
echo ''" width="400" height="400" />';
exit();
}
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit();
php
error_reporting(0);//屏蔽报错
$photo=$_GET["photo"];
$oled=$_GET["oled"];
$all=$_GET["all"];
$esp32=$_GET["esp32"];
$mark = $_GET["mark"];
if($esp32 == 1)
{
if (file_exists($filename)) {
// 读取文件内容
$content = file_get_contents($filename);
$aa = mb_substr("".$instruction."",0,10,'utf-8');
$bb = mb_substr("".$instruction."",10,10,'utf-8');
$cc = mb_substr("".$instruction."",20,10,'utf-8');
$dd = mb_substr("".$instruction."",30,10,'utf-8');
$data = array(
'content' => $content,
'oled_a' => $aa,
'oled_b' => $bb,
'oled_c' => $cc,
'oled_d' => $dd,
);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit();
}
}
$origin=$_GET["origin"];
if($origin==""){exit("起点origin地址为空");}
$destination=$_GET["destination"];
if($destination==""){exit("目的地destination地址为空");}
$apiKey = 'xxxxxxxxxxxxxxx';
if($all == 1)
{
$html = file_get_contents("https://restapi.amap.com/v3/direction/walking?origin=".$origin."&destination=".$destination."&key=".$apiKey."");
echo $html;
exit();
}
$html = file_get_contents("https://restapi.amap.com/v3/direction/walking?origin=".$origin."&destination=".$destination."&key=".$apiKey."");
$arr = json_decode($html, true); // 将获取到的 JSON 数据解析成数组
$distance = $arr["route"]["paths"][0]["distance"];//步行距离
$duration = $arr["route"]["paths"][0]["duration"];//步行预计
$instruction = $arr["route"]["paths"][0]["steps"][0]["instruction"];//路段步行指示
$orientation = $arr["route"]["paths"][0]["steps"][0]["orientation"];//方向
$polyline = $arr["route"]["paths"][0]["steps"][0]["polyline"];//坐标点
if($mark == 1)
{
// 定义文件名
$filename = "walk.txt";
// 使用文件写入模式打开文件。如果文件不存在,会自动创建
$file = fopen($filename, "w");
// 检查文件是否成功打开
if ($file) {
// 将文本写入文件
fwrite($file, $instruction);
// 关闭文件
fclose($file);
}
}
if($photo == 1)
{
// 构建图片URL
$apiKey = 'xxxxxxxxxxxx';
$ip = $location;
$savePath = 'walk_map.png';
$imageUrl = "https://restapi.amap.com/v3/staticmap?zoom=16&size=400*400&paths=10,0x0000ff,1,,:".$polyline."&key=".$apiKey."";
// 使用file_get_contents获取图片内容
$imageContent = file_get_contents($imageUrl);
// 使用file_put_contents将图片内容保存到文件
$saveResult = file_put_contents($savePath, $imageContent);
$map = file_get_contents("http://api.xemowo.top/api/gaode/walk_map.png");
// 将图像数据转换为 Base64 编码
$base64 = base64_encode($map);
// 嵌入到 img 标签中
echo ''" width="400" height="400" />';
exit();
}
//适配oled
if($oled == 1)
{
$aa = mb_substr("".$instruction."",0,10,'utf-8');
$bb = mb_substr("".$instruction."",10,10,'utf-8');
$cc = mb_substr("".$instruction."",20,10,'utf-8');
$dd = mb_substr("".$instruction."",30,10,'utf-8');
$data = array(
'distance' => $distance,
'duration' => $duration,
'instruction' => $instruction,
'orientation' => $orientation,
'polyline' => $polyline,
'oled_a' => $aa,
'oled_b' => $bb,
'oled_c' => $cc,
'oled_d' => $dd,
);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit();
}else{
$data = array(
'distance' => $distance,
'duration' => $duration,
'instruction' => $instruction,
'orientation' => $orientation,
'polyline' => $polyline,
);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit();
}
"esp32"];
$mark = $_GET["mark"];
$filename = "walk.txt";
if($esp32 == 1)
{
if (file_exists($filename)) {
// 读取文件内容
$content = file_get_contents($filename);
$aa = mb_substr("".$content."",0,10,'utf-8');
$bb = mb_substr("".$content."",10,10,'utf-8');
$cc = mb_substr("".$content."",20,10,'utf-8');
$dd = mb_substr("".$content."",30,10,'utf-8');
$data = array(
'content' => $content,
'oled_a' => $aa,
'oled_b' => $bb,
'oled_c' => $cc,
'oled_d' => $dd,
);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit();
}
}
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ BOARD_I2C_SCL, /* data=*/ BOARD_I2C_SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
const char * ID = "XEMOWO_PC";//wifi账号
const char * PASSWORD = "1SUNjiajun";//wifi密码
const char* one;//api第一行内容
const char* two;//api第二行内容
const char* three;//api第三行内容
const char* four;//api第四行内容
String API = "";
String url_xinzhi = "";
String WeatherURL = "";
HTTPClient http;
String GitURL(String api)
{
url_xinzhi = "http://api.xemowo.top/api/gaode/esp_walk.php?esp32=1";//oled=1则表示使用oled专属格式
return url_xinzhi;
}
void ParseWeather(String url)
{
http.begin(url);
int httpGet = http.GET();
if(httpGet > 0)
{
Serial.printf("HTTPGET is %d",httpGet);
if(httpGet == HTTP_CODE_OK)
{
StaticJsonDocument<500> doc;
String json = http.getString();
Serial.println("解析");
Serial.println(json);
deserializeJson(doc, json);
one = doc["oled_a"]; // "人生就是一列开往坟墓"
two = doc["oled_b"]; // "的列车,路途上会有很"
three = doc["oled_c"]; // "多站,很难有人可以至"
four = doc["oled_d"]; // "始至终陪着走完。\n"
}
else
{
Serial.printf("ERROR1!!");
ParseWeather(WeatherURL);
}
}
else
{
Serial.printf("ERROR2!!");
ParseWeather(WeatherURL);
}
http.end();
}
void setup() {
// put your setup code here, to run once:
u8g2.setFont( u8g2_font_wqy12_t_gb2312 );//设置为中文字体
u8g2.begin();
u8g2.enableUTF8Print();
Serial.begin(115200);
Serial.println("Init u8g2 ....");
Serial.println("WiFi:");
Serial.println(ID);
Serial.println("PASSWORLD:");
Serial.println(PASSWORD);
WiFi.begin(ID,PASSWORD);
u8g2.setCursor (0, 10);
u8g2.println("连接wifi中");
u8g2.sendBuffer();
while(WiFi.status()!=WL_CONNECTED)
{
delay(10000);//延迟大一点,不然联网连不上!
Serial.println("正在连接...");
u8g2.setCursor (0, 10);
u8g2.println("连接wifi中");
u8g2.sendBuffer();
}
Serial.println("连接成功!");
//==================wifi连接==================
u8g2.clearBuffer();
WeatherURL = GitURL(API);
delay(100);
}
void loop() {
ParseWeather(WeatherURL);
Serial.println(WeatherURL);
u8g2.clearBuffer();//清平
delay(10);
u8g2.setCursor (0, 10);
u8g2.println(one);
u8g2.setCursor (0, 25);
u8g2.println(two);
u8g2.setCursor (0, 40);
u8g2.println(three);
u8g2.setCursor (0, 55);
u8g2.println(four);
u8g2.sendBuffer();//将内容上传到缓存区
delay(5000);
}
①下载库文件,项目所需的库,都可以在内置的库文件管理器中找到
(请备注来意,加群请备注城市-称呼-行业岗位信息)