master
zhaocheng 4 years ago
parent c373267b79
commit f3f1c444ed
  1. 2
      app/Console/Commands/Test.php
  2. 29
      app/Http/Controllers/Api/AuthController.php
  3. 25
      app/Http/Controllers/Api/BaseController.php
  4. 2
      app/Http/Kernel.php
  5. 5
      app/Http/Middleware/ParamVerify.php
  6. 29
      app/Libs/MyLib.php
  7. 3
      composer.json
  8. 141
      composer.lock
  9. 3
      config/database.php
  10. 19
      config/hprose.php
  11. 1
      routes/api.php
  12. 5
      routes/rpc.php

@ -39,8 +39,6 @@ class Test extends Command
*/
public function handle()
{
$client = new \Hprose\Socket\Client('tcp://127.0.0.1:1317', false);
var_dump($client->demo());
exit();
}
}

@ -117,17 +117,28 @@ class AuthController extends BaseController
*/
public function login()
{
if (!$token = auth('api')->attempt([
'username' => $this->params['username'],
'password' => $this->params['password'],
])) {
return $this->error(401, '登录失败,用户名或密码错误');
$employee = EmployeeT::where('username', $this->params['username'])->first();
if(!$employee){
return $this->error(401, '登录失败,用户名不存在');
}
if(!password_verify($this->params['password'], $employee->password)){
return $this->error(401, '登录失败,密码错误');
}
return $this->success([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth('api')->factory()->getTTL() * 60
'user_id' => $employee->id,
'username' => $employee->username,
'nickname' => $employee->nickname,
'company_id' => $employee->company_id,
'group_id' => $employee->group_id,
'phone' => $employee->phone,
'monthly_working_days' => $employee->monthly_working_days,
'entry_date' => $employee->entry_date,
'official_date' => $employee->official_date,
'resign_date' => $employee->resign_date,
'probation_salary' => $employee->probation_salary,
'official_salary' => $employee->official_salary,
'is_outer' => $employee->is_outer,
'status' => $employee->status,
]);
}

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Libs\MyLib;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
@ -18,6 +19,7 @@ class BaseController extends Controller
{
$this->request = $request;
$this->params = $request->input();
env('DB_DATABASE', 'forge');
$this->initialize();
}
@ -48,4 +50,27 @@ class BaseController extends Controller
'data' => $data,
], $code);
}
private function calc($operator, $value1, $value2)
{
switch ($operator){
case 'eq':
return $value1 == $value2;
case 'neq':
return $value1 != $value2;
case 'gt':
return $value1 > $value2;
case 'egt':
return $value1 >= $value2;
case 'lt':
return $value1 < $value2;
case 'elt':
return $value1 <= $value2;
case 'heq':
return $value1 === $value2;
case 'nheq':
return $value1 !== $value2;
}
}
}

@ -53,7 +53,7 @@ class Kernel extends HttpKernel
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
// 'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,

@ -19,6 +19,9 @@ class ParamVerify
*/
public function handle(Request $request, Closure $next)
{
if(!MyLib::IpIsLan($request->ip())){
return response()->json(['code' => 403, 'msg' => '禁止外网访问'], 403);
}
$rules = $request->get('rules');
$attributes = $request->get('attributes');
array_walk($attributes, function(&$value){
@ -50,7 +53,7 @@ class ParamVerify
}
if ($validator->fails()) {
return response()->json(['code' => 422, 'msg' => $validator->errors()->first(), 'data' => $validator->errors()->all()], 400);
return response()->json(['code' => 422, 'msg' => $validator->errors()->first(), 'data' => $validator->errors()->all()], 422);
}
}
return $next($request);

@ -70,4 +70,33 @@ class MyLib
}
return $ip;
}
public static function IpIsLan(string $ip)
{
if ($ip == '127.0.0.1') return true;
return self::IpIsValid($ip,"192.168.0.0-192.168.255.255")
|| self::IpIsValid($ip,"172.16.0.0-172.31.255.255")
|| self::IpIsValid($ip,"10.0.0.0-10.255.255.255");
}
public static function IpIsValid(string $ip, string $ip_section = ''){
$ip = trim($ip);
$ip_section = trim($ip_section);
if (empty($ip)) return false;
$pattern_ip = '((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)';
$pattern_ipb = '/'. $pattern_ip ."\-". $pattern_ip .'/';
$pattern_ip = '/' . $pattern_ip . '/';
$match_count = preg_match($pattern_ip, $ip);
if ($pattern_ipb == '' && $match_count > 0) return true;
if (!$match_count || ($ip_section != '' && preg_match($pattern_ipb, $ip_section))) return false;
list($ip_min, $ip_max) = explode('-', $ip_section);
$ip_min = explode('.', $ip_min);
$ip_max = explode('.', $ip_max);
$ips = explode('.', $ip);
for($i = 0; $i < 4; $i ++) {
if($ips[$i] > $ip_max[$i] || $ips[$i] < $ip_min[$i]) return false;
}
return true;
}
}

@ -16,8 +16,7 @@
"iidestiny/laravel-filesystem-oss": "^2.1",
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5",
"tymon/jwt-auth": "^1.0",
"zhuqipeng/laravel-hprose": "v1.0.*"
"tymon/jwt-auth": "^1.0"
},
"require-dev": {
"facade/ignition": "^2.5",

141
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f4b86984c7875266a63799ac3e085339",
"content-hash": "89e830c2ea322cb898c94664d79e1f9a",
"packages": [
{
"name": "aliyuncs/oss-sdk-php",
@ -937,90 +937,6 @@
},
"time": "2020-09-30T07:37:11+00:00"
},
{
"name": "hprose/hprose",
"version": "v2.0.40",
"source": {
"type": "git",
"url": "https://github.com/hprose/hprose-php.git",
"reference": "ab4955a31596a71b0ba205e18a8598a95ef005b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hprose/hprose-php/zipball/ab4955a31596a71b0ba205e18a8598a95ef005b4",
"reference": "ab4955a31596a71b0ba205e18a8598a95ef005b4",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": ">=4.0.0"
},
"suggest": {
"ext-hprose": "Faster serialize and unserialize hprose extension."
},
"type": "library",
"autoload": {
"files": [
"src/init.php"
],
"psr-4": {
"Hprose\\": "src/Hprose"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ma Bingyao",
"email": "andot@hprose.com",
"homepage": "http://hprose.com",
"role": "Developer"
}
],
"description": "It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.",
"homepage": "http://hprose.com/",
"keywords": [
"HTML5",
"Hprose",
"Socket",
"ajax",
"async",
"communication",
"cross-domain",
"cross-language",
"cross-platform",
"framework",
"future",
"game",
"http",
"json",
"jsonrpc",
"library",
"middleware",
"phprpc",
"protocol",
"rpc",
"serialization",
"serialize",
"service",
"tcp",
"unix",
"web",
"webapi",
"webservice",
"websocket",
"xmlrpc"
],
"support": {
"issues": "https://github.com/hprose/hprose-php/issues",
"source": "https://github.com/hprose/hprose-php/tree/v2.0.40"
},
"time": "2020-03-30T15:33:41+00:00"
},
{
"name": "iidestiny/flysystem-oss",
"version": "2.5",
@ -5381,61 +5297,6 @@
"source": "https://github.com/webmozart/assert/tree/master"
},
"time": "2020-07-08T17:02:28+00:00"
},
{
"name": "zhuqipeng/laravel-hprose",
"version": "v1.0.2",
"source": {
"type": "git",
"url": "https://github.com/zhuqipeng/laravel-hprose.git",
"reference": "38afe2b5632ebe17f1fcab2aba35a1134cff8d18"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zhuqipeng/laravel-hprose/zipball/38afe2b5632ebe17f1fcab2aba35a1134cff8d18",
"reference": "38afe2b5632ebe17f1fcab2aba35a1134cff8d18",
"shasum": ""
},
"require": {
"hprose/hprose": "v2.0.*",
"php": ">=7.0.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Zhuqipeng\\LaravelHprose\\ServiceProvider"
],
"aliases": {
"LaravelHproseRouter": "Zhuqipeng\\LaravelHprose\\Facades\\Router"
}
}
},
"autoload": {
"psr-4": {
"Zhuqipeng\\LaravelHprose\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "朱其鹏",
"email": "28942998@qq.com"
}
],
"description": "Hprose for Laravel",
"keywords": [
"Hprose",
"laravel"
],
"support": {
"issues": "https://github.com/zhuqipeng/laravel-hprose/issues",
"source": "https://github.com/zhuqipeng/laravel-hprose/tree/master"
},
"time": "2018-11-26T02:48:13+00:00"
}
],
"packages-dev": [

@ -48,7 +48,8 @@ return [
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
// 'database' => env('DB_DATABASE', 'forge'),
'database' => 'user_center',
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),

@ -1,19 +0,0 @@
<?php
return [
/**
* 监听地址列表
* 字符串json格式数组
*/
'uris' => json_decode(env('HPROSE_URIS', '["tcp://0.0.0.0:1314"]')),
/**
* true开启 false关闭,开启后将自动对外发布一个远程调用方法 `demo`
* $client->demo()
*/
'demo' => env('HPROSE_DEMO'),
'parameter' => 'App\\Controllers\\Parameters',
'controller' => 'App\\Controllers',
];

@ -17,6 +17,7 @@ use Illuminate\Support\Facades\Route;
Route::namespace('App\Http\Controllers\Api')->group(function(){
Route::post('auth/login', 'AuthController@login');
Route::get('auth/login', 'AuthController@login');
Route::post('auth/refresh', 'AuthController@refresh');
Route::post('tool/upload', 'CommonController@upload');

@ -1,5 +0,0 @@
<?php
\LaravelHproseRouter::add('demo', function () {
return 'demo';
});
Loading…
Cancel
Save