bokun抓取的程序

mobile-first
赵鹏 5 years ago
parent f31d1e9d50
commit c2e9227600

@ -0,0 +1,107 @@
<?php
/*
* @Author: zp
* @Date: 2020-04-29 11:36:41
* @LastEditTime: 2020-05-26 15:33:10
* @LastEditors: Please set LastEditors
* @Description: 雷延廷的抓取bokun接口文件
* @FilePath: \trippest.com\TP\libraries\bokun_lib.php
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Bokun_lib
{
protected $ci;
private $bokun_url = 'https://api.bokun.is'; // https://api.bokun.io
private $access_key = '2f6284e43ee84f6a85fbb0c5660c7404';
private $secret_key = 'ef3353fe28dc402b9045c2a766b68efe';
public function __construct()
{
$this->ci =& get_instance();
}
/**
* @description:
* @param string $activityid :产品的ID
* @return: json :产品的详细json数据
* @Date Changed:
*/
public function get_activity_detail($activityid){
$path = "/activity.json/$activityid?currency=USD&lang=EN";
$activity = $this->call_bokun($path,'get');
return ($activity);
}
public function get_all_product_list()
{
$path = "/product-list.json/list?lang=EN";
$product_list = $this->call_bokun($path,'get');
return ($product_list);
}
public function get_product_list_detail($list_id)
{
$path = "/product-list.json/$list_id?currency=USD&lang=EN";
$product_list = $this->call_bokun($path,'get');
return ($product_list);
}
public function get_activity_price($bokun_id)
{
$path = "/activity.json/$bokun_id/price-list?currency=USD";
$price_list = $this->call_bokun($path,'get');
return ($price_list);
}
private function make_bokun_signature($date, $method, $path)
{
$raw_str = $date . $this->access_key . strtoupper($method) . $path;
return base64_encode(hash_hmac("sha1", $raw_str, $this->secret_key, TRUE));
}
private function call_bokun($path, $method, $body=null)
{
$url = $this->bokun_url . $path;
$create_date = gmdate("Y-m-d H:i:s");
$bokun_signature = $this->make_bokun_signature($create_date, $method, $path);
$curl = curl_init();
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array(
"X-Bokun-Date:" . $create_date,
"X-Bokun-AccessKey :" . $this->access_key,
"X-Bokun-Signature :" . $bokun_signature
)
);
$set_post = strtoupper($method) === 'GET' ? false : true;
curl_setopt($curl, CURLOPT_POST, $set_post);
// curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
log_message('debug','call_bokun ' . $method . PHP_EOL . var_export($url, 1));
$output = curl_exec($curl);
if (curl_errno($curl)) {
log_message('error', "curl error code: ".curl_error($curl)."; curl call: ".$path);
} else {
$httpStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode) {
log_message('error', "Request html Status Code: ".$httpStatusCode."; curl call: ".$path);
}
}
curl_close($curl);
return $output;
}
}
/* End of file Bokun_lib.php */

@ -0,0 +1,288 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class getbokun extends CI_Controller
{
var $webUrl = "http://localhost:105";
public function __construct()
{
parent::__construct();
$this->load->library("Bokun_lib");
$this->load->model("tpBokun_model");
}
public function index()
{
//echo "bokun数据导入页面";
$this->load->view('getindex');
}
/*
"activity":{
"readme":"这个json数据用来记录从bokun接口中获取的数据项",
"id": 75363, //产品activity的ID
"published": false, //不确定是否需要用这个来判断发布
"title": "Mini Group: 2-Day Beijing Boutique Tour: Forbidden City, Mutianyu Great Wall, Summer Palace and Temple of Heaven",
"description": "",
"excerpt": "",
"requiredCustomerFields": [
"firstName",
"lastName",
"email",
"phoneNumber",
"nationality",
"passportId"
], //这个主要是判断passportId在预订表单是否需要录入
"keyPhoto": {
"id": 343309,
"originalUrl": "https://bokun.s3.amazonaws.com/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg",
"description": "Temple of Heaven",
"alternateText": "Temple of Heaven",
"height": null,
"width": null,
"flags": [],
"derived": [
{
"name": "large",
"url": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=660&h=660",
"cleanUrl": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=660&h=660"
},
{
"name": "preview",
"url": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=300&h=300",
"cleanUrl": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=300&h=300"
},
{
"name": "thumbnail",
"url": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=80&h=80&fit=crop",
"cleanUrl": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=80&h=80&fit=crop"
}
],
"fileName": "/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg"
}, //产品主要图片
"photos": [
{
"id": 343297,
"originalUrl": "https://bokun.s3.amazonaws.com/8b40e352-6410-4e43-a150-21ad918188d3.jpg",
"description": "Bird view of Forbidden City from Jingshan Park",
"alternateText": "Bird view of Forbidden City from Jingshan Park",
"height": null,
"width": null,
"flags": [],
"derived": [
{
"name": "large",
"url": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=660&h=660",
"cleanUrl": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=660&h=660"
},
{
"name": "preview",
"url": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=300&h=300",
"cleanUrl": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=300&h=300"
},
{
"name": "thumbnail",
"url": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=80&h=80&fit=crop",
"cleanUrl": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=80&h=80&fit=crop"
}
],
"fileName": "/8b40e352-6410-4e43-a150-21ad918188d3.jpg"
}
], //产品其它图片
"included": "<ul><li></li></ul> ", //包含
"excluded": "<ul><li></li></ul> ",//不包含
"requirements": "<ul><li></li></ul> ", //需求
"attention": "<ul><li></li></ul> ", //景点条例与上面4个合并到
"country": "China",
"city": "Beijing",
"durationText": "2 days",
"agendaItems": [{
"title": "",
"excerpt": "",
"body": "",
"day": 1,
"keyPhoto":{}
"photos":[{}]
}
], //行程描述,合并后放信息平台的详细内容里面,其中行程图片和整个产品图片一样,放头部
}
}
*/
/**
* @description: 获取bokunapi的所有产品数据按城市,类别,产品一步步的循环录入
* @param string $city 城市名称
* @return:
*/
function getAll_Bokun($city = "")
{
//先进行对应城市的更新
// $this->checkAllCity();
//循环接口开始
$result = $this->bokun_lib->get_all_product_list();
//print_r($result);
$result = json_decode($result);
if (is_array($result) && count($result) > 0) {
//productlist是所有产品按城市分类然后child里面是类别分类
foreach ($result as $pItem) {
$cityName = str_replace("'", "", $pItem->title); //城市名称,用来判断信息平台是否有该城市
if (isset($cityName)) {
if ($city != "" && strtolower($city) != strtolower($cityName)) {
continue; //如果设置了指定抓取城市
} else {
$list_id = $pItem->id;
$pchild_Detail = $this->bokun_lib->get_product_list_detail($list_id);
$data_pchild_Detail = json_decode($pchild_Detail); //类别详细
foreach ($data_pchild_Detail->items as $pcdItem) { //循环类别
$activityData = $pcdItem->activity; //产品详细内容
$this->doActivity($activityData, $cityName);
}
}
}
}
} else {
echo "无接口数据!";
}
}
/**
* @description: 处理每个产品activity),分析及入库
* @param {type} $ActivityData: 产品的JSON数据
* @param string $CityName:因为activity里面的城市名称和总分类的名称可能不一样比如bagan,详细里面是old bagan。直接传递
* @param bool $OverWrive:是否覆盖已导入的产品
* @return:
* @Date Changed:
*/
function doActivity($ActivityData, $CityName = "", $OverWrive = false)
{
// print_r($ActivityData);
// die();
//解析后获取需要的参数
$activityId = $ActivityData->id; //产品的activityId可以获取对应的产品详细内容。
//先判断是否是新产品
$checkNewUrl = $this->webUrl . "/guide.php/thirdparty/tpmanage/webgetbokun/checkActivityId/$activityId/";
$checkNew = json_decode($this->tpBokun_model->getCrulData($checkNewUrl));
if ($checkNew->return == "yes" && $OverWrive == false) {
return;
}
//提交网前接口
$PAGCode = "bk_" . $activityId;
$checkCode = "cits"; //用来防止参数被破解
$PassParam["activityid"] = $activityId;
$PassParam["PAG_Code"] = $PAGCode;
$PassParam["CityName"] = $CityName;
$PassParam["checkCode"] = $checkCode;
$strPass = base64_encode(json_encode($PassParam));
$AddUrl = $this->webUrl . "/guide.php/thirdparty/tpmanage/webgetbokun/addActivity/$strPass/";
$addInfo = json_decode($this->tpBokun_model->getCrulData($AddUrl));
//echo($addInfo);
if ($addInfo->status == "ok") {
//提交本地翰特保存
if ($CityName == "") {
$CityName = $ActivityData->googlePlace->city; //如果没有传递城市名称参数就获取activity数据中的
}
$PAG_CII_SN = $this->tpBokun_model->getCityIdByName($CityName);
if ($PAG_CII_SN != null) {
$this->tpBokun_model->PAG_CII_SN = $PAG_CII_SN->CII2_CII_SN;
}
$this->tpBokun_model->PAG_Code = $PAGCode;
$this->tpBokun_model->PAG_Title = $ActivityData->title;
$this->tpBokun_model->PAG_PPI_SN = $ActivityData->id;
$this->tpBokun_model->PAG2_Name = $ActivityData->title;
$this->tpBokun_model->PAG2_Title = $ActivityData->description;
$pagsn = $this->tpBokun_model->AddProductToHT();
}
}
/**
* @description: 提交到前端接口,执行更新所有城市的操作
* @param {type}
* @return:
* @Date Changed:
*/
function checkAllCity()
{
$url = "/guide.php/thirdparty/tpmanage/webgetbokun/checkAllCity/";
$str = $this->tpBokun_model->getCrulData($url);
echo $str;
}
/**
* @description: 只更新翰特的产品信息
* @param {type}
* @return:
* @Date Changed:
*/
function onlyUpdateHT($city = "")
{
//循环接口开始
$result = $this->bokun_lib->get_all_product_list();
//print_r($result);
$result = json_decode($result);
if (is_array($result) && count($result) > 0) {
//productlist是所有产品按城市分类然后child里面是类别分类
foreach ($result as $pItem) {
$cityName = str_replace("'", "", $pItem->title); //城市名称,用来判断信息平台是否有该城市
if (isset($cityName)) {
if ($city != "" && strtolower($city) != strtolower($cityName)) {
continue; //如果设置了指定抓取城市
} else {
$list_id = $pItem->id;
$pchild_Detail = $this->bokun_lib->get_product_list_detail($list_id);
$data_pchild_Detail = json_decode($pchild_Detail); //类别详细
foreach ($data_pchild_Detail->items as $pcdItem) { //循环类别
$activityData = $pcdItem->activity; //产品详细内容
//提交本地翰特保存
if ($cityName == "") {
$cityName = $activityData->googlePlace->city; //如果没有传递城市名称参数就获取activity数据中的
}
$PAG_CII_SN = $this->tpBokun_model->getCityIdByName($cityName);
if ($PAG_CII_SN != null) {
$this->tpBokun_model->PAG_CII_SN = $PAG_CII_SN->CII2_CII_SN;
}
//解析后获取需要的参数
$activityId = $activityData->id; //产品的activityId可以获取对应的产品详细内容。
//先判断是否是新产品
$checkNewUrl = $this->webUrl . "/guide.php/thirdparty/tpmanage/webgetbokun/checkActivityId/$activityId/";
$checkNew = json_decode($this->tpBokun_model->getCrulData($checkNewUrl));
if ($checkNew->return == "yes") {
continue;
}
$PAGCode = "bk_" . $activityId;
$this->tpBokun_model->PAG_Code = $PAGCode;
$this->tpBokun_model->PAG_Title = $activityData->title;
$this->tpBokun_model->PAG_PPI_SN = $activityData->id;
$this->tpBokun_model->PAG2_Name = $activityData->title;
$this->tpBokun_model->PAG2_Title = $activityData->description;
$pagsn = $this->tpBokun_model->AddProductToHT();
echo("添加:".$PAGCode."\r\n");
}
}
}
}
echo ("抓取完成 \r\n");
} else {
echo "无接口数据!";
}
}
}
/* End of file getbokun.php */

@ -0,0 +1,409 @@
<?php
/**
* 网前用的抓取程序,主要是单独处理抓取的单个产品
*/
defined('BASEPATH') or exit('No direct script access allowed');
class webgetbokun extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library("Bokun_lib");
$this->load->model("tpBokun_model");
$this->load->helper("text");
$this->load->model("InfoBokunData_model");
}
public function index()
{
}
/**
* @description: 检查是否是新的bokun产品根据infobokundata表的activityid记录
* @param {type}
* @return:
* @Date Changed:
*/
function checkActivityId($activityid)
{
$result = $this->tpBokun_model->checkActivityId($activityid);
// print_r($result);
echo $result;
return $result;
}
/**
* @description: 前端根据activityid抓取具体的产品信息并根据传递过来pag_code保存数据到信息平台
* @param string $PassParam 传递过来的参数base64
* @return:
* @Date Changed:
*/
function addActivity($PassParam)
{
$ParamData = json_decode(base64_decode($PassParam));
//print_r($ParamData);
$activityid = $ParamData->activityid;
$PAG_Code = $ParamData->PAG_Code;
$CityName = $ParamData->CityName;
$checkCode = $ParamData->checkCode;
if ($checkCode != "cits") {
return "Error"; //传递的验证code错误
} else {
//1.根据城市名称获取对应的is_id作为 父类ID
$is_id = $this->get_isid_byCity($CityName);
//2.根据$activityid 抓取接口数据
$activityDeatil = json_decode($this->bokun_lib->get_activity_detail($activityid));
$title = $activityDeatil->title;
$title_url = str_replace("'", "", strtolower($title));
$title_url = str_replace(":", "", $title_url);
$title_url = str_replace("(", " ", $title_url);
$title_url = str_replace(")", " ", $title_url);
$title_url = str_replace("/", " ", $title_url);
$title_url = str_replace("\\", " ", $title_url);
$title_url = str_replace(" ", " ", $title_url);
$title_url = str_replace(' ', '-', $title_url);
$CityName_url = str_replace("'", "", str_replace(' ', '-', strtolower($CityName)));
//3.根据抓取数据进行信息表infocontent和infostructures表的添加
$this->tpBokun_model->ic_title = $title;
$this->tpBokun_model->ic_url_title = $title;
$guideUrl = "/$CityName_url-tours/$title_url/";
$this->tpBokun_model->ic_url = $guideUrl;
//抓取数据组合成详细内容。
$arrContent = $activityDeatil->agendaItems;
$strContent = "";
foreach ($arrContent as $ContentItem) {
$strTemp = "";
if ($ContentItem->title != "") {
$strTemp .= "<h3><i class=\"fa fa-circle\" aria-hidden=\"true\"></i>" . $ContentItem->title . "</h3>";
}
if ($ContentItem->body != "") {
$strTemp .= $ContentItem->body;
}
if ($ContentItem->excerpt != "") {
$strTemp .= "<p>" . $ContentItem->excerpt . "</p>";
}
if ($strTemp != "") {
$strContent .= "<div class=\"details-list\">" . $strTemp . "</div>";
}
}
$this->tpBokun_model->ic_content = $strContent;
//简介
$temp_summary = $activityDeatil->description;
if ($activityDeatil->excerpt != "") {
$temp_summary .= "<p>" . $activityDeatil->excerpt . "</p>";
}
$this->tpBokun_model->ic_summary = $temp_summary;
//seo
$this->tpBokun_model->ic_seo_title = character_limiter($title, 100);
$this->tpBokun_model->ic_seo_description = character_limiter(strip_tags($activityDeatil->description), 200);
$tempKeywords = $activityDeatil->keywords;
if (is_array($tempKeywords) && count($tempKeywords) > 0) {
$this->tpBokun_model->ic_seo_keywords = implode(",", $tempKeywords);
}
$this->tpBokun_model->ic_status = 1;
$tempData = json_decode($this->tpBokun_model->addInfo($is_id));
if (is_array($tempData)) {
$ic_id = $tempData[0]->value->ic_id;
} else {
$result["status"] = "error";
echo json_encode($result);
}
//4.附加属性添加infometa表及新建的infoBokunData表
if ($ic_id > 0) {
//先旧的infometa表
$tempRequireFileds = $activityDeatil->requiredCustomerFields; //根据抓取的需求字段判断是否需要passport
if (is_array($tempRequireFileds)) {
if (in_array("passportId", $tempRequireFileds[0])) {
$this->tpBokun_model->addMeta($ic_id, "meta_trippest_type", "gg");
}
}
$this->tpBokun_model->addMeta($ic_id, "meta_product_code", $PAG_Code); //对应翰特编码
$this->tpBokun_model->addMeta($ic_id, "meta_facts_city", $activityDeatil->googlePlace->city); //保存一下具体城市
//然后保存新建的infobokunData表
$this->InfoBokunData_model->ibd_ic_id = $ic_id; //统一的
$this->InfoBokunData_model->ibd_ItemName = "ActivityID";
$this->InfoBokunData_model->ibd_Itemvalue = $activityid;
$ibd_id = $this->InfoBokunData_model->Add();
$this->InfoBokunData_model->ibd_parentId = $ibd_id; //设置剩余的属性都是这个activityid的子类避免每条记录都保存activityid
$this->InfoBokunData_model->ibd_ItemName = "keyPhoto"; //主要图片
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->keyPhoto->originalUrl;
$this->InfoBokunData_model->ibd_ItemType = "originalUrl";
$this->InfoBokunData_model->Add();
$arrKeyPhoto = $activityDeatil->keyPhoto->derived; //主要图片派生图,大中小类型
if (is_array($arrKeyPhoto)) {
foreach ($arrKeyPhoto as $kPhotoItem) {
$this->InfoBokunData_model->ibd_Itemvalue = $kPhotoItem->url;
$this->InfoBokunData_model->ibd_ItemType = $kPhotoItem->name;
$this->InfoBokunData_model->Add();
}
}
$arrProductPhoto = $activityDeatil->photos; //产品主要图片
if (is_array($arrProductPhoto)) {
foreach ($arrProductPhoto as $pPhotoItem) {
$this->InfoBokunData_model->ibd_ItemName = "ProductPhoto";
$this->InfoBokunData_model->ibd_Itemvalue = $pPhotoItem->originalUrl;
$this->InfoBokunData_model->ibd_ItemType = "originalUrl";
$this->InfoBokunData_model->Add();
$arrProductPhotoDerived = $pPhotoItem->derived; //产品主要图片的派生图,大中小类型
if (is_array($arrProductPhotoDerived)) {
foreach ($arrProductPhotoDerived as $pPhotoDerivedItem) {
$this->InfoBokunData_model->ibd_Itemvalue = $pPhotoDerivedItem->url;
$this->InfoBokunData_model->ibd_ItemType = $pPhotoDerivedItem->name;
$this->InfoBokunData_model->Add();
}
}
}
}
//一些FAQ类的属性如includedrequirements
$this->InfoBokunData_model->ibd_ItemName = "included"; //
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->included;
$this->InfoBokunData_model->ibd_ItemType = "";
$this->InfoBokunData_model->Add();
$this->InfoBokunData_model->ibd_ItemName = "excluded"; //
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->excluded;
$this->InfoBokunData_model->ibd_ItemType = "";
$this->InfoBokunData_model->Add();
$this->InfoBokunData_model->ibd_ItemName = "requirements"; //
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->requirements;
$this->InfoBokunData_model->ibd_ItemType = "";
$this->InfoBokunData_model->Add();
$this->InfoBokunData_model->ibd_ItemName = "attention"; //
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->attention;
$this->InfoBokunData_model->ibd_ItemType = "";
$this->InfoBokunData_model->Add();
$this->InfoBokunData_model->ibd_ItemName = "country"; //
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->googlePlace->country;
$this->InfoBokunData_model->ibd_ItemType = "";
$this->InfoBokunData_model->Add();
$this->InfoBokunData_model->ibd_ItemName = "city"; //
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->googlePlace->city;
$this->InfoBokunData_model->ibd_ItemType = "";
$this->InfoBokunData_model->Add();
$this->InfoBokunData_model->ibd_ItemName = "durationText"; //
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->durationText;
$this->InfoBokunData_model->ibd_ItemType = "";
$this->InfoBokunData_model->Add();
if ($activityDeatil->noPickupMsg != null && $activityDeatil->noPickupMsg != "") {
$this->InfoBokunData_model->ibd_ItemName = "noPickupMsg"; //
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->noPickupMsg;
$this->InfoBokunData_model->ibd_ItemType = "";
$this->InfoBokunData_model->Add();
}
if ($activityDeatil->ticketMsg != null && $activityDeatil->ticketMsg != "") {
$this->InfoBokunData_model->ibd_ItemName = "ticketMsg"; //
$this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->ticketMsg;
$this->InfoBokunData_model->ibd_ItemType = "";
$this->InfoBokunData_model->Add();
}
$arrAgendaItems = $activityDeatil->agendaItems; //保存产品行程里面的派生图片
if (is_array($arrAgendaItems)) {
foreach ($arrAgendaItems as $agendaItem) {
if ($agendaItem->keyPhoto != null && $agendaItem->keyPhoto != "") {
$this->InfoBokunData_model->ibd_ItemName = "AgendaPhoto";
$this->InfoBokunData_model->ibd_Itemvalue = $agendaItem->keyPhoto->originalUrl;
$this->InfoBokunData_model->ibd_ItemDescription = $$agendaItem->keyPhoto->description;
$this->InfoBokunData_model->ibd_ItemType = "originalUrl";
$this->InfoBokunData_model->Add();
}
$arrAgendaItemPhotos = $agendaItem->photos;
if (is_array($arrAgendaItemPhotos)) {
foreach ($arrAgendaItemPhotos as $agendaPhotoItem) {
$this->InfoBokunData_model->ibd_ItemName = "AgendaPhoto";
$this->InfoBokunData_model->ibd_Itemvalue = $agendaPhotoItem->originalUrl;
$this->InfoBokunData_model->ibd_ItemType = "originalUrl";
$this->InfoBokunData_model->ibd_ItemDescription = $agendaPhotoItem->description;
$this->InfoBokunData_model->Add();
}
}
}
}
} else {
$result["status"] = "error";
echo json_encode($result);
}
//5. 返回成功信息
$result["status"] = "ok";
$result["ic_id"] = $ic_id;
echo json_encode($result);
}
}
/**
* @description: 根据城市名称获取对应的is_id判断产品放到信息平台的位置
* @param {type}
* @return: int is_id :城市所在信息平台的Id
* @Date Changed:
*/
function get_isid_byCity($CityName)
{
$cityUrl = "/" . str_replace("'", "", str_replace(' ', '-', strtolower($CityName))) . "-" . "tours/";
$row = $this->tpBokun_model->getInfomationAll($cityUrl);
if (isset($row)) {
$result = $row->is_id;
} else {
$result = $this->tpBokun_model->is_topId;
}
return $result;
}
/**
* @description: 为了方便,首先循环添加所有的城市目录
* @param {type}
* @return:
* @Date Changed:
*/
function checkAllCity()
{
$str_return = "";
$result = $this->bokun_lib->get_all_product_list();
//print_r($result);
$result = json_decode($result);
if (is_array($result) && count($result) > 0) {
//productlist是所有产品按城市分类然后child里面是类别分类
foreach ($result as $pItem) {
$cityName = $pItem->title; //城市名称,用来判断信息平台是否有该城市
if (isset($cityName)) {
$infoCity = json_decode($this->doInfoCity($cityName)); //获取导入的城市名称为父类,下面的产品在信息平台里面放在这个的下面
if ($infoCity->type == "new") {
$str_return .= $infoCity->cityname . ",";
}
}
}
}
if ($str_return != "") {
echo "新城市添加:" . $str_return."\r\n";
} else {
echo "没有新的城市"."\r\n";
}
}
/**
* @description: 判断信息平台是否有该城市的记录,没有则添加。/beijing-tours/
* @param {type}
* @return: 返回info的is_id ,作为父类ID
* @Date Changed:
*/
function doInfoCity($CityName)
{
$cityUrl = "/" . str_replace("'", "", str_replace(' ', '-', strtolower($CityName))) . "-" . "tours/";
$infoDetail = $this->tpBokun_model->getInfomationAll($cityUrl);
if (isset($infoDetail)) {
//如果存在
$result["Id"] = $infoDetail->is_id;
$result["cityname"] = $infoDetail->ic_title;
$result["type"] = "old";
} else {
//如果不存在就录入
$this->tpBokun_model->ic_title = ucwords($CityName) . " Tours";
$this->tpBokun_model->ic_url_title = ucwords($CityName) . " Tours";
$this->tpBokun_model->ic_url = $cityUrl;
$tempData = json_decode($this->tpBokun_model->addInfo($this->tpBokun_model->is_topId));
if (is_array($tempData)) {
$result["Id"] = $tempData[0]->value->is_id;
$result["cityname"] = $CityName;
$result["type"] = "new";
} else {
$result["Id"] = 0;
$result["cityname"] = "";
$result["type"] = "error";
}
}
return json_encode($result);
}
/**
* @description: 网前只抓取信息平台的信息。由于产品的翰特编码都是yong bk_activityid的规则组成所以分开更新是可能的。这样可以保证不需要理会本地和网前的处理速度
* @param sring $city : 城市名称 。用来单独更新某个城市
* @return:
* @Date Changed:
*/
function onlyUpdateInfo($city = "")
{
//先进行对应城市的更新
$this->checkAllCity();
//循环接口开始
$result = $this->bokun_lib->get_all_product_list();
//print_r($result);
$result = json_decode($result);
if (is_array($result) && count($result) > 0) {
//productlist是所有产品按城市分类然后child里面是类别分类
foreach ($result as $pItem) {
$cityName = str_replace("'", "", $pItem->title); //城市名称,用来判断信息平台是否有该城市
if (isset($cityName)) {
if ($city != "" && strtolower($city) != strtolower($cityName)) {
continue; //如果设置了指定抓取城市
} else {
$list_id = $pItem->id;
$pchild_Detail = $this->bokun_lib->get_product_list_detail($list_id);
$data_pchild_Detail = json_decode($pchild_Detail); //类别详细
foreach ($data_pchild_Detail->items as $pcdItem) { //循环类别
$activityData = $pcdItem->activity; //产品详细内容
//解析后获取需要的参数
$activityId = $activityData->id; //产品的activityId可以获取对应的产品详细内容。
//先判断是否是新产品
$checkNew = json_decode($this->tpBokun_model->checkActivityId($activityId));
if ($checkNew->return == "yes") {
continue;
}
//提交网前接口
$PAGCode = "bk_" . $activityId;
$checkCode = "cits"; //用来防止参数被破解
$PassParam["activityid"] = $activityId;
$PassParam["PAG_Code"] = $PAGCode;
$PassParam["CityName"] = $cityName;
$PassParam["checkCode"] = $checkCode;
$strPass = base64_encode(json_encode($PassParam));
$this->addActivity($strPass);
echo "\r\n" ;
}
}
}
}
echo ("抓取完成!\r\n");
} else {
echo "无接口数据!\r\n";
}
}
}
/* End of file webgetbokun.php */

@ -0,0 +1,168 @@
<?php
class IContent_model extends CI_Model
{
var $insert_id = -1;
function __construct()
{
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
}
function Add($ic_url, $ic_url_title, $ic_type, $ic_title, $ic_content, $ic_summary, $ic_seo_title, $ic_seo_description, $ic_seo_keywords,
$ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, $ic_recommend_tours, $ic_recommend_packages,
$ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author)
{
$ic_content=str_replace('http:'.$this->config->item('site_image_url'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url_remote2'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url_org'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url2'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url_remote'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url3'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url_org2'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace('#textarea#', 'textarea',$ic_content);
$sql = "INSERT INTO infoContents \n"
. " ( \n"
. " ic_url, ic_url_title, ic_type, ic_title, ic_content, ic_summary, ic_seo_title, \n"
. " ic_seo_description, ic_seo_keywords, ic_show_bread_crumbs, ic_status, \n"
. " ic_template, ic_photo,ic_photo_width,ic_photo_height, ic_sitecode, ic_recommend_tours, ic_recommend_packages, \n"
. " ic_ht_area_id, ic_ht_area_type,ic_ht_product_id,ic_ht_product_type,ic_author, ic_datetime \n"
. " ) \n"
. "VALUES \n"
. " ( N?,N?,?,N?,N?,N?,N?,N?,N?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,getdate() )";
$query = $this->HT->query($sql,
array($ic_url, $ic_url_title, $ic_type, $ic_title, str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),
$ic_content),
$ic_summary, $ic_seo_title, $ic_seo_description, $ic_seo_keywords, $ic_show_bread_crumbs, $ic_status,
$ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, "trippest", $ic_recommend_tours, $ic_recommend_packages,
$ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author));
$this->insert_id = $this->HT->last_id('infoContents');
return $query;
}
function Update($ic_id, $ic_url, $ic_url_title, $ic_type, $ic_title, $ic_content, $ic_summary, $ic_seo_title, $ic_seo_description, $ic_seo_keywords,
$ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, $ic_recommend_tours, $ic_recommend_packages,
$ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author)
{
$ic_content=str_replace('http:'.$this->config->item('site_image_url'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url2'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url_org'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url_remote'), $this->config->item('site_image_url'),$ic_content);
$ic_content=str_replace($this->config->item('media_image_url_remote2'), $this->config->item('site_image_url'),$ic_content);
$sql = "UPDATE infoContents \n"
. "SET ic_url = N?, \n"
. " ic_url_title = N?, \n"
. " ic_type = ?, \n"
. " ic_title = N?, \n"
. " ic_content = N?, \n"
. " ic_summary = N?, \n"
. " ic_seo_title = N?, \n"
. " ic_seo_description = N?, \n"
. " ic_seo_keywords = N?, \n"
. " ic_show_bread_crumbs = ?, \n"
. " ic_status = ?, \n"
. " ic_template = ?, \n"
. " ic_photo = ?, \n"
. " ic_photo_width = ?, \n"
. " ic_photo_height = ?, \n"
. " ic_recommend_tours = ?, \n"
. " ic_recommend_packages = ?, \n"
. " ic_datetime = GETDATE() , \n"
. " ic_ht_area_id = ?, \n"
. " ic_ht_area_type = ?, \n"
. " ic_ht_product_id = ?, \n"
. " ic_ht_product_type = ?, \n"
. " ic_author = ? \n"
. "WHERE ic_id = ? \n"
. "AND ic_sitecode = ? ";
$query = $this->HT->query($sql,
array($ic_url, $ic_url_title, $ic_type, $ic_title, $ic_content, $ic_summary,
$ic_seo_title, $ic_seo_description, $ic_seo_keywords, $ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height,
$ic_recommend_tours, $ic_recommend_packages, $ic_ht_area_id,
$ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author, $ic_id,"trippest"));
return $query;
}
//删除信息
function force_update($ic_id, $ic_content)
{
$sql = "UPDATE infoContents SET ic_content = N? WHERE ic_id = ?";
$query = $this->HT->query($sql, array($ic_content, $ic_id));
return $query;
}
//删除信息
function Delete($ic_id)
{
$sql = "DELETE \n"
. "FROM infoContents \n"
. "WHERE ic_id = ?";
$query = $this->HT->query($sql, array($ic_id));
return $query;
}
//递增浏览量
function inc_views($sitecode,$page_url)
{
//查询信息需要过滤url上的域名
if($page_url && $sitecode)
{
$page_url=substr($page_url,strpos($page_url,'/',8));//过滤掉url前面的http://
$sql = "UPDATE infoContents \n"
. "SET ic_view = ISNULL(ic_view,0) + 1 \n"
. "WHERE ic_sitecode = ? AND ic_url = N?";
return $this->HT->query($sql,array($sitecode,$page_url));
}
}
public function get_ic_contents($ic_id)
{
$sql="SELECT top 1 ic_id from infoContents where ic_id=?";
$query=$this->HT->query($sql,array($ic_id));
if ($query->result())
{
$row = $query->row();
return $row;
}
else
{
return FALSE;
}
}
public function get_ic_contents2($ic_id)
{
$sql="SELECT top 1 ic_id, ic_content, ic_title, ic_url, ic_photo, ic_sitecode, ic_seo_description from infoContents where ic_id=?";
$query=$this->HT->query($sql,array($ic_id));
if ($query->result())
{
$row = $query->row();
return $row;
}
else
{
return FALSE;
}
}
public function get_ic_contents_by_list($ic_id_list)
{
$ic_id_list=trim($ic_id_list);
$ic_id_list.=0;
$sql="SELECT * from infoContents where ic_id in ($ic_id_list) order by charindex(','+ltrim(ic_id)+',', ',$ic_id_list,')";
$query=$this->HT->query($sql);
if ($query->result())
{
$row = $query->result();
return $row;
}
else
{
return FALSE;
}
}
}

@ -0,0 +1,219 @@
<?php
class IStructures_model extends CI_Model
{
var $insert_id = -1;
function __construct()
{
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
}
function Detail($is_id)
{
$sql = "SELECT TOP 1 is1.is_id, \n"
. " is1.is_parent_id, \n"
. " is1.is_path, \n"
. " is1.is_level, \n"
. " is1.is_sort, \n"
. " is1.is_sitecode, \n"
. " is1.is_datetime, \n"
. " is1.is_ic_id \n"
. "FROM infoStructures is1 \n"
. "WHERE is1.is_id = ?";
$query = $this->HT->query($sql, array($is_id));
//print_r($this->HT->queries);
if ($query->result())
{
$row = $query->row();
return $row;
}
else
{
return FALSE;
}
}
function Add($is_parent_id, $is_ic_id=-1)
{
if ($is_parent_id == 0)
{
$is_path = '';
$is_level = 1;
$is_sort = 999;
}
else
{
$infoStructure = $this->Detail($is_parent_id);
if ($infoStructure)
{
$is_path = $infoStructure->is_path;
$is_level = $infoStructure->is_level + 1;
$is_sort = 999;
}
else
{
return false;
}
}
$sql = "INSERT INTO infoStructures \n"
. " ( \n"
. " is_parent_id, is_path, is_level, is_sort, is_sitecode, is_datetime, is_ic_id \n"
. " ) \n"
. "VALUES \n"
. " ( \n"
. " ?, ?, ?, ?, ?, getdate(), ? \n"
. " )";
$query = $this->HT->query($sql, array($is_parent_id, $is_path, $is_level, $is_sort, "trippest", $is_ic_id));
$this->insert_id = $this->HT->last_id('infoStructures');
//把自己的ID加到path上
$set_sql = "UPDATE infoStructures \n"
. "SET is_path = is_path + CONVERT(VARCHAR(200), is_id) + ',' \n"
. "WHERE is_id = ?";
$query = $this->HT->query($set_sql, array($this->insert_id));
return $this->insert_id;
}
function GetParent($is_path, $level=1)
{
if ($is_path == '')
{
return false;
}
$sql = "SELECT TOP 1 is1.is_id, \n"
. " is1.is_parent_id, \n"
. " is1.is_path, \n"
. " is1.is_level, \n"
. " is1.is_sort, \n"
. " is1.is_sitecode, \n"
. " is1.is_datetime, \n"
. " is1.is_ic_id \n"
. "FROM infoStructures is1 \n"
. "WHERE is1.is_level = ? \n"
. " AND is1.is_id IN ($is_path 0) \n"
. "ORDER BY \n"
. " is1.is_id ASC";
$query = $this->HT->query($sql, array($level));
// print_r($this->HT->queries);
if ($query->result())
{
$row = $query->row();
return $row;
}
else
{
return FALSE;
}
}
//查询节点的根节点
function get_root($is_id)
{
$detail = $this->Detail($is_id);
$root = $this->GetParent($detail->is_path, 1);
if ($root)
{
return $root;
}
else
{ //没有根节点则返回本节点
return $detail;
}
}
//判断是否有子节点
function HasChild($is_id)
{
$sql = "SELECT TOP 1 is1.is_id \n"
. "FROM infoStructures is1 \n"
. "WHERE is1.is_parent_id = ?";
$query = $this->HT->query($sql, array($is_id));
if ($query->result())
{
return true;
}
else
{
return FALSE;
}
}
//删除节点
function Delete($is_id)
{
$sql = "DELETE \n"
. "FROM infoStructures \n"
. "WHERE is_id = ?";
$query = $this->HT->query($sql, array($is_id));
return $query;
}
//设置排序
function set_sort($is_id, $sort)
{
$sql = "UPDATE infoStructures \n"
. "SET is_datetime = GETDATE(), \n"
. " is_sort = ? \n"
. "WHERE is_id = ?";
$query = $this->HT->query($sql, array($sort, $is_id));
//print_r($this->HT->queries);
return $query;
}
//设置路径
function set_path($parent_id, $is_id)
{
$structure = $this->Detail($is_id);
//如果父级相同则不需要重新设置path
if ($parent_id == $structure->is_parent_id)
{
return true;
}
$parent = $this->Detail($parent_id);
//设置当前节点
$set_parent_id = $parent->is_id;
$set_level = $parent->is_level + 1;
$set_path = $parent->is_path . $is_id . ',';
$set_sql = "UPDATE infoStructures \n"
. "SET is_parent_id = ?, \n"
. " is_level = ?, \n"
. " is_path = ? \n"
. "WHERE is_id = ?";
$this->HT->query($set_sql, array($set_parent_id, $set_level, $set_path, $is_id));
$structure = $this->Detail($is_id);
//查询当前节点的所有子节点
$sql = "SELECT is1.is_id, \n"
. " is1.is_parent_id, \n"
. " is1.is_path, \n"
. " is1.is_level, \n"
. " is1.is_sort \n"
. "FROM infoStructures is1 \n"
. "WHERE ',' + is1.is_path LIKE '%,$structure->is_id,%' \n"
. "ORDER BY \n"
. " is1.is_level ASC ";
$query = $this->HT->query($sql);
foreach ($query->result() as $item)
{
if ($item->is_parent_id != $structure->is_id)
{
$structure = $this->Detail($item->is_parent_id);
}
$set_parent_id = $structure->is_id;
$set_level = $structure->is_level + 1;
$set_path = $structure->is_path . $item->is_id . ',';
$set_sql = "UPDATE infoStructures \n"
. "SET is_parent_id = ?, \n"
. " is_level = ?, \n"
. " is_path = ? \n"
. "WHERE is_id = ?";
$this->HT->query($set_sql, array($set_parent_id, $set_level, $set_path, $item->is_id));
}
}
}

@ -0,0 +1,292 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class TpBokun_model extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
$this->load->model("IContent_model");
$this->load->model("IStructures_model");
$CI = &get_instance();
}
/**
* 获取信息平台的内容,所有信息,包含发布和没发布的
*/
function getInfomationAll($guideurl)
{
// $sql = "select top 1 * from infoContents a inner join infoStructures b on a.ic_id=b.is_ic_id where ic_URL='".$guideurl."' and ic_status=1 and is_siteCode='ct'";
$sql = "select top 1 * from infoContents a inner join infoStructures b on a.ic_id=b.is_ic_id where ic_URL='" . $guideurl . "' and is_siteCode='" . Site_Code . "'";
$query = $this->HT->query($sql);
if ($query->num_rows() > 0) {
return $query->row();
} else {
return null;
}
}
/**
* @description: 检查是否是新的bokun产品根据infobokundata表的activityid记录
* @param {type}
* @return:
* @Date Changed:
*/
function checkActivityId($activityid)
{
$sql = "select top 1 * from infobokundata where ibd_itemname='ActivityID' and CONVERT(varchar(100),ibd_itemvalue)=?";
$query = $this->HT->query($sql, array($activityid));
if ($query->num_rows() > 0) {
$result["return"] = "yes";
} else {
$result["return"] = "no";
}
return json_encode($result);
}
/**
* @description: 根据城市名称获取城市ID
* @param string $cityname:城市名称
* @return:
* @Date Changed:
*/
function getCityIdByName($cityname)
{
$sql = "select top 1 CII2_CII_SN from CItyInfo2 where CII2_Name = '" . $cityname . "' and CII2_LGC=1";
$query = $this->HT->query($sql);
if ($query->num_rows() > 0) {
return $query->row();
} else {
return null;
}
}
/**-------------------抓取程序------------------------- */
var $is_topId = "278000665"; //产品的最高级父类
//ic_content表的字段
var $ic_url = "";
var $ic_url_title = "New Information";
var $ic_type = "";
var $ic_title = "";
var $ic_content = "";
var $ic_summary = "";
var $ic_seo_title = "";
var $ic_seo_description = "";
var $ic_seo_keywords = "";
var $ic_show_bread_crumbs = 0;
var $ic_status = 0;
var $ic_template = "";
var $ic_photo = "";
var $ic_photo_width = 0;
var $ic_photo_height = 0;
var $ic_recommend_tours = "";
var $ic_recommend_packages = "";
var $ic_ht_area_id = 0;
var $ic_ht_area_type = "";
var $ic_ht_product_id = 0;
var $ic_ht_product_type = "";
var $ic_author = "";
/**
* @description: 添加一条信息平台信息
* @param string $PAG_Code 翰特产品的编码
* @return:
* @Date Changed:
*/
public function addInfo($is_parent_id, $PAG_Code = "")
{
if ($is_parent_id == $this->is_topId) {
//这个是城市级别的数据添加
} else {
//产品添加
}
//添加.
$this->IContent_model->Add(
$this->ic_url,
$this->ic_url_title,
$this->ic_type,
$this->ic_title,
$this->ic_content,
$this->ic_summary,
$this->ic_seo_title,
$this->ic_seo_description,
$this->ic_seo_keywords,
$this->ic_show_bread_crumbs,
$this->ic_status,
$this->ic_template,
$this->ic_photo,
$this->ic_photo_width,
$this->ic_photo_height,
$this->ic_recommend_tours,
$this->ic_recommend_packages,
$this->ic_ht_area_id,
$this->ic_ht_area_type,
$this->ic_ht_product_id,
$this->ic_ht_product_type,
$this->ic_author
);
$infocontent = $this->IContent_model->get_ic_contents($this->IContent_model->insert_id);
if (!empty($infocontent) && $this->IStructures_model->Add($is_parent_id, $this->IContent_model->insert_id)) {
$is_id = $this->IStructures_model->insert_id;
$InfoStructures = $this->IStructures_model->Detail($is_id);
$InfoStructures->is_id = $is_id;
$InfoStructures->ic_id = $infocontent->ic_id;
$data[] = array('name' => 'ok', 'value' => $InfoStructures);
} else {
$data[] = array('name' => 'no', 'value' => 'form_info_error');
}
return json_encode($data);
}
/**---------Meta表的操作----------- */
function addMeta($im_ic_id, $im_key, $im_value)
{
$sql = "INSERT INTO infoMetas \n"
. " ( \n"
. " im_ic_id, im_key, im_value \n"
. " ) \n"
. "VALUES \n"
. " ( \n"
. " ?, ?, N? \n"
. " )";
return $this->HT->query($sql, array($im_ic_id, $im_key, (string) $im_value));
}
/**----------翰特入库--------------- */
var $pag_sn;
var $PAG_CII_SN = 0;
var $PAG_Code = "";
var $PAG_Scheme = "1,2,3,4,5,6,7";
var $PAG_Title = "";
var $PAG_DEI_SN = "34";
var $PAG_PPI_SN = 0; //存放activityid
var $PAG2_LGC = 1;
var $PAG2_Name = "";
var $PAG2_Title = "";
/**
* @description: 添加产品信息到翰特
* @param {type}
* @return:
* @Date Changed:
*/
function AddProductToHT()
{
$sql = "
INSERT INTO [BIZ_PackageInfo]
([PAG_CII_SN]
,[PAG_Code]
,[PAG_Scheme]
,[CreatTime]
,[PAG_Title]
,[PAG_DEI_SN]
,[PAG_PPI_SN]
)
VALUES
( ?,?,?,GETDATE(),?,?,?)
";
$query = $this->HT->query($sql, array(
$this->PAG_CII_SN,
$this->PAG_Code,
$this->PAG_Scheme,
$this->PAG_Title,
$this->PAG_DEI_SN,
$this->PAG_PPI_SN
));
$this->pag_sn = $this->HT->query("select max(pag_sn) as pag_sn from BIZ_PackageInfo")->row("pag_sn");
//插入语种表
$sql2 = "
INSERT INTO [BIZ_PackageInfo2]
([PAG2_PAG_SN]
,[PAG2_LGC]
,[PAG2_Name]
,[PAG2_Title]
)
VALUES
(?,?,?,?)
";
//录入中,英两个语种
for ($i = 1; $i < 3; $i++) {
$this->HT->query($sql2, array(
$this->pag_sn,
$i,
$this->PAG2_Name,
$this->PAG2_Title
));
}
return $this->pag_sn;
}
/**------其它一些公用函数--- */
/**
* @description: 抓取页面程序
* @param string $url 抓取地址
* @param string $data 传递的参数
* @return:
* @Date Changed:
*/
function getCrulData($url, $data = '', $method = 'GET')
{
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
if ($method == 'POST' && !empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
}
curl_setopt($curl, CURLOPT_TIMEOUT, 40); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_TIMEOUT_MS, 40000); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$tmpInfo = curl_exec($curl); // 执行操作
$errno = curl_errno($curl);
if ($errno !== 0) {
return false;
echo $errno . curl_error($curl); //记录错误日志
}
curl_close($curl); //关闭CURL会话
return $tmpInfo; //返回数据
}
/**
* @description: 过滤掉特殊字符
* @param {type}
* @return:
* @Date Changed:
*/
function match_chinese($chars,$encoding='utf8'){
$pattern =($encoding=='utf8')?'/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u':'/[\x80-\xFF]/';
preg_match_all($pattern,$chars,$result);
return join('',$result[0]);
}
}
/* End of file TpBokun_model.php */

@ -0,0 +1,55 @@
<div class="col-sm-5 well">
</div>
<div class="col-sm-18">
<div class="panel panel-default">
<div class="panel-heading">抓取Bokun数据</div>
<div class="panel-body">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-striped">
<tr>
<td width="120">&nbsp;</td>
<td width="300">
<div class="progress">
<div id="pros" class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
</div>
</div>
<div class="form_submit">
<button type="button" class="btn btn-success" id="trigger_ajax">test</button>
</div>
</td>
<td>&nbsp;
<P>由于涉及HT所以更新主程序需要运行在本地http://202.103.68.144:65008/info.php/thirdparty/tpmanage/getbokun/,网前信息平台的有另外单独的更新程序。</P>
<p>第一步,可以先单独抓取更新所有的城市信息,这样可以先保证城市信息的完整。</p>
<p><a href="/info.php/thirdparty/tpmanage/getbokun/checkAllCity/">点击更新所有城市信息</a></p>
<p style="display: none;"></p>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td id="msg_1">请等待:当前进度:<span>0%</span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3" id="msg_1a"></td>
</tr>
</table>
</div>
</div>
</div>
<script type="text/javascript">
var trigger = document.getElementById("trigger_ajax");
trigger.onclick = function(){
var xhr = new XMLHttpRequest();
xhr.onprogress = function(event){
if(event.lengthComputable){
var loaded = parseInt(event.loaded/event.total*100)+"%";
$('#pros').width(loaded);
$('#pros').text(loaded);
}
}
xhr.open("post", "/info.php/thirdparty/updatetrain/updatestation/test/", true);
xhr.send(null);
}
</script>
Loading…
Cancel
Save