如果你还是“程序员”,我劝你别创业!
很多程序员一看就知道不会创业
“程序员思维”会害死你!
在IT这一行做得久了,会接触到无数让人哭笑不得的外行话。
「我们就差一个写代码的了」是其中典型的一种,之所以黑它,不是因为程序员有多自大,认为自己被轻视所以愤怒。而是因为说这句话的人里有90%以上绝对不仅仅差一个写代码的,而是一整套技术体系。
那么,程序员在创业公司之中真的这么重要吗???
很多程序员一看就知道不会创业
“程序员思维”会害死你!
在IT这一行做得久了,会接触到无数让人哭笑不得的外行话。
「我们就差一个写代码的了」是其中典型的一种,之所以黑它,不是因为程序员有多自大,认为自己被轻视所以愤怒。而是因为说这句话的人里有90%以上绝对不仅仅差一个写代码的,而是一整套技术体系。
那么,程序员在创业公司之中真的这么重要吗???
<?php
/**
* 百度 LBS云图数据接口
* Author: IceCry <http://www.zhinizhiwo.com>
* Date: 2017-10-14 15:51
*
* 云存储使用V3 V4暂不支持云检索
* 暂不使用sn签名
* 百度LBS.云 http://lbsyun.baidu.com/index.php?title=lbscloud
*/
namespace ice;
class Bmap
{
private static $ak;
private static $tableid;
public function __construct($ak='', $tableid=0) {
if($ak===''){
die('ak required !');
}
self::$ak = $ak;
self::$tableid = $tableid;
}
/**
* 创建位置数据表
*
* @param <type> $name 中文表名
* @param integer $geotype 数据类型 1点 2线(暂不支持) 3面
* @param integer $is_published 是否发布到云检索 1自动发布到检索
*/
public function create_table($name, $geotype=1, $is_published=0, $sn='', $timestamp=0)
{
$url = 'http://api.map.baidu.com/geodata/v3/geotable/create';
$data = [
'ak' => self::$ak,
'name' => $name,
'geotype' => $geotype,
'is_published' => $is_published
];
$res = $this->https_request($url, $data);
return $res;
}
/**
* 查询表
*
* @param string $name 表名 可选
* @param string $sn 签名
*
* @return <type> ( description_of_the_return_value )
*/
public function search_table($name='', $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/geotable/list';
$data = [
'ak' => self::$ak,
'name' => $name
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 查询指定id表
*
* @param integer $id id
* @param string $sn sn
*
* @return <type> ( description_of_the_return_value )
*/
public function search_id($id=0, $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/geotable/detail';
$data = [
'ak' => self::$ak,
'id' => $id
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 修改表
*
* @param integer $id 表id
* @param integer $is_published 是否为云检索
* @param string $name 表名
* @param string $sn The serial number
*
* @return <type> ( description_of_the_return_value )
*/
public function update_table($id=0, $is_published=0, $name='', $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/geotable/update';
$data = [
'ak' => self::$ak,
'id' => $id,
'name' => $name,
'is_published' => $is_published,
'sn' => $sn
];
$res = $this->https_request($url, $data);
return $res;
}
/**
* 删除表 只能删除空表
*
* @param integer $id 表id
* @param string $sn The serial number
*/
public function delete_table($id=0, $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/geotable/delete';
$data = [
'ak' => self::$ak,
'id' => $id,
'sn' => $sn
];
$res = $this->https_request($url, $data);
return $res;
}
/**
* 创建/更新列
*
* @param string $name 中文列名
* @param string $key 列名
* @param integer $type 值类型 枚举值1:Int64, 2:double, 3:string, 4:在线图片url
* @param integer $max_length 最大长度 1-2048 type为string有效 汉字数
* @param string $default_value 默认值
* @param integer $is_sortfilter_field 是否排序筛选
* @param integer $is_search_field 是否文本检索
* @param integer $is_index_field 是否存储引擎的索引字段
* @param integer $is_unique_field 是否唯一索引
* @param string $sn 权限签名
*/
public function deal_column($id=0, $name='', $key='', $type=0, $max_length=0, $default_value='', $is_sortfilter_field=0, $is_search_field=0, $is_index_field=0, $is_unique_field=0, $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/column/create';
$data = [
'ak' => self::$ak,
'name' => $name,
'key' => $key,
'type' => $type,
'max_length' => $max_length,
'default_value' => $default_value,
'is_sortfilter_field' => $is_sortfilter_field,
'is_search_field' => $is_search_field,
'is_index_field' => $is_index_field,
'is_unique_field' => $is_unique_field,
'geotable_id' => self::$tableid,
'sn' => $sn
];
//如果存在id则更新
if($id){
$url = 'http://api.map.baidu.com/geodata/v3/column/update';
$data['id'] = $id;
}
$res = $this->https_request($url, $data);
return $res;
}
/**
* 查询列
*
* @param string $name 表名 可选
* @param string $key 属性key
* @param string $sn 签名
*
* @return <type> ( description_of_the_return_value )
*/
public function search_column($name='', $key='', $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/column/list';
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'name' => $name,
'key' => $key,
'sn' => $sn
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 查询指定id列数据
*
* @param integer $id The identifier
* @param string $sn The serial number
*/
public function search_column_id($id=0, $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/column/detail';
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'id' => $id,
'sn' => $sn
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 删除指定列
*
* @param integer $id 列id
* @param string $sn 签名
*
* @return <type> ( description_of_the_return_value )
*/
public function delete_column($id=0, $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/column/delete';
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'id' => $id,
'sn' => $sn
];
$res = $this->https_request($url, $data);
return $res;
}
/**
* 创建地理位置
*
* @param string $title poi名称
* @param string $address 地址
* @param string $tags 标签
* @param <type> $latitude 纬度
* @param <type> $longitude 经度
* @param integer $coord_type 坐标类型 1:GPS经纬度坐标 2:国测局加密经纬度坐标 3:百度加密经纬度坐标 4:百度加密墨卡托坐标
* @param string $diy 自定义数据
* @param string $sn 签名
* @param string $diyvalue 自定义唯一索引key
*/
public function deal_poi($id=0, $title='', $address='', $tags='', $latitude, $longitude, $coord_type=3, $diy=array(), $sn='', $diyvalue='')
{
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'title' => $title,
'address' => $address,
'tags' => $tags,
'latitude' => $latitude,
'longitude' => $longitude,
'coord_type' => $coord_type
];
$url = 'http://api.map.baidu.com/geodata/v3/poi/create';
if($id){
$url = 'http://api.map.baidu.com/geodata/v3/poi/update';
$data['id'] = $id;
}
$data = array_merge($data, $diy);
$res = $this->https_request($url, $data);
return $res;
}
/**
* 查询指定条件poi
*
* @param array $diy 自定义数据 is_index_field=1 string加$精准匹配
* @param string $title 标题
* @param string $tags 标签
* @param string $bounds 矩形区域
* @param integer $page_index 分页
* @param integer $page_size 页面大小
* @param string $sn 签名
*/
public function search_poi_list($diy=[], $title='', $tags='', $bounds='', $page_index=0, $page_size=10, $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/poi/list';
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'title' => $title,
'tags' => $tags,
'bounds' => $bounds,
'page_index' => $page_index,
'page_size' => $page_size
];
$data = array_merge($data, $diy);
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 查询指定id的数据
*
* @param integer $id id
* @param string $sn 签名
*
* @return <type> ( description_of_the_return_value )
*/
public function search_id_poi($id=0, $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/poi/detail';
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'id' => $id
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 删除poi 支持批量删除
*
* @param integer $id 删除单条 存在则其他条件无效
* @param string $diyvalue 自定义唯一索引
* @param string $ids 删除id列表1,2,3 批量删除尽可能使用此方法 <1000
* @param array $diyIndex 用户自定义 需设置is_index_field=1
* @param string $title 名称
* @param string $tags 标签
* @param string $bounds 矩形区域
* @param array $diyColumn 自定义
* @param integer $is_total_del 标记为批量删除 若仅设置为1不指定条件则删除全表
* @param string $sn 签名
*/
public function delete_poi($id=0, $diyvalue='', $ids='', $diyIndex=array(), $title='', $tags='', $bounds='', $diyColumn=array(), $is_total_del=0, $sn='')
{
$url = 'http://api.map.baidu.com/geodata/v3/poi/delete';
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'id' => $id,
'diyvalue' => $diyvalue,
'ids' => $ids,
'title' => $title,
'tags' => $tags,
'bounds' => $bounds,
'is_total_del' => $is_total_del
];
$arr = array_merge($diyIndex, $diyColumn);
$data = array_merge($data, $arr);
if(!$id){
unset($data['id']);
}
$res = $this->https_request($url, $data);
return $res;
}
/**
* 批量上传数据 暂无用 每日限调用25次
*/
public function create_multi_data()
{
$url = 'http://api.map.baidu.com/geodata/v3/poi/upload';
}
/**
* 批量上传进度查询接口 暂无用
*/
public function create_multi_progress()
{
$url = '';
}
/**
* 批量操作查询结果 暂无用
*/
public function multi_job_search()
{
}
/**
* 云检索 周边检索
*
* @param string $q 检索关键词
* @param string $location 经纬度
* @param integer $coord_type 坐标系 3百度经纬度
* @param integer $radius 检索半径
* @param string $tags 标签
* @param string $sortby 排序字段
* @param string $filter 过滤条件
* @param integer $page_index 分页索引
* @param integer $page_size 分页数量
* @param string $callback 回调函数
* @param string $sn
*
* @return <type> ( description_of_the_return_value )
*/
public function search_nearby($q='', $location='', $coord_type=3, $radius=1000, $tags='', $sortby='', $filter='', $page_index=0, $page_size=10, $callback='', $sn='')
{
$url = 'http://api.map.baidu.com/geosearch/v3/nearby';
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'q' => $q,
'location' => $location,
'coord_type' => $coord_type,
'radius' => $radius,
'tags' => $tags,
'sortby' => $sortby,
'filter' => $filter,
'page_index' => $page_index,
'page_size' => $page_size
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 云检索 本地检索
*
* @param string $q 查询字符
* @param integer $coord_type 坐标类型
* @param string $region 检索区域 默认全国
* @param string $tags 标签
* @param string $sortby 排序
* @param string $filter 过滤
* @param integer $page_index 分页索引
* @param integer $page_size 分页数量
* @param string $callback 回调函数
* @param string $sn The serial number
*/
public function search_local($q='', $coord_type=3, $region='', $tags='', $sortby='', $filter='', $page_index=0, $page_size=10, $callback='', $sn='')
{
$url = 'http://api.map.baidu.com/geosearch/v3/local';
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'q' => $q,
'coord_type' => $coord_type,
'region' => $region,
'tags' => $tags,
'sortby' => $sortby,
'filter' => $filter,
'page_index' => $page_index,
'page_size' => $page_size
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 云检索 矩形检索
*
* @param string $q 查询内容
* @param string $bounds 矩形区域
* @param string $tags The tags
* @param integer $coord_type The coordinate type
* @param string $sortby The sortby
* @param string $filter The filter
* @param integer $page_index The page index
* @param integer $page_size The page size
* @param string $callback The callback
* @param string $sn The serial number
*
* @return <type> ( description_of_the_return_value )
*/
public function search_bound($q='', $bounds='', $tags='', $coord_type=3, $sortby='', $filter='', $page_index=0, $page_size=10, $callback='', $sn='')
{
$url = 'http://api.map.baidu.com/geosearch/v3/bound';
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'q' => $q,
'bounds' => $bounds,
'tags' => $tags,
'coord_type' => $coord_type,
'sortby' => $sortby,
'filter' => $filter,
'page_index' => $page_index,
'page_size' => $page_size
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 云检索 poi详情检索
*
* @param integer $uid poi点的id值
* @param integer $coord_type The coordinate type
* @param string $sn The serial number
*
* @return <type> ( description_of_the_return_value )
*/
public function search_poi_detail($uid=0, $coord_type=3, $sn='')
{
$url = 'http://api.map.baidu.com/geosearch/v3/detail/'.$uid;
$data = [
'ak' => self::$ak,
'geotable_id' => self::$tableid,
'coord_type' => $coord_type
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* curl
*
* @param <type> $url The url
* @param <type> $data The data
* @param <type> $isget 是否为get请求
*
* @return <type> ( description_of_the_return_value )
*/
public function https_request($url, $data = null, $isget = false)
{
$headers = array(
'Cache-Control:no-cache',
'Pragma:no-cache'
);
if($isget){
$url .= '?';
if(is_array($data)){
$url .= http_build_query($data);
}elseif(is_string($data)) {
$url .= $data;
}
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT,3);
if (!empty($data) && !$isget){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}
TP5 位置:/extends/ice/Amap.php 使用:use ice\Amap
<?php
/**
* 高德云图数据接口
* Author: IceCry <http://www.zhinizhiwo.com>
* Date: 2017-10-14 09:01
*/
namespace ice;
class Amap
{
private static $key;
private static $tableid;
public function __construct($key='', $tableid='') {
if($key===''){
die('key required !');
}
self::$key = $key;
self::$tableid = $tableid;
}
/**
* 创建云图数据表
*
* @param <type> $name 表名
* @param <type> $name 数字前面
*
* http://yuntuapi.amap.com/datamanage/table/create
* 返回值 status info tableid
*/
public function create_table($name='', $sig='')
{
$name = $name ? $name : date('YmdHis');
$url = "http://yuntuapi.amap.com/datamanage/table/create";
$data = [
'key' => self::$key,
'name' => $name,
'sig' => $sig
];
$res = $this->https_request($url, $data);
return $res;
}
/**
* 创建单条位置信息
*
* @param <type> $loctype 定位方式 1经纬度 2地址
* @param <type> $_location 经纬度
* @param <type> $_address 地址
* @param <type> $_name 数据名称
* @param <type> $coordtype 坐标类型 1: gps 2: autonavi 3: baidu
* @param <type> $sig 数字签名
* @param <type> $diy 用户自定义数据
*
* http://yuntuapi.amap.com/datamanage/data/create
* 返回值 status info _id
*/
public function deal_single_data($loctype=1, $_location='', $_address='', $_name='', $coordtype='3', $sig='', $diy=array(), $isUpdate=false)
{
$url = 'http://yuntuapi.amap.com/datamanage/data/create';
if($isUpdate){
$url = 'http://yuntuapi.amap.com/datamanage/data/update';
}
//基础信息 仅处理经纬度方式
$info = [
'_name' => $_name,
'_location' => $_location,
'coordtype' => $coordtype,
'_address' => $_address,
];
$info = json_encode(array_merge($info, $diy));
$data = [
'key' => self::$key,
'tableid' => self::$tableid,
'loctype' => $loctype,
'data' => $info
];
$res = https_request($url, $data);
return $res;
}
/**
* 暂无用 使用高德后台上传
*/
public function add_multi_data()
{
}
/**
* 删除单条/多条数据
*
* @param string $ids 数据1-50条 _id 1,3,4
* @param string $sig The signal
*
* 返回值 status info success fail成功/失败条数
*/
public function delete_data($ids='', $sig='')
{
$url = "http://yuntuapi.amap.com/datamanage/data/delete";
$data = [
'key' => self::$key,
'tableid' => self::$tableid,
'ids' => $ids,
'sig' => $sig
];
$res = $this->https_request($url, $data);
$res = json_decode($res);
return $res;
}
/**
* 获取批量处理进度 暂无用
*/
public function get_import_status()
{
}
/**
* 云检索 本地检索
*
* @param string $keywords 搜索关键词
* @param string $city 中文城市
* @param string $filter 过滤条件
* @param string $sortrule 排序规则
* @param string $limit 分页条数
* @param string $page 当前页
* @param string $sig 数字签名
*/
public function search_local($keywords=' ', $city='全国', $filter='', $sortrule='', $limit=10, $page=1, $sig='')
{
$url = 'http://yuntuapi.amap.com/datasearch/local';
$data = [
'key' => self::$key,
'tableid' => self::$tableid,
'keywords' => $keywords,
'city' => $city,
'filter' => $filter,
'sortrule' => $sortrule,
'limit' => $limit,
'page' => $page,
'sig' => $sig
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 云检索 周边检索
*
* @param string $keywords 搜索关键词
* @param string $center 中心经纬度
* @param string $radius 查询半径
* @param string $filter 过滤条件
* @param string $sortrule 排序规则
* @param string $limit 分页条数
* @param string $page 当前页
* @param string $sig 数字签名
*/
public function search_around($keywords=' ', $center='119.168162,36.713983', $radius='3000', $filter='', $sortrule='', $limit=10, $page=1, $sig='')
{
$url = 'http://yuntuapi.amap.com/datasearch/around';
$data = [
'key' => self::$key,
'tableid' => self::$tableid,
'keywords' => $keywords,
'center' => $center,
'radius' => $radius,
'filter' => $filter,
'sortrule' => $sortrule,
'limit' => $limit,
'page' => $page,
'sig' => $sig
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 多边形检索 暂无用
*/
public function search_polygon()
{
}
/**
* 云检索 id检索(poi详情检索)
*
* @param string $_id 地图数据id
* @param string $sig 数字签名
*
* @return <type> ( description_of_the_return_value )
*/
public function search_id($_id='', $sig='')
{
$url = 'http://yuntuapi.amap.com/datasearch/id';
$data = [
'key' => self::$key,
'tableid' => self::$tableid,
'_id' => $_id,
'sig' => $sig
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 云检索 按条件检索数据(可遍历整表数据)
*
* @param string $filter 过滤条件
* @param string $sortrule 排序规则
* @param string $limit 分页条数
* @param string $page 当前页
* @param string $sig 数字签名
*/
public function search_by_condition($filter='', $sortrule='', $limit=10, $page=1, $sig='')
{
$url = 'http://yuntuapi.amap.com/datamanage/data/list';
$data = [
'key' => self::$key,
'tableid' => self::$tableid,
'filter' => $filter,
'sortrule' => $sortrule,
'limit' => $limit,
'page' => $page,
'sig' => $sig
];
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* 云检索 数据分布检索
*
* @param string $keywords 搜索关键词
* @param string $center 中心经纬度
* @param string $radius 查询半径
* @param string $filter 过滤条件
* @param string $sortrule 排序规则
* @param string $limit 分页条数
* @param string $page 当前页
* @param string $sig 数字签名
*/
public function search_area_count($keywords=' ', $type='', $country='中国', $province='', $city='', $filter='', $sig='', $callback='cb')
{
$data = [
'key' => self::$key,
'tableid' => self::$tableid,
'filter' => $filter,
// 'callback' => $callback,
'sig' => $sig
];
switch ($type) {
case 'province':
$url = 'http://yuntuapi.amap.com/datasearch/statistics/province';
$data['country'] = $country;
break;
case 'city':
$url = 'http://yuntuapi.amap.com/datasearch/statistics/city';
$data['province'] = $province;
break;
case 'district':
$url = 'http://yuntuapi.amap.com/datasearch/statistics/district';
$data['province'] = $province;
$data['city'] = $city;
break;
default:
$url = '';
break;
}
$res = $this->https_request($url, $data, true);
return $res;
}
/**
* curl
*
* @param <type> $url The url
* @param <type> $data The data
* @param <type> $isget 是否为get请求
*
* @return <type> ( description_of_the_return_value )
*/
public function https_request($url, $data = null, $isget = false)
{
$headers = array(
'Cache-Control:no-cache',
'Pragma:no-cache'
);
if($isget){
$url .= '?';
if(is_array($data)){
$url .= http_build_query($data);
}elseif(is_string($data)) {
$url .= $data;
}
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT,3);
if (!empty($data) && !$isget){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}
Vue.js 入坑笔记
表单中keyup事件自动检索数据中,考虑性能需延迟处理按键事件,无需每次keyup均执行异步请求。
利用event的timeStamp来标记时间,这样每次的keyup事件都会修改last的值,注意last必需为全局变量。如果时间差为0(也就是你停止输入1s之内都没有其它的keyup事件发生)则执行。
需处理that=$(this);,否则报错Cannot read property 'toLowerCase' of undefined
基础代码如下:
var oldtime;
$('input[name=dept]').keyup(function(event){
oldtime = event.timeStamp;
that=$(this);
setTimeout(function(){
if((oldtime-event.timeStamp)==0){
var name = that.val();
$.ajax({
url:"{:U('Dept/ajax_get_dept')}",
type: "post",
async: false,
data: {'keyword':name},
dataType:"html",
success: function (data) {
console.log(data);
}
});
}
},500);
})
系统-SQL命令行工具-多行命令
delete from dede_addonarticle;
delete from dede_addonimages;
delete from dede_archives;
delete from dede_arctiny;
delete from dede_co_htmls;
delete from dede_co_urls;
delete from dede_co_mediaurls;
delete from dede_tagindex ;
delete from dede_taglist;
delete from dede_keywords;
TRUNCATE TABLE `dede_archives`;
TRUNCATE TABLE `dede_archives`;
ALTER TABLE `dede_archives` AUTO_INCREMENT =1;
ALTER TABLE `dede_arctiny` AUTO_INCREMENT =1;
ALTER TABLE `dede_addonarticle` AUTO_INCREMENT =1;
工作过程需要定时查询某些关键在百度、360及搜狗中的排序,于是写了一个简单的查询类,有更好的方法或错误可以回复交流。
基本思路:根据关键词搜索结果匹配所在页面中的排序值
ThinkPHP5 /extend/org/util/KeyRank.php
<?php
namespace org\util;
error_reporting(E_ALL & ~E_NOTICE);
/**
* 获取关键词在百度、360、搜狗排名
*
* Author: IceCry <http://www.zhinizhiwo.com>
*
* @param string $key 检测关键字
* @param string $url 检测域名
* @param integer $deep 页面深度
* @param integer $start 起始页面
* @param integer $trytime尝试次数
*
* @return integer 排名(不包含竞价广告,为自然排名)
*/
class KeyRank{
private static $url;
private static $key;
private static $start;
private static $deep;
private static $trytime;
public function __construct($key='', $url='', $deep=3, $start=1, $trytime=3) {
if($key==='' || $url===''){
die('key & url required !');
}
self::$url = $url;
self::$key = $key;
self::$deep = $deep;
self::$start = $start;
self::$trytime = $trytime;
}
//百度
public static function baiduRank(){
$rank=$page=0;
$res = ['rank'=>$rank, 'page'=>$rank];
for ($d=self::$start; $d <= self::$deep; $d++) {
$pn = 10*($d-1);
$url = "http://www.baidu.com/s?ie=utf-8&wd=".urlencode(self::$key).'&pn='.$pn;
$str = self::https_request($url);
preg_match("/<div id=\"content_left\">.*?<div id=\"rs\">/ism", $str, $content);
$str = $content[0];
$arr = explode('<div class="result', $str);
// var_dump($arr);die;
if(!$arr[0]){
for ($i=0; $i < self::$trytime; $i++) {
$str = self::https_request($url);
preg_match("/<div id=\"content_left\">.*?<div id=\"rs\">/ism", $str, $content);
$str = $content[0];
$arr = explode('<div class="result', $str);
if($arr[0] != ''){
break;
}
sleep(3);
}
if(!$arr[0]){
$err = date('Y/m/d H:i:s')."【错误】#百度#关键词@".self::$key."@页面抓取失败\r\n";
file_put_contents('./err.log', $err, FILE_APPEND);
break;
}
}
foreach ($arr as $k => $v) {
if($k==0) continue;
// preg_match("/<div class=\"f13\">.*?<\/a>/ism", $v, $xxx);
preg_match("/class=\"c-showurl\".*?>.*?<\/[^b|.]*?>/ism", $v, $xxx);
if(isset($xxx[0]) && strstr(strip_tags($xxx[0]), self::$url)){
global $rank, $page;
$page = $d;
$rank = $k + ($d-1)*10;
break;
}
}
if($rank){
$res['rank'] = $rank;
$res['page'] = $page;
return $res;
}
}
return $res;
}
//360
public static function soRank(){
$rank=$page=0;
$res = ['rank'=>$rank, 'page'=>$rank];
for ($d=self::$start; $d <= self::$deep; $d++) {
$url = "https://www.so.com/s?ie=utf-8&fr=so.com&src=home_so.com&q=".urlencode(self::$key)."&pn=".$d;
$str = self::https_request($url);
preg_match("/<ul class=\"result\">.*?<div id=\"side\">/ism", $str, $content);
$str = $content[0];
$arr = explode('<li class="res-list', $str);
if(!$arr[0]){
for ($i=0; $i < self::$trytime; $i++) {
$str = self::https_request($url);
preg_match("/<ul class=\"result\">.*?<div id=\"side\">/ism", $str, $content);
$str = $content[0];
$arr = explode('<li class="res-list', $str);
if($arr[0] != ''){
break;
}
sleep(3);
}
if(!$arr[0]){
$err = date('Y/m/d H:i:s')."【错误】#360#关键词@".self::$key."@页面抓取失败\r\n";
file_put_contents('./err.log', $err, FILE_APPEND);
break;
}
}
foreach ($arr as $k => $v) {
if($k==0) continue;
preg_match("/<cite>.*?<\/cite>/ism", $v, $xxx);
if(isset($xxx[0]) && strstr(strip_tags($xxx[0]), self::$url)){
global $rank, $page;
$page = $d;
$rank = $k + ($d-1)*10;
break;
}
}
if($rank){
$res['rank'] = $rank;
$res['page'] = $page;
return $res;
}
}
return $res;
}
//搜狗
public static function sogouRank(){
$rank=$page=0;
$res = ['rank'=>$rank, 'page'=>$rank];
for ($d=self::$start; $d <= self::$deep; $d++) {
$url = "https://www.sogou.com/web?query=".urlencode(self::$key)."&page=".$d;
$str = self::https_request($url);
preg_match("/<div class=\"results\".*?<div class=\"right\"/ism", $str, $content);
$str = $content[0];
$arr = explode('<!-- a -->', $str);
if(!$arr[0]){
for ($i=0; $i < self::$trytime; $i++) {
$str = self::https_request($url);
preg_match("/<div class=\"results\".*?<div class=\"right\"/ism", $str, $content);
$str = $content[0];
$arr = explode('<!-- a -->', $str);
if($arr[0] != ''){
break;
}
sleep(3);
}
if(!$arr[0]){
$err = date('Y/m/d H:i:s')."【错误】#搜狗#关键词@".self::$key."@页面抓取失败\r\n";
file_put_contents('./err.log', $err, FILE_APPEND);
break;
}
}
//sogou首页个数非稳定10个 判断排名依据
foreach ($arr as $k => $v) {
$total = count($arr);
if($k==0) continue;
preg_match("/<cite.*?>.*?<\/cite>/ism", $v, $xxx);
if(isset($xxx[0]) && strstr(strip_tags($xxx[0]), self::$url)){
global $rank, $page;
$page = $d;
// $rank = $k + ($d-1)*10;
$tmp += $total;
$rank = $k + $tmp - $total;
break;
}
}
if($rank){
$res['rank'] = $rank;
$res['page'] = $page;
return $res;
}
}
return $res;
}
//curl
public static function https_request($url, $data = null){
$headers = array(
"Content-type:application/html;charset=utf-8",
"User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36",
'Cache-Control:no-cache'
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT,3);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}
/*$KeyRank = new KeyRank('婧氏纸尿裤', 'magibaby.net', 2);
$baidu = $KeyRank::baiduRank();
$so = $KeyRank::soRank();
$sogou = $KeyRank::sogouRank();
var_dump($baidu);
var_dump($so);
var_dump($sogou);*/
laydate设置默认开始时间
laydate.skin('molv');
var start1 = {
elem: '#usetime',
format: 'YYYY-MM-DD hh:mm',
max: laydate.now(), //最大日期
istime: true,
istoday: false,
choose: function(datas){
end1.min = datas; //开始日选好后,重置结束日的最小日期
end1.start = datas //将结束日的初始值设定为开始日
},
start: laydate.now(0, 'YYYY-MM-DD hh:mm:ss')
};
laydate(start1);