Skip to content

Commit

Permalink
新功能,查询手机号所属信息
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexchent committed Jan 16, 2020
1 parent 473d6c7 commit cda9da7
Show file tree
Hide file tree
Showing 22 changed files with 1,309 additions and 306 deletions.
374 changes: 207 additions & 167 deletions .idea/workspace.xml

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions Helper/HttpRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace libs;
/**http请求模块
* Created by PhpStorm.
* User: SD
* Date: 2016/7/7
* Time: 15:27
*/
class HttpRequest
{
//利用file_get_contents获取数据
public static function request($url, $params=[], $method='GET'){
$res = null;
if(preg_match("/^(http|https)\:\/\/(\w+\.\w+\.\w+)/", $url)){
$method = strtoupper($method);
if($method=='GET'){
if ($params) {
if (strripos('?', $url)) {
$url = $url . '&' . http_build_query($params);
} else {
$url = $url . '?' . http_build_query($params);
}
}
$res = file_get_contents($url);
} elseif($method=='post') {
exit("$method have none");
}else{
exit("$method have none");
}
}
return $res;
}
}
60 changes: 60 additions & 0 deletions Helper/QueryPhone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
namespace app;
/**
* Created by PhpStorm.
* User: SD
* Date: 2016/7/6
* Time: 15:37
*/
use libs\HttpRequest;

class QueryPhone
{
/**
* 淘宝api
* https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=130********
*/
const PHONE_API = 'https://tcc.taobao.com/cc/json/mobile_tel_segment.htm';
const BAIDU_API_PHONE = 'http://apis.baidu.com/apistore/mobilenumber/mobilenumber?phone';
const BAIDU_PAI_apikey = '14153e647b7aa96a4be61d8f90468e6c';

const QUERY_PHONE = 'PHONE:INFO:';

private static function _formatData($data)
{
$ret = null;
if (!empty($data)) {
preg_match_all("/(\w+):'([^']+)/", $data, $res);
$items = array_combine($res[1], $res[2]);
foreach ($items as $itemKey => $itemVal) {
$ret[$itemKey] = iconv('GB2312', 'UTF-8', $itemVal);
}
}
return $ret;
}

public static function verifyPhone($phone)
{
if (preg_match("/^1[34578]{1}\d{9}/", $phone)) {
return true;
} else {
return false;
}
}

public static function query($phone)
{
$phoneData = null;
if (self::verifyPhone($phone)) {
//TODO 加缓存
$response = HttpRequest::request(self::PHONE_API, ['tel' => $phone]);

$phoneData = self::_formatData($response);

$phoneData['msg'] = '数据由阿里巴巴提供';

}
return $phoneData;
}

}
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@ session_start([
- [php7新特性——移除扩展](https://www.runoob.com/php/php-removed-extensions.html)

## [Helper 辅助类小工具](/Helper)
- [裁剪分割文本文件](/Helper/cuttxt.php)
- [裁剪分割文本文件](/Helper/cuttxt.php)


## [下载图片](/getimg)
1. [基类](/getimg/GetImageClass.php)
2. [测试](/getimg/gethenha.php)


## [Helper 帮助](/Helper)
- [手机号查询](/Helper/QueryPhone.php)
- [file_get_content发送http请求](/Helper/HttpRequest.php)
29 changes: 29 additions & 0 deletions find_phone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* 测试
* Created by PhpStorm.
* User: SD
* Date: 2016/7/6
* Time: 15:36
*/
include_once "autoload.php";
use app\QueryPhone;



$tel = $_POST['phone'] ?? 15251895564;

$response = QueryPhone::query($tel);

if(is_array($response)&&isset($response['province'])){
$response['phone'] = $tel;
$response['code'] = 200;
}else{
$response['code'] = 400;
$response['msg'] = "手机号码错误";
}

echo json_encode($response);



77 changes: 0 additions & 77 deletions getimage/GetImageClass.php

This file was deleted.

43 changes: 0 additions & 43 deletions getimage/gethenha.php

This file was deleted.

45 changes: 45 additions & 0 deletions getimg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>从www.henha.com获取图片资源</title>
<link type="text/css" href="static/css/bootstrap.min.css" rel="stylesheet">
<script type="application/javascript" src="static/js/jquery-3.0.0.min.js"></script>
<script type="application/javascript" src="static/js/jquery.cookie.js"></script>
<script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
</head>
<body>
<header style="height: 100px;"></header>
<div class="container">
<div class="row">
<form class="form-horizontal" action="#" method="post">
<div class="form-group">
<label for="start-number" class="col-sm-2 control-label">起始页</label>
<div class="col-sm-10">
<input type="number" class="form-control" id="start-number" name="start-number" placeholder="从零开始" required min="0" step="1" value="">
</div>
</div>
<div class="form-group">
<label for="all-number" class="col-sm-2 control-label">下载数量</label>
<div class="col-sm-10">
<input type="number" class="form-control" id="all-number" name="all-number" placeholder="上限500" aria-valuemax="500" required max="500" step="1">
</div>
</div>
<div class="form-group">
<div class="col-sm-12 text-right">
<button type="submit" class="btn btn-primary btn-lg">确定</button>
</div>
</div>
</form>
</div>
</div>

</body>
<script>
function init(){
var start_num = parseInt($.cookie('end_num'))+1;
$('#start-number').val(start_num);
}
window.onload=init();
</script>
</html>
32 changes: 17 additions & 15 deletions getimg/GetImageClass.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
<?php

define("DIR_IMG","/Users/chentao/Documents/work/interview/getimg/img/");
define("ERR_LOG","./img/log.txt");
define("ERR_MKDIR","./img/mkdir.log");
define("DIR_IMG", "/Users/chentao/Documents/work/interview/getimg/img/");
define("ERR_LOG", "./img/log.txt");
define("ERR_MKDIR", "./img/mkdir.log");

class GetImageClass{
/**创建多级目录

/**
* 创建多级目录
*
* @param $path 目录路径
* @return mixed
* @param string $path 目录路径
*/
public function makedir($path){
public function make_dir($path) :void {
//header("Content-type:text/html;charset=utf-8");
//判断目录存在否,存在给出提示,不存在则创建目录
if (is_dir($path)){
return $path;
return ;
}else{
//第三个参数是“true”表示能创建多级目录,iconv防止中文目录乱码
$res=mkdir(iconv("UTF-8", "GBK", $path),0777,true);
if ($res){
return $path;
return ;
}else{
file_put_contents(ERR_MKDIR, $path, FILE_APPEND | LOCK_EX);
}
}
}


/**保存图片
/**
* 保存图片
*
* @param string $url 图片地址
* @param sttring $dir 用于创建保存图片的文件夹名
* @param string $url 图片地址
* @param string $dir 用于创建保存图片的文件夹名
* @param string $filename 图片名
* @return bool
*/
public function grabImage_base($url, $dir, $filename='') {
public function grabImage_base($url, $dir=DIR_IMG, $filename='') {

if($url == '') {
return false; //如果 $url 为空则返回 false;
Expand All @@ -47,10 +50,9 @@ public function grabImage_base($url, $dir, $filename='') {
return false; //格式不在允许的范围
}

$this->makedir($dir);//创建保存图片的文件夹
$this->make_dir($dir);//创建保存图片的文件夹
if($filename == '') $filename = $dir.time().$ext_name; //以时间戳另起名

//echo $filename,"\n";die;
//开始捕获
ob_start();
readfile($url);
Expand Down
4 changes: 1 addition & 3 deletions getimg/gethenha.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

$getimgbase = new GetImageClass();
$url ='http://pic1.win4000.com/pic/c/33/16d2340465.jpg';
$newFile=$getimgbase->grabImage_base($url, DIR_IMG);
$newFile=$getimgbase->grabImage_base($url);



?>
Loading

0 comments on commit cda9da7

Please sign in to comment.