Commit bcc0f446 authored by shajiaiming's avatar shajiaiming

参数配置

parent a27f96e8
......@@ -12,18 +12,25 @@ define('WALLET_PROJECT_PATH', '/data_wallet/token'); //定义框架代码的目
define('WALLET_RUNTIME_PATH', dirname(__DIR__)); //定义程序运行的目录
if (isset($_GET['env']) && 'test' == $_GET['env']) {
require_once __DIR__ . '/../common/helper/Curl.php';
require_once __DIR__ . '/../common/helper/InitAppHelper.php';
$realip = InitAppHelper::getUserIp();
$ip_list = file_get_contents('http://47.100.212.109/api_ip_limit.txt');
$ip_arr = explode("\n", $ip_list);
foreach ($ip_arr as $key => $ip) {
if ($ip == $realip) {
$data = [
'code' => 403,
'message' => '请求次数过多!'
];
echo json_encode($data);
exit;
if (strpos($_SERVER['REQUEST_URI'], 'black-list') == false) {
$realip = InitAppHelper::getUserIp();
$url = 'http://127.0.0.1:8082/interface/validate/black-list';
Curl::prepare($url);
Curl::exec_get();
$ip_list = Curl::get_response_assoc();
if (isset($ip_list['data']) && count($ip_list > 0)) {
foreach ($ip_list['data'] as $key => $ip) {
if ($ip == $realip) {
$data = [
'code' => 403,
'message' => '请求次数过多!'
];
echo json_encode($data);
exit;
}
}
}
}
}
......
......@@ -92,6 +92,13 @@ return [
'password' => 'fuzamei47100222198',
'database' => 6,
],
'redis_es' => [
'class' => 'yii\redis\Connection',
'hostname' => '47.100.226.15',
'port' => 6379,
'password' => 'fuzamei47100222198',
'database' => 7,
],
'queue' => [
'class' => \yii\queue\redis\Queue::class,
'redis' => 'redis-queue', // Redis connection component or its config
......
......@@ -151,5 +151,17 @@ return [
3 => '文章',
4 => '邀请有礼Banner',
5 => '邀请有礼海报'
],
'api_ip_limit' => [
'limit' => 200,
'white_list' => [
'127.0.0.1',
'47.103.119.244', //lsb 1
'47.100.212.109', //lsb 2
'183.129.134.34', //公司
'129.226.132.153', //公司VPN
'161.117.33.70' //比特元
]
]
];
<?php
/**
* Class curl
* @package simple_curl
*/
class Curl
{
protected static $url;
protected static $headers;
protected static $query;
protected static $responses;
/**
* @param $url
* @param $headers
* @param $query
*/
public static function prepare($url, $query = array(), $headers = array())
{
self::$url = $url;
self::$headers = $headers;
self::$query = http_build_query($query);
}
/**
* Execute post method curl request
*/
public static function exec_post()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, self::$url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, self::$headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, self::$query);
self::$responses = curl_exec($curl);
curl_close($curl);
}
/**
* Execute get method curl request
*/
public static function exec_get()
{
$full_url = self::$url . '?' . self::$query;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $full_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, self::$headers);
self::$responses = curl_exec($curl);
curl_close($curl);
}
/**
* @return mixed
*/
public static function get_response()
{
return self::$responses;
}
/**
* @return mixed
*/
public static function get_response_assoc()
{
return json_decode(self::$responses, true);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment