bokun抓取的程序
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,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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue