You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/application/third_party/updatetrain/controllers/updatestation.php

256 lines
9.1 KiB
PHTML

<?php
/*
* @Author: your name
* @Date: 2020-01-14 11:19:04
* @LastEditTime: 2020-05-08 14:22:49
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \information-system\application\third_party\updatetrain\controllers\updatestation.php
* 本地运行地址http://202.103.68.144:65008/info.php/thirdparty/updatetrain/updatestation/
* 前台的接口也需要更新一次https://cht.mycht.cn/info.php/apps/trainsystem/innerTrainSearch/getallstation
*/
defined('BASEPATH') or exit('No direct script access allowed');
6 years ago
ini_set('memory_limit', '256M');
6 years ago
set_time_limit(0);
class updatestation extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model("station_model");
}
public function index()
{
//
$this->load->view('bootstrap3/header');
$this->load->view('updatestation');
$this->load->view('bootstrap3/footer');
}
6 years ago
public function test()
{
$results = "";
for ($i = 1; $i <= 2000000; $i++) {
$results .= '"' . $i . '"';
6 years ago
}
$len = strlen($results);
6 years ago
header("Content-Length: " . $len);
6 years ago
header("Content-Encoding:UTF-8");
6 years ago
echo $results;
}
/**
* @description: 从12306抓取数据对比翰特数据库
* @param {type}
* @return:
*/
public function getstatioBy12306()
{
$stationUrl = "https://kyfw.12306.cn/otn/resources/js/framework/station_name.js";
$StationData = $this->get_data($stationUrl);
// echo $StationData;
$arr_Station = explode("@", str_replace("';", "", str_replace("var station_names ='", "", $StationData)));
//print_r($arr_Station);
$NewStation = "";
6 years ago
$UpdateStaion = "";
for ($i = 0; $i < count($arr_Station); $i++) {
if ($arr_Station[$i] != null) {
$arr_StationDetail = explode("|", $arr_Station[$i]);
6 years ago
$TRS_Code = $arr_StationDetail[2];
$TRS_StationCN = $arr_StationDetail[1];
$TRS_Station = $arr_StationDetail[3];
// print_r($arr_StationDetail);
//对比数据库,如果是新的就保存
6 years ago
$isNew = $this->station_model->CompareStation($TRS_Code, $TRS_StationCN);
if ($isNew == 1) {
//更新
$strStation = "@-1|" . $TRS_Code . "|" . $TRS_Station . "|" . $TRS_StationCN . "|2|";
$UpdateStaion .= $strStation;
//表操作
6 years ago
$this->station_model->UpdateStation($TRS_Code, $TRS_StationCN);
6 years ago
} else if ($isNew == 2) {
//新增
$strStation = "@9999|" . $TRS_Code . "|" . $TRS_Station . "|" . $TRS_StationCN . "|2|";
$NewStation .= $strStation;
//表增加操作
$data["StationCN"] = $TRS_StationCN;
$data["Station"] = $TRS_Station;
$data["Code"] = $TRS_Code;
6 years ago
$this->station_model->AddStation($data);
}
}
}
6 years ago
$NewStationList = $UpdateStaion . $NewStation;
6 years ago
6 years ago
$len = strlen($NewStationList); //count( explode("@",$NewStationList))-1;
header("Content-Length: " . $len);
6 years ago
header("Content-Encoding:UTF-8");
6 years ago
6 years ago
if ($len > 0) {
//发送邮件
$this->station_model->SendMail(
"UpdateStationSystem",
"noreplay@email.com",
'zhaopeng',
'zhaopeng@hainatravel.com',
'New Station(by12306):' . date("Y-m-d"),
$NewStationList
);
6 years ago
echo $NewStationList;
}else{
echo "无站点更新";
6 years ago
}
}
/**
* @description: 对比12306与目前的站点文件
* @param {type}
* @return:
*/
public function getNewStationByFile()
{
$stationUrl = "https://kyfw.12306.cn/otn/resources/js/framework/station_name.js";
$StationData = $this->get_data($stationUrl);
$StationFileUrl = "https://biz.chinahighlights.com/china-trains/js/train/StationInfo.js";
$StationFileData = $this->get_data($StationFileUrl);
// echo $StationData;
$arr_Station = explode("@", str_replace("';", "", str_replace("var station_names ='", "", $StationData)));
$arr_StationFile = explode("@", str_replace("\";", "", str_replace("var station_names =\"", "", $StationFileData)));
//print_r($arr_Station);
$NewStation = "";
for ($i = 0; $i < count($arr_Station); $i++) {
$isNew = true;
$arr_StationDetail = explode("|", $arr_Station[$i]);
6 years ago
for ($j = 0; $j < count($arr_StationFile); $j++) {
if ($arr_Station[$i] != null) {
$arr_StationFileDetail = explode("|", $arr_StationFile[$j]);
//对比目前的站点文件,如果是新的就保存
if ($arr_StationDetail[2] == $arr_StationFileDetail[1] && $arr_StationDetail[1] == $arr_StationFileDetail[3]) {
6 years ago
$isNew = false;
6 years ago
break;
}
}
}
if ($isNew) {
6 years ago
$NewStation .= $arr_Station[$i] . "@";
}
}
echo $NewStation;
}
/**
6 years ago
* @description: 目前站点文件与翰特数据对比,导入HT没有的数据
* @param {type}
* @return:
*/
6 years ago
public function CheckFileAndHT()
{
$StationFileUrl = "https://biz.chinahighlights.com/china-trains/js/train/StationInfo.js";
$StationFileData = $this->get_data($StationFileUrl);
$arr_StationFile = explode("@", str_replace("\";", "", str_replace("var station_names =\"", "", $StationFileData)));
$NewStation = "";
6 years ago
for ($i = 0; $i < count($arr_StationFile); $i++) {
$arr_StationFileDetail = explode("|", $arr_StationFile[$i]);
6 years ago
//对比数据库,如果是新的就保存
$isNew = $this->station_model->GetStationCount($arr_StationFileDetail[1], $arr_StationFileDetail[3]);
if ($isNew) {
$NewStation .= $arr_StationFile[$i] . "@";
//保存到数据库
$data["StationCN"] = $arr_StationFileDetail[3];
$data["Station"] = $arr_StationFileDetail[2];
$data["Code"] = $arr_StationFileDetail[1];
6 years ago
//$this->station_model->AddStation($data);
6 years ago
}
}
6 years ago
if (strlen($NewStation) > 0) {
//发送邮件
$this->station_model->SendMail(
"UpdateStationSystem",
"noreplay@email.com",
'zhaopeng',
'zhaopeng@hainatravel.com',
'站点文件导入HT:' . date("Y-m-d"),
$NewStation
);
echo $NewStation;
} else {
echo ("无新站点");
}
}
/**
* @description: 从HT获取最新的站点信息
* @param {type}
* @return:
*/
6 years ago
public function GetNewStationFromHT()
{
//先获取当前使用的站点文件
$StationFileUrl = "https://biz.chinahighlights.com/china-trains/js/train/StationInfo.js";
$StationFileData = $this->get_data($StationFileUrl);
$arr_StationFile = explode("@", str_replace("\";", "", str_replace("var station_names =\"", "", $StationFileData)));
$NewStation = "";
//循环HT站点表对比
$StationList = $this->station_model->GetStationList();
6 years ago
foreach ($StationList as $Item) {
$isNew = true;
6 years ago
$TRS_ID = $Item->TRS_ID;
$TRS_StationCN = $Item->TRS_StationCN;
$TRS_Station = $Item->TRS_Station;
$TRS_Code = $Item->TRS_Code;
for ($i = 0; $i < count($arr_StationFile); $i++) {
$arr_StationFileDetail = explode("|", $arr_StationFile[$i]);
6 years ago
//对比数据库,如果是新的就保存
if ($TRS_StationCN == $arr_StationFileDetail[3] && $TRS_Code == $arr_StationFileDetail[1]) {
$isNew = false;
break;
6 years ago
}
}
if ($isNew) {
6 years ago
$strStation = "@" . $TRS_ID . "|" . $TRS_Code . "|" . $TRS_Station . "|" . $TRS_StationCN . "|2|";
$NewStation .= $strStation;
}
}
6 years ago
// echo $NewStation;
//发送邮件
$this->station_model->SendMail(
"UpdateStationSystem",
"noreplay@email.com",
'zhaopeng',
'zhaopeng@hainatravel.com',
'New Station:' . date("Y-m-d"),
$NewStation
);
}
function get_data($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证https证书
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}
/* End of file updatestation.php */