php管理和接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

70 lines
2.0 KiB

<?php
namespace app\admin\service;
use app\admin\model\Ip as IpModel;
class IpService
{
/**
* 发起请求获取IP
* @return bool
*/
public static function proxy(): bool
{
$app_key = "50f95964abbb4b10f9b5e4f1075149d0";
$url = "https://api.wandoudl.com/api/ip/list-v2?";
$params = [
// 账户密钥
"app_key" => $app_key,
// 指定套餐,默认不指定
"pack" => "0",
// 获取代理IP数量
"num" => "20",
// 代理协议 http协议: 1
"xy" => "1",
// 格式 1:txt 2-json
"type" => "2",
// 支持自定义间隔符
"lb" => "\r\n",
// 是否去重,默认不去重,不去重=0,去重=99
"nr" => "0",
// 指定地区,默认全国,支持指定省或市,支持同时指定多个,英文符号 | 分隔
// 全国: 0
// 北京市: 110000
// 北京市+江苏省+杭州市: 110000|320000|330100
"area_id" => "0",
//
"isp" => 0,
];
$data = self::curl($url, $params);
return IpModel::updateIp($data);
}
protected static function curl($url, $params)
{
$ch = curl_init();
// 设置请求地址
curl_setopt($ch, CURLOPT_URL, $url . http_build_query($params));
// https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// 响应内容返回而不是直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 请求超时时间 秒
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
// 发出网络请求
$output = curl_exec($ch);
$result = json_decode($output, true);
if (isset($result['code'])) {
if ($result['code'] == 200) {
return $result['data'];
}
}
return [];
}
}