Commit 4b5de055 by banice

03命令成功

parent 3e42114a
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/11/2
* Time: 下午6:20
*/
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class TestController extends Controller
{
public function test(Request $request)
{
Log::debug($request->all());
}
}
\ No newline at end of file
...@@ -33,7 +33,7 @@ class ChargerController extends Controller ...@@ -33,7 +33,7 @@ class ChargerController extends Controller
$chargerCommand->setMethod('Cmd_Res'); $chargerCommand->setMethod('Cmd_Res');
$send = new Send($chargerCommand); $send = new Send($chargerCommand);
$send->setCallBackUrl(route('deviceChargerReceiver')); $send->setCallBackUrl(route('deviceChargerReceiver'));
$send->setDeviceId('d245d3fd-26e1-4818-95b9-37e6af3cfcf7'); $send->setDeviceId('e03b8e91-3309-4764-8567-80e1644ca4ca');
if ($send->send() === true) { if ($send->send() === true) {
...@@ -45,6 +45,9 @@ class ChargerController extends Controller ...@@ -45,6 +45,9 @@ class ChargerController extends Controller
} }
dd(1);
} }
public function receiver(Request $request) public function receiver(Request $request)
......
...@@ -13,44 +13,169 @@ use App\Http\Controllers\Controller; ...@@ -13,44 +13,169 @@ use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Lib\Api; use Lib\Api;
use Lib\Session;
use Src\route\Route; use Src\route\Route;
use Validator;
class MessageController extends Controller class MessageController extends Controller
{ {
private $route = [];
public function receiver(Request $request) public function receiver(Request $request)
{ {
Log::debug($request->all()); $message = $request->all();
$command = 'ff'; Log::debug($message);
$validator = Validator::make($request->all(), [
'service' => 'required'
]);
if ($validator->fails()) {
Log::error($validator->errors()->first());
return;
}
if (isset($message['service']['data']['upData']) === false) {
return;
}
$clientId = $message['deviceId'];
Session::$deviceId = $clientId;
$update = $message['service']['data']['upData'];
$command = substr($update, 6, 2);
Log::debug($command);
Log::debug($update);
$api = new Api(); $api = new Api();
$api->boot(); $api->boot();
if (isset($api->route[$command])) { if (isset($api->route[$command])) {
$clientId = 'deviceCode';
$message = '';
$route = $api->route[$command]; $route = $api->route[$command];
if ($route instanceof Route) { if ($route instanceof Route) {
$reflection = $route->getController(); $reflection = $route->getController();
$controller = $reflection->newInstanceArgs([$clientId, $update, $command]);
$method = $route->getMethod();
$controller = $reflection->newInstanceArgs([$clientId, $message, $command]); Log::debug($method);
$method = $route->getMethod();
try { $controller->$method();
$controller->$method();
} catch (\Exception $exception) {
Log::error($exception->getMessage());
}
unset($route); unset($route);
unset($controller); unset($controller);
unset($api); unset($api);
} else {
Log::error('not instance');
} }
} else {
Log::error('can not find command');
} }
} }
private function boot()
{
Log::debug('boot');
$this->add('01', 'accept\CertifyController@certify');
$this->add('00', 'HeartController@break');
$this->add('02', 'accept\AccessController@request');
$this->add('03', 'accept\AccessController@syncPort');
$this->add('04', 'business\charger\StartController@start');
$this->add('05', 'business\charger\OverController@over');
$this->add('0B', 'business\port\StateController@change');
$this->add('07', 'business\power\PowerController@plural');
$this->add('17', 'business\power\PowerController@one');
$this->add('06', 'business\power\CapacityController@capacity');
$this->add('08', 'business\port\OnlineController@online');
$this->add('09', 'business\port\OfflineController@offline');
// $this->add('0F', 'business\power\ShutdownController@shutdown');
$this->add('0A', 'setting\SettingController@get');
$this->add('31', 'card\PayRuleController@get');
$this->add('32', 'card\BalanceController@get');
$this->add('33', 'card\charger\RequestController@request');
$this->add('34', 'card\charger\StartController@start');
$this->add('35', 'card\charger\OverController@over');
$this->add('0E', 'setting\DeviceMacController@getAll');
$this->add('D1', 'update\QueryController@check');
$this->add('CD', 'update\QueryController@currentVersion');
}
private function add(string $command, string $controllerAction, array $middleware = [])
{
Log::debug('add');
$route = new Route();
$route->setCommand($command);
if (strstr($controllerAction, '@')) {
$controllerAction = explode('@', $controllerAction);
try {
$controllerName = 'Application\\controller\\' . $controllerAction[0];
$controller = new \ReflectionClass($controllerName);
$route->setController($controller);
$methods = $controller->getMethods(\ReflectionMethod::IS_PUBLIC);
$result = false;
foreach ($methods as $method) {
if ($method->name === $controllerAction[1]) {
$result = true;
}
}
if ($result === false) {
exit($controllerAction[1] . 'method not find');
}
$route->setMethod($controllerAction[1]);
unset($controller);
} catch (\ReflectionException $exception) {
exit(__CLASS__ . '-->' . $exception->getMessage());
}
$this->route[$command] = $route;
} else {
exit('wrong route missing controller');
}
unset($route);
}
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/23
* Time: 下午2:54
*/
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class MqttMiddleware
{
public function handle(Request $request, Closure $next)
{
$validator = Validator::make($request->all(), [
'deviceId' => 'required',
'gatewayId' => 'required',
]);
if ($validator->fails()) {
return 0;
}
return $next($request);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/27
* Time: 上午10:09
*/
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class RedisServiceProvider extends ServiceProvider
{
protected $defer = true;
public function register()
{
$this->app->singleton('Redis', function ($app) {
$redis = new \Redis();
$config = config('database.redis.default');
$redis->connect($config['host']);
$redis->select($config['database']);
return $redis;
});
}
public function boot()
{
}
public function provides()
{
return ['Redis'];
}
}
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
use Workerman\MySQL\Connection; use Workerman\MySQL\Connection;
use Lib\Crc; use Lib\Crc;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Application\route\Api; use Application\route\Api;
use Src\route\Route; use Src\route\Route;
use Lib\station\gateway\Gateway; use Lib\station\gateway\Gateway;
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/23
* Time: 上午9:28
*/
namespace Application;
use GuzzleHttp\Client;
use Lib\iot\AccessToken;
use Lib\iot\Request;
use Illuminate\Support\Facades\Log;
class Gateway
{
public static $appId = '';
public static $deviceId = '';
public static $command = '';
public static $expireTime = 0;
public static $maxRetransmit = 1;
private static function init()
{
static::$appId = env('IOT_APP_ID');
}
public static function bindUid(string $clientId, string $uid)
{
}
public static function sendToClient(string $clientId, string $message)
{
$client = new Client();
$request = [
'verify' => false,
'cert' => [
config('iot.cert_path'),
'IoM@1234',
]
];
$request['headers'] = [
'app_key' => env('IOT_APP_ID'),
'Authorization' => 'Bearer ' . AccessToken::getAccessTokenCache(),
'Content-Type' => 'application/json',
];
// 'appId' => env('IOT_APP_ID'),
$request['json'] = [
'deviceId' => $clientId,
'command' =>
['serviceId' => 'Transmission',
'method' => 'Cmd_Res',
'paras' => ['downData' => strtoupper($message)],
],
'expireTime' => static::$expireTime,
'maxRetransmit' => static::$maxRetransmit
];
Log::debug('response = ' . $message);
$response = $client->request('POST', config('iot.host') . 'iocm/app/cmd/v1.4.0/deviceCommands', $request);
if ($response->getStatusCode() === 201) {
return true;
}
return false;
}
}
\ No newline at end of file
...@@ -63,11 +63,11 @@ class Controller ...@@ -63,11 +63,11 @@ class Controller
*/ */
protected $defaultHeader = [ protected $defaultHeader = [
'preamble' => 2, 'preamble' => 2,
'headerFlag' => 1, 'headerFlag' => 1,
'headerCtrl' => 1, 'headerCtrl' => 1,
'length' => 2, 'length' => 2,
'nonce' => 1, 'nonce' => 1,
]; ];
...@@ -160,13 +160,13 @@ class Controller ...@@ -160,13 +160,13 @@ class Controller
$this->logRecord->setCommand($command); $this->logRecord->setCommand($command);
if (isset($_SESSION['station_id'])) { // if (isset($_SESSION['station_id'])) {
$this->logRecord->setStationId($_SESSION['station_id']); // $this->logRecord->setStationId($_SESSION['station_id']);
} // }
if (isset($_SESSION['gateway_id'])) { // if (isset($_SESSION['gateway_id'])) {
$this->logRecord->setGatewayId($_SESSION['gateway_id']); // $this->logRecord->setGatewayId($_SESSION['gateway_id']);
//
} // }
} }
...@@ -174,15 +174,13 @@ class Controller ...@@ -174,15 +174,13 @@ class Controller
public function __destruct() public function __destruct()
{ {
if($this->command === '00') if ($this->command === '00') {
{ return;
return ;
} }
$logWriter = new GatewayLogWriter(); $logWriter = new GatewayLogWriter();
if($this->response->getResponseMessage() !== '') if ($this->response->getResponseMessage() !== '') {
{
$this->logRecord->setResponse($this->response->getResponseMessage()); $this->logRecord->setResponse($this->response->getResponseMessage());
} }
$logWriter->write($this->logRecord); $logWriter->write($this->logRecord);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
namespace Application\controller; namespace Application\controller;
use Lib\Session;
use Src\route\Route; use Src\route\Route;
class HeartController extends Controller class HeartController extends Controller
...@@ -34,11 +35,15 @@ class HeartController extends Controller ...@@ -34,11 +35,15 @@ class HeartController extends Controller
{ {
$time = time(); $time = time();
$redis = \Events::getRedis(); $redis = app('Redis');
if (isset($_SESSION['gateway_id'])) {
$redis->hSet(self::GATEWAY_LAST_HEART_TIME, $_SESSION['gateway_id'], $time);
$redis->zIncrBy(self::GATEWAY_HEART_TIMES, 1, $_SESSION['gateway_id']); $gatewayId = Session::get('gateway_id');
if (filled($gatewayId)) {
$redis->hSet(self::GATEWAY_LAST_HEART_TIME, $gatewayId, $time);
$redis->zIncrBy(self::GATEWAY_HEART_TIMES, 1, $gatewayId);
} }
$this->response->send('00', sprintf('%08x', time())); $this->response->send('00', sprintf('%08x', time()));
......
...@@ -13,8 +13,10 @@ use Application\controller\Controller; ...@@ -13,8 +13,10 @@ use Application\controller\Controller;
use Application\model\DeviceModel; use Application\model\DeviceModel;
use Application\model\GatewayModel; use Application\model\GatewayModel;
use Lib\Aes; use Lib\Aes;
use GatewayWorker\Lib\Gateway; use Lib\Session;
use Src\route\Route; use Src\route\Route;
use Illuminate\Support\Facades\Log;
use Application\Gateway;
/** /**
* 设备认证 * 设备认证
...@@ -45,14 +47,11 @@ class CertifyController extends Controller ...@@ -45,14 +47,11 @@ class CertifyController extends Controller
public function certify() public function certify()
{ {
$nonce = $this->getNonce(); $nonce = $this->getNonce();
$mac = $this->request->get('mac'); $mac = $this->request->get('mac');
$_SESSION['gateway_mac'] = $mac;
$_SESSION['certified'] = true;
$gatewayModel = new GatewayModel(); $gatewayModel = new GatewayModel();
$gatewayModelResult = $gatewayModel->getColumns([ $gatewayModelResult = $gatewayModel->getColumns([
...@@ -60,20 +59,19 @@ class CertifyController extends Controller ...@@ -60,20 +59,19 @@ class CertifyController extends Controller
'id', 'id',
'name', 'name',
'type_id' 'type_id'
], 'mac_address = ' . "'$mac'"); ], 'mac_address=' . $mac);
if ($gatewayModelResult == false) { if ($gatewayModelResult == false) {
Gateway::closeClient($this->clientId); Log::error('no this gateway hahah');
return; return;
} }
$stationId = $gatewayModelResult['station_id']; $stationId = $gatewayModelResult['station_id'];
$gatewayId = $gatewayModelResult['id']; $gatewayId = $gatewayModelResult['id'];
Session::update('station_id', $stationId);
Session::update('gateway_id', $gatewayId);
$_SESSION['station_id'] = $stationId; Log::debug(Session::get('station_id'));
$_SESSION['gateway_id'] = $gatewayId;
$productId = 'A22E4F4CDB05C460E450E46241DD6F89'; $productId = 'A22E4F4CDB05C460E450E46241DD6F89';
...@@ -81,14 +79,6 @@ class CertifyController extends Controller ...@@ -81,14 +79,6 @@ class CertifyController extends Controller
$sign = substr($sign, 0, 8); $sign = substr($sign, 0, 8);
if (Gateway::isUidOnline($mac) === 1) {
$clients = Gateway::getclientIdByUid($mac);
foreach ($clients as $client) {
Gateway::closeClient($client);
}
}
Gateway::bindUid($this->clientId, $mac); Gateway::bindUid($this->clientId, $mac);
......
...@@ -17,7 +17,7 @@ use Lib\cdz\order\state\ChargerState; ...@@ -17,7 +17,7 @@ use Lib\cdz\order\state\ChargerState;
use Lib\cdz\order\state\ShedState; use Lib\cdz\order\state\ShedState;
use Lib\cdz\order\state\WaitingState; use Lib\cdz\order\state\WaitingState;
use Lib\Gateway; use Lib\Gateway;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\StateCode; use Lib\StateCode;
use Lib\station\gateway\port\Port; use Lib\station\gateway\port\Port;
use Src\route\Route; use Src\route\Route;
......
...@@ -14,8 +14,8 @@ use Lib\cdz\order\Order; ...@@ -14,8 +14,8 @@ use Lib\cdz\order\Order;
use Lib\cdz\order\state\ChargerState; use Lib\cdz\order\state\ChargerState;
use Lib\cdz\order\state\WaitingState; use Lib\cdz\order\state\WaitingState;
use Lib\Gateway; use Lib\Gateway;
use Lib\log\Log;
use Lib\StateCode; use Lib\StateCode;
use Illuminate\Support\Facades\Log;
class StartController extends Controller class StartController extends Controller
{ {
......
...@@ -11,7 +11,7 @@ namespace Application\controller\business\port; ...@@ -11,7 +11,7 @@ namespace Application\controller\business\port;
use Application\controller\Controller; use Application\controller\Controller;
use Application\model\ExceptionModel; use Application\model\ExceptionModel;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\StateCode; use Lib\StateCode;
use Lib\station\gateway\port\Port; use Lib\station\gateway\port\Port;
use Src\BroadcastToAgent; use Src\BroadcastToAgent;
......
...@@ -18,7 +18,7 @@ use Lib\cdz\order\state\PowerExceedState; ...@@ -18,7 +18,7 @@ use Lib\cdz\order\state\PowerExceedState;
use Lib\cdz\order\state\ShedState; use Lib\cdz\order\state\ShedState;
use Lib\cdz\order\state\WaitingState; use Lib\cdz\order\state\WaitingState;
use Lib\Gateway; use Lib\Gateway;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\StateCode; use Lib\StateCode;
use Lib\station\gateway\port\Port; use Lib\station\gateway\port\Port;
......
...@@ -14,7 +14,7 @@ use Application\model\OrderModel; ...@@ -14,7 +14,7 @@ use Application\model\OrderModel;
use Application\model\OrderPowerModel; use Application\model\OrderPowerModel;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis; use Lib\cdz\order\save\OrderSaveRedis;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\station\gateway\port\Port; use Lib\station\gateway\port\Port;
class PowerController extends Controller class PowerController extends Controller
......
...@@ -13,7 +13,7 @@ use Application\controller\Controller; ...@@ -13,7 +13,7 @@ use Application\controller\Controller;
use Application\model\BillTmpModel; use Application\model\BillTmpModel;
use GatewayWorker\Lib\Gateway; use GatewayWorker\Lib\Gateway;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
class PayRuleController extends Controller class PayRuleController extends Controller
{ {
......
...@@ -10,7 +10,7 @@ namespace Application\controller\card\charger; ...@@ -10,7 +10,7 @@ namespace Application\controller\card\charger;
use Application\controller\Controller; use Application\controller\Controller;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\station\gateway\port\Port; use Lib\station\gateway\port\Port;
use Application\model\OrderPowerModel; use Application\model\OrderPowerModel;
......
...@@ -14,7 +14,7 @@ use Application\model\CardModel; ...@@ -14,7 +14,7 @@ use Application\model\CardModel;
use Application\model\OrderModel; use Application\model\OrderModel;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis; use Lib\cdz\order\save\OrderSaveRedis;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\Tool; use Lib\Tool;
class RequestController extends Controller class RequestController extends Controller
......
...@@ -13,6 +13,8 @@ use Application\controller\Controller; ...@@ -13,6 +13,8 @@ use Application\controller\Controller;
use Application\model\DeviceModel; use Application\model\DeviceModel;
use Application\model\GatewayModel; use Application\model\GatewayModel;
use Lib\Gateway; use Lib\Gateway;
use Lib\Session;
use Illuminate\Support\Facades\Log;
class DeviceMacController extends Controller class DeviceMacController extends Controller
{ {
...@@ -26,21 +28,21 @@ class DeviceMacController extends Controller ...@@ -26,21 +28,21 @@ class DeviceMacController extends Controller
public function getAll() public function getAll()
{ {
if (isset($_SESSION['gateway_id']) === true) {
$gatewayId = $_SESSION['gateway_id'];
$deviceModel = new DeviceModel(); $gatewayId = Session::get('gateway_id');
$devicesMac = $deviceModel->getAllColumns(['device_mac'], 'gateway_id = ' . $gatewayId); if ($gatewayId !== '') {
$deviceModel = new DeviceModel();
$devicesMac = $deviceModel->getAllColumns(['device_mac'], 'gateway_id=' . $gatewayId);
$count = count($devicesMac); $count = count($devicesMac);
$tmp = []; $tmp = [];
foreach ($devicesMac as $deviceMac) { foreach ($devicesMac as $deviceMac) {
array_push($tmp, $deviceMac['device_mac']); array_push($tmp, $deviceMac->device_mac);
} }
$devicesMacStr = implode('', $tmp); $devicesMacStr = implode('', $tmp);
$this->response->send('0e', sprintf('%02x', $count) . $devicesMacStr); $this->response->send('0e', sprintf('%02x', $count) . $devicesMacStr);
......
...@@ -13,7 +13,8 @@ use Application\controller\Controller; ...@@ -13,7 +13,8 @@ use Application\controller\Controller;
use Application\model\ConfigModel; use Application\model\ConfigModel;
use Application\model\StationModel; use Application\model\StationModel;
use Lib\Gateway; use Lib\Gateway;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\Session;
class SettingController extends Controller class SettingController extends Controller
{ {
...@@ -39,33 +40,25 @@ class SettingController extends Controller ...@@ -39,33 +40,25 @@ class SettingController extends Controller
$idConfigsValue = []; $idConfigsValue = [];
foreach ($configs as $config) { foreach ($configs as $config) {
$idConfigsValue[$config['id']] = $config['config_value']; $idConfigsValue[$config->id] = $config->config_value;
} }
$invertalTime = $idConfigsValue['5']; //设备上报数据间隔单位 秒 $invertalTime = $idConfigsValue['5']; //设备上报数据间隔单位 秒
if (isset($_SESSION['station_id']) === false) {
Gateway::closeClient($this->clientId);
Log::error('setting miss station_id');
if (filled(Session::get('station_id')) === false) {
Log::error('setting miss station_id');
return; return;
} }
$stationId = $_SESSION['station_id']; $stationId = Session::get('station_id');
$stationModel = new StationModel();
$stationMaxCep = $stationModel->getColumn('max_cep', 'id = ' . $stationId); $stationModel = new StationModel();
$stationMaxCep = $stationModel->getColumn('max_cep', 'id=' . $stationId);
$powerUpperLimit = isset($stationMaxCep) ? $stationMaxCep : $idConfigsValue['1']; $powerUpperLimit = isset($stationMaxCep) ? $stationMaxCep : $idConfigsValue['1'];
$getPriceConfig = $idConfigsValue['6']; $getPriceConfig = $idConfigsValue['6'];
$powerSaturateInvertalTime = $idConfigsValue['7']; $powerSaturateInvertalTime = $idConfigsValue['7'];
$extraTime = $idConfigsValue['8']; $extraTime = $idConfigsValue['8'];
$powerLowerLimit = getenv('LOW_POWER_LIMIT'); $powerLowerLimit = getenv('LOW_POWER_LIMIT');
$detectTime = 5; $detectTime = 5;
$afterFormat = $this->adaptor([ $afterFormat = $this->adaptor([
[$invertalTime, 4], [$invertalTime, 4],
[$getPriceConfig, 2], [$getPriceConfig, 2],
...@@ -75,10 +68,7 @@ class SettingController extends Controller ...@@ -75,10 +68,7 @@ class SettingController extends Controller
[$powerLowerLimit, 2], [$powerLowerLimit, 2],
[$detectTime, 2], [$detectTime, 2],
]); ]);
$this->response->send('0a', implode($afterFormat)); $this->response->send('0a', implode($afterFormat));
} }
/** /**
......
...@@ -14,7 +14,7 @@ use Application\model\DeviceModel; ...@@ -14,7 +14,7 @@ use Application\model\DeviceModel;
use Application\model\GatewayModel; use Application\model\GatewayModel;
use Application\model\GatewayUpdateModel; use Application\model\GatewayUpdateModel;
use GatewayWorker\Lib\Gateway; use GatewayWorker\Lib\Gateway;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
class QueryController extends Controller class QueryController extends Controller
{ {
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
namespace Application\model; namespace Application\model;
use Illuminate\Support\Facades\DB;
class ConfigModel extends Model class ConfigModel extends Model
{ {
...@@ -16,7 +18,9 @@ class ConfigModel extends Model ...@@ -16,7 +18,9 @@ class ConfigModel extends Model
public function getIdConfigValue() public function getIdConfigValue()
{ {
return $this->db->query('SELECT id , config_value FROM '.$this->table); // return $this->db->query('SELECT id , config_value FROM '.$this->table);
return DB::table($this->table)->get(['id', 'config_value'])->toArray();
} }
...@@ -24,35 +28,46 @@ class ConfigModel extends Model ...@@ -24,35 +28,46 @@ class ConfigModel extends Model
public function getPowerUpperLimit() public function getPowerUpperLimit()
{ {
return $this->getColumn('config_value', 'id = 1'); $result = DB::table($this->table)->where('id', 1)->first(['config_value']);
return $result->config_value;
} }
//数据上报间隔时间 //数据上报间隔时间
public function getInvertalTime() public function getInvertalTime()
{ {
return $this->getColumn('config_value', 'id = 5'); $result = DB::table($this->table)->where('id', 5)->first(['config_value']);
return $result->config_value;
} }
//获取计价配置时间间隔 //获取计价配置时间间隔
public function getPriceConfig() public function getPriceConfig()
{ {
return $this->getColumn('config_value', 'id = 6'); $result = DB::table($this->table)->where('id', 6)->first(['config_value']);
return $result->config_value;
} }
//充满自停的功率检测此时 //充满自停的功率检测此时
public function getPowerSaturateInvertalTime() public function getPowerSaturateInvertalTime()
{ {
return $this->getColumn('config_value', 'id = 7'); $result = DB::table($this->table)->where('id', 7)->first(['config_value']);
return $result->config_value;
} }
//充满自停额外的供电时间 //充满自停额外的供电时间
public function getExtraTime() public function getExtraTime()
{ {
$result = DB::table($this->table)->where('id', 8)->first(['config_value']);
return $result->config_value;
return $this->getColumn('config_value', 'id = 8');
} }
} }
\ No newline at end of file
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
namespace Application\model; namespace Application\model;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class Model class Model
{ {
...@@ -26,9 +28,9 @@ class Model ...@@ -26,9 +28,9 @@ class Model
*/ */
public function getColumn($column, $where) public function getColumn($column, $where)
{ {
$where = str_split($where, '='); $where = explode('=', $where);
$result = DB::table($this->table)->where($where[0], $where[1])->whereNotNull('deleted_at')->first([$column]); $result = DB::table($this->table)->where($where[0], $where[1])->whereNull('deleted_at')->first([$column]);
if (blank($result)) { if (blank($result)) {
$result = ''; $result = '';
} else { } else {
...@@ -44,8 +46,11 @@ class Model ...@@ -44,8 +46,11 @@ class Model
*/ */
public function getColumns(Array $columns, $where) public function getColumns(Array $columns, $where)
{ {
$where = str_split($where, '='); $where = explode('=', $where);
$result = DB::table($this->table)->where($where[0], $where[1])->whereNotNull('deleted_at')->first($columns);
$result = DB::table($this->table)->where($where[0], $where[1])->whereNull('deleted_at')->first($columns);
Log::debug(json_encode($result));
if (blank($result)) { if (blank($result)) {
$result = []; $result = [];
...@@ -62,13 +67,11 @@ class Model ...@@ -62,13 +67,11 @@ class Model
*/ */
public function getAllColumns(Array $columns, $where) public function getAllColumns(Array $columns, $where)
{ {
$where = str_split($where, '='); $where = explode('=', $where);
$result = DB::table($this->table)->where($where[0], $where[1])->whereNotNull('deleted_at')->get($columns); $result = DB::table($this->table)->where($where[0], $where[1])->whereNull('deleted_at')->get($columns)->toArray();
if (blank($result)) { if (blank($result)) {
$result = []; $result = [];
} else {
$result = $result->toArray();
} }
return $result; return $result;
...@@ -105,7 +108,7 @@ class Model ...@@ -105,7 +108,7 @@ class Model
*/ */
public function update(array $update, $where) public function update(array $update, $where)
{ {
$where = str_split($where, '='); $where = explode('=', $where);
return DB::table($this->table)->where($where[0], $where[1])->update($update); return DB::table($this->table)->where($where[0], $where[1])->update($update);
} }
......
...@@ -29,6 +29,9 @@ $app->withEloquent(); ...@@ -29,6 +29,9 @@ $app->withEloquent();
$app->configure('logging'); $app->configure('logging');
$app->configure('iot'); $app->configure('iot');
$app->configure('database');
$app->configure('cache');
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -85,6 +88,7 @@ $app->singleton( ...@@ -85,6 +88,7 @@ $app->singleton(
// $app->register(App\Providers\AuthServiceProvider::class); // $app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class); // $app->register(App\Providers\EventServiceProvider::class);
$app->register(\App\Providers\RedisServiceProvider::class);
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Load The Application Routes | Load The Application Routes
......
...@@ -140,7 +140,7 @@ return [ ...@@ -140,7 +140,7 @@ return [
'cluster' => env('REDIS_CLUSTER', false), 'cluster' => env('REDIS_CLUSTER', false),
'default' => [ 'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'), 'host' => env('REDIS_HOST', 'redis.test.senthink.com'),
'port' => env('REDIS_PORT', 6379), 'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 4), 'database' => env('REDIS_DATABASE', 4),
'password' => env('REDIS_PASSWORD', null), 'password' => env('REDIS_PASSWORD', null),
......
...@@ -9,14 +9,20 @@ ...@@ -9,14 +9,20 @@
namespace Lib; namespace Lib;
use Src\route\Route; use Src\route\Route;
use Illuminate\Support\Facades\Log;
class Api class Api
{ {
public $route = []; public $route = [
];
public function boot() public function boot()
{ {
Log::debug('boot');
$this->add('01', 'accept\CertifyController@certify'); $this->add('01', 'accept\CertifyController@certify');
$this->add('00', 'HeartController@break'); $this->add('00', 'HeartController@break');
$this->add('02', 'accept\AccessController@request'); $this->add('02', 'accept\AccessController@request');
...@@ -58,11 +64,12 @@ class Api ...@@ -58,11 +64,12 @@ class Api
* *
* @param string $command * @param string $command
* @param string $controllerAction * @param string $controllerAction
* @param array $middlewar * @param array $middleware
* @return void * @return void
*/ */
public function add(string $command, string $controllerAction, array $middleware = []) public function add(string $command, string $controllerAction, array $middleware = [])
{ {
$route = new Route(); $route = new Route();
$route->setCommand($command); $route->setCommand($command);
...@@ -91,7 +98,8 @@ class Api ...@@ -91,7 +98,8 @@ class Api
} }
if ($result === false) { if ($result === false) {
exit($controllerAction[1] . 'method not find'); Log::error($controllerAction[1] . 'method not find');
} }
$route->setMethod($controllerAction[1]); $route->setMethod($controllerAction[1]);
...@@ -100,7 +108,7 @@ class Api ...@@ -100,7 +108,7 @@ class Api
} catch (\ReflectionException $exception) { } catch (\ReflectionException $exception) {
exit(__CLASS__ . '-->' . $exception->getMessage()); Log::error(__CLASS__ . '-->' . $exception->getMessage());
} }
...@@ -108,7 +116,7 @@ class Api ...@@ -108,7 +116,7 @@ class Api
} else { } else {
exit('wrong route missing controller'); Log::error('wrong route missing controller');
} }
unset($route); unset($route);
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/23
* Time: 下午3:03
*/
namespace Lib;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class Session
{
public static $session = [];
public static $deviceId = '';
public static function update($key, $value)
{
static::init();
static::$session[$key] = $value;
Cache::forever(static::$deviceId, json_encode(static::$session));
}
public static function init()
{
if (blank(static::$session)) {
$request = app('request');
if ($request instanceof Request) {
static::$deviceId = $deviceId = $request->get('deviceId');
$cache = Cache::get($deviceId);
static::$session = json_decode($cache, true);
}
}
}
public static function get($key = '')
{
static::init();
if (isset(static::$session[$key]) === false) {
return '';
}
return blank(static::$session[$key]) ? '' : static::$session[$key];
}
}
\ No newline at end of file
...@@ -13,7 +13,7 @@ use Application\model\OrderExceptionModel; ...@@ -13,7 +13,7 @@ use Application\model\OrderExceptionModel;
use Application\model\OrderModel; use Application\model\OrderModel;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis; use Lib\cdz\order\save\OrderSaveRedis;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\rabbitmq\PublishPortShed; use Lib\rabbitmq\PublishPortShed;
use Lib\remote\api\message\ChargerFullMessage; use Lib\remote\api\message\ChargerFullMessage;
use Lib\remote\api\message\ChargerShedMessage; use Lib\remote\api\message\ChargerShedMessage;
......
...@@ -11,7 +11,7 @@ namespace Lib\cdz_order\state; ...@@ -11,7 +11,7 @@ namespace Lib\cdz_order\state;
use Lib\cdz\order\NoticePortShed; use Lib\cdz\order\NoticePortShed;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
class OfflineNetState extends State class OfflineNetState extends State
{ {
......
...@@ -13,7 +13,7 @@ use Application\model\OrderExceptionModel; ...@@ -13,7 +13,7 @@ use Application\model\OrderExceptionModel;
use Application\model\OrderModel; use Application\model\OrderModel;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis; use Lib\cdz\order\save\OrderSaveRedis;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\remote\api\message\ChargerReloadMessage; use Lib\remote\api\message\ChargerReloadMessage;
use Lib\remote\api\message\ChargerShedTimeOutMessage; use Lib\remote\api\message\ChargerShedTimeOutMessage;
use Lib\remote\api\message\ChargerTimeoutMessage; use Lib\remote\api\message\ChargerTimeoutMessage;
......
...@@ -13,7 +13,7 @@ use Application\model\OrderExceptionModel; ...@@ -13,7 +13,7 @@ use Application\model\OrderExceptionModel;
use Application\model\OrderModel; use Application\model\OrderModel;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis; use Lib\cdz\order\save\OrderSaveRedis;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\remote\api\message\FailMessage; use Lib\remote\api\message\FailMessage;
use Lib\remote\api\message\SendMessage; use Lib\remote\api\message\SendMessage;
use Lib\remote\api\message\StartMessage; use Lib\remote\api\message\StartMessage;
...@@ -54,9 +54,9 @@ class WaitingState extends State ...@@ -54,9 +54,9 @@ class WaitingState extends State
$orderModel = new OrderModel(); $orderModel = new OrderModel();
$orderModel->update([ $orderModel->update([
'is_stop' => StateCode::FINISH_REFUND, 'is_stop' => StateCode::FINISH_REFUND,
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
'end_time' => date('Y-m-d H:i:s'), 'end_time' => date('Y-m-d H:i:s'),
], 'id = ' . $this->order->getId()); ], 'id = ' . $this->order->getId());
$port = new Port(); $port = new Port();
...@@ -104,8 +104,8 @@ class WaitingState extends State ...@@ -104,8 +104,8 @@ class WaitingState extends State
//更新订单状态 //更新订单状态
$update = [ $update = [
'is_charger' => StateCode::PORT_CHARGER, 'is_charger' => StateCode::PORT_CHARGER,
'start_time' => date('Y-m-d H:i:s', $this->order->getStartTime()), 'start_time' => date('Y-m-d H:i:s', $this->order->getStartTime()),
'start_capacity' => $this->order->getStartCapacity(), 'start_capacity' => $this->order->getStartCapacity(),
]; ];
$orderModel = new OrderModel(); $orderModel = new OrderModel();
...@@ -144,9 +144,9 @@ class WaitingState extends State ...@@ -144,9 +144,9 @@ class WaitingState extends State
$orderExceptionModel = new OrderExceptionModel(); $orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([ $orderExceptionModel->insertRow([
'order_id' => $this->order->getId(), 'order_id' => $this->order->getId(),
'state' => '-1' . StateCode::PORT_EXCEPTION, 'state' => '-1' . StateCode::PORT_EXCEPTION,
'desc' => '打开口子失败', 'desc' => '打开口子失败',
'created_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s'),
]); ]);
//推送消息 //推送消息
......
...@@ -10,7 +10,7 @@ namespace Lib\cdz\order\save; ...@@ -10,7 +10,7 @@ namespace Lib\cdz\order\save;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
class OrderSaveRedis class OrderSaveRedis
{ {
...@@ -29,7 +29,7 @@ class OrderSaveRedis ...@@ -29,7 +29,7 @@ class OrderSaveRedis
public function __construct(Order $order) public function __construct(Order $order)
{ {
$this->redis = \Events::getRedis(); $this->redis = app('Redis')();
$this->order = $order; $this->order = $order;
......
...@@ -15,7 +15,7 @@ use Application\model\OrderModel; ...@@ -15,7 +15,7 @@ use Application\model\OrderModel;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis; use Lib\cdz\order\save\OrderSaveRedis;
use Lib\Gateway; use Lib\Gateway;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\rabbitmq\PublishPortShed; use Lib\rabbitmq\PublishPortShed;
use Lib\remote\api\message\ChargerFullMessage; use Lib\remote\api\message\ChargerFullMessage;
use Lib\remote\api\message\ChargerShedMessage; use Lib\remote\api\message\ChargerShedMessage;
...@@ -49,7 +49,7 @@ class ChargerState extends State ...@@ -49,7 +49,7 @@ class ChargerState extends State
'updated_at' => $this->nowDate, 'updated_at' => $this->nowDate,
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
'state' => 1, 'state' => 1,
], 'id = ' . $this->order->getId()); ], 'id=' . $this->order->getId());
$port = new Port(); $port = new Port();
$port->setState(StateCode::PORT_ONLINE); $port->setState(StateCode::PORT_ONLINE);
...@@ -196,7 +196,7 @@ class ChargerState extends State ...@@ -196,7 +196,7 @@ class ChargerState extends State
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
'state' => 1, 'state' => 1,
], 'id = ' . $this->order->getId()); ], 'id=' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel(); $orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([ $orderExceptionModel->insertRow([
......
...@@ -12,7 +12,7 @@ namespace Lib\cdz\order\state; ...@@ -12,7 +12,7 @@ namespace Lib\cdz\order\state;
use GuzzleHttp\Psr7\LazyOpenStream; use GuzzleHttp\Psr7\LazyOpenStream;
use Lib\cdz\order\NoticePortShed; use Lib\cdz\order\NoticePortShed;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
class OfflineNetState extends State class OfflineNetState extends State
{ {
......
...@@ -11,7 +11,7 @@ namespace Lib\cdz\order\state; ...@@ -11,7 +11,7 @@ namespace Lib\cdz\order\state;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis; use Lib\cdz\order\save\OrderSaveRedis;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
class OfflinePowerState extends State class OfflinePowerState extends State
{ {
......
...@@ -13,7 +13,7 @@ use Application\model\OrderExceptionModel; ...@@ -13,7 +13,7 @@ use Application\model\OrderExceptionModel;
use Application\model\OrderModel; use Application\model\OrderModel;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis; use Lib\cdz\order\save\OrderSaveRedis;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\remote\api\message\ChargerReloadMessage; use Lib\remote\api\message\ChargerReloadMessage;
use Lib\remote\api\message\ChargerShedTimeOutMessage; use Lib\remote\api\message\ChargerShedTimeOutMessage;
use Lib\remote\api\message\ChargerTimeoutMessage; use Lib\remote\api\message\ChargerTimeoutMessage;
...@@ -36,12 +36,12 @@ class ShedState extends State ...@@ -36,12 +36,12 @@ class ShedState extends State
{ {
$orderModel = new OrderModel(); $orderModel = new OrderModel();
$orderModel->update([ $orderModel->update([
'is_stop' => $this->order->getEndCode(), 'is_stop' => $this->order->getEndCode(),
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
'updated_at' => $this->nowDate, 'updated_at' => $this->nowDate,
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
'state' => 1, 'state' => 1,
], 'id = ' . $this->order->getId()); ], 'id=' . $this->order->getId());
$port = new Port(); $port = new Port();
$port->setState(StateCode::PORT_ONLINE); $port->setState(StateCode::PORT_ONLINE);
...@@ -70,9 +70,9 @@ class ShedState extends State ...@@ -70,9 +70,9 @@ class ShedState extends State
$orderException = new OrderExceptionModel(); $orderException = new OrderExceptionModel();
$orderException->insertRow([ $orderException->insertRow([
'order_id' => $this->order->getId(), 'order_id' => $this->order->getId(),
'state' => StateCode::PORT_SHED . StateCode::FINISH_USER, 'state' => StateCode::PORT_SHED . StateCode::FINISH_USER,
'desc' => '用户主动结束充电', 'desc' => '用户主动结束充电',
'created_at' => $this->nowDate, 'created_at' => $this->nowDate,
]); ]);
...@@ -123,10 +123,10 @@ class ShedState extends State ...@@ -123,10 +123,10 @@ class ShedState extends State
$orderExceptionModel = new OrderExceptionModel(); $orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow( $orderExceptionModel->insertRow(
[ [
'order_id' => $this->order->getId(), 'order_id' => $this->order->getId(),
'state' => StateCode::PORT_SHED . StateCode::PORT_CHARGER, 'state' => StateCode::PORT_SHED . StateCode::PORT_CHARGER,
'created_at' => $this->nowDate, 'created_at' => $this->nowDate,
'desc' => '订单口子脱落重新插上', 'desc' => '订单口子脱落重新插上',
] ]
); );
...@@ -168,20 +168,20 @@ class ShedState extends State ...@@ -168,20 +168,20 @@ class ShedState extends State
{ {
$orderExceptionModel = new OrderExceptionModel(); $orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([ $orderExceptionModel->insertRow([
'order_id' => $this->order->getId(), 'order_id' => $this->order->getId(),
'state' => StateCode::PORT_SHED . StateCode::FINISH_SHED_TIMEOUT, 'state' => StateCode::PORT_SHED . StateCode::FINISH_SHED_TIMEOUT,
'created_at' => $this->nowDate, 'created_at' => $this->nowDate,
'desc' => '订单口子脱落超时结束', 'desc' => '订单口子脱落超时结束',
]); ]);
$orderModel = new OrderModel(); $orderModel = new OrderModel();
$orderModel->update([ $orderModel->update([
'state' => 1, 'state' => 1,
'updated_at' => $this->nowDate, 'updated_at' => $this->nowDate,
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
'is_stop' => StateCode::FINISH_SHED_TIMEOUT, 'is_stop' => StateCode::FINISH_SHED_TIMEOUT,
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
], 'id = ' . $this->order->getId()); ], 'id=' . $this->order->getId());
$port = new Port($this->order->getPortId()); $port = new Port($this->order->getPortId());
...@@ -205,10 +205,10 @@ class ShedState extends State ...@@ -205,10 +205,10 @@ class ShedState extends State
$orderModel = new OrderModel(); $orderModel = new OrderModel();
$orderModel->update([ $orderModel->update([
'is_stop' => StateCode::FINISH_SHED_TIMEOUT, 'is_stop' => StateCode::FINISH_SHED_TIMEOUT,
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
'state' => 1, 'state' => 1,
], 'id = ' . $this->order->getId()); ], 'id=' . $this->order->getId());
} }
...@@ -224,20 +224,20 @@ class ShedState extends State ...@@ -224,20 +224,20 @@ class ShedState extends State
{ {
$orderExceptionModel = new OrderExceptionModel(); $orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([ $orderExceptionModel->insertRow([
'order_id' => $this->order->getId(), 'order_id' => $this->order->getId(),
'state' => StateCode::PORT_SHED . StateCode::FINISH_TIME_END, 'state' => StateCode::PORT_SHED . StateCode::FINISH_TIME_END,
'created_at' => $this->nowDate, 'created_at' => $this->nowDate,
'desc' => '订单充电时间结束', 'desc' => '订单充电时间结束',
]); ]);
$orderModel = new OrderModel(); $orderModel = new OrderModel();
$orderModel->update([ $orderModel->update([
'is_stop' => StateCode::FINISH_TIME_END, 'is_stop' => StateCode::FINISH_TIME_END,
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
'state' => 1, 'state' => 1,
'updated_at' => $this->nowDate, 'updated_at' => $this->nowDate,
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
], 'id = ' . $this->order->getId()); ], 'id=' . $this->order->getId());
$port = new Port($this->order->getPortId()); $port = new Port($this->order->getPortId());
$port->setState(StateCode::PORT_ONLINE); $port->setState(StateCode::PORT_ONLINE);
......
...@@ -14,7 +14,7 @@ use Application\model\OrderModel; ...@@ -14,7 +14,7 @@ use Application\model\OrderModel;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis; use Lib\cdz\order\save\OrderSaveRedis;
use Lib\Gateway; use Lib\Gateway;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\remote\api\message\FailMessage; use Lib\remote\api\message\FailMessage;
use Lib\remote\api\message\SendMessage; use Lib\remote\api\message\SendMessage;
use Lib\remote\api\message\StartMessage; use Lib\remote\api\message\StartMessage;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
namespace Lib\iot; namespace Lib\iot;
use Illuminate\Support\Facades\Cache;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
class AccessToken implements Request class AccessToken implements Request
...@@ -60,24 +59,30 @@ class AccessToken implements Request ...@@ -60,24 +59,30 @@ class AccessToken implements Request
$this->accessToken = $body['accessToken']; $this->accessToken = $body['accessToken'];
$expiresLn = $body['expiresIn']; $expiresLn = $body['expiresIn'];
$this->refreshToken = $body['refreshToken']; $this->refreshToken = $body['refreshToken'];
Cache::put(self::ACCESS_CACHE_KEY, $this->accessToken, $expiresLn / 60); $redis = app('Redis');
Cache::put(self::REFRESH_ACCESS_CACHE_KEY, $this->refreshToken, 25 * 24 * 60); if ($redis instanceof \Redis) {
$redis->set(self::ACCESS_CACHE_KEY, $this->accessToken, $expiresLn);
$redis->set(self::REFRESH_ACCESS_CACHE_KEY, $this->refreshToken, 25 * 24 * 60);
}
} }
public static function getAccessTokenCache() public static function getAccessTokenCache()
{ {
// Cache::forget(self::ACCESS_CACHE_KEY);
// Cache::forget(self::REFRESH_ACCESS_CACHE_KEY);
if (Cache::has(self::ACCESS_CACHE_KEY) === true) { $redis = app('Redis');
// $redis->del(self::ACCESS_CACHE_KEY);
// $redis->del(self::REFRESH_ACCESS_CACHE_KEY);
if ($redis->exists(self::ACCESS_CACHE_KEY) == true) {
return Cache::get(self::ACCESS_CACHE_KEY); return $redis->get(self::ACCESS_CACHE_KEY);
} else if (Cache::has(self::REFRESH_ACCESS_CACHE_KEY) === true) { } else if ($redis->exists(self::REFRESH_ACCESS_CACHE_KEY) === true) {
//todo refresh 换取token 并缓存新的token和新的refresh //todo refresh 换取token 并缓存新的token和新的refresh
$refreshToken = new RefreshToken(); $refreshToken = new RefreshToken();
$refreshToken->setRefreshToken(Cache::get(self::REFRESH_ACCESS_CACHE_KEY)); $refreshToken->setRefreshToken($redis->get(self::REFRESH_ACCESS_CACHE_KEY));
$iotClient = new IotClient($refreshToken); $iotClient = new IotClient($refreshToken);
if ($iotClient->request() === true) { if ($iotClient->request() === true) {
$response = $iotClient->getResponse(); $response = $iotClient->getResponse();
......
...@@ -71,18 +71,11 @@ class IotClient ...@@ -71,18 +71,11 @@ class IotClient
if ($this->request->isJson() === false) { if ($this->request->isJson() === false) {
$request['form_params'] = $this->request->getFormData(); $request['form_params'] = $this->request->getFormData();
Log::debug($request);
$this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request); $this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request);
} else { } else {
$request['json'] = $this->request->getFormData(); $request['json'] = $this->request->getFormData();
Log::debug($request);
$this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request); $this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request);
} }
Log::debug($this->response->getStatusCode());
return $this->response->getStatusCode() === $returnCode; return $this->response->getStatusCode() === $returnCode;
} }
......
...@@ -63,6 +63,8 @@ class Send implements Request ...@@ -63,6 +63,8 @@ class Send implements Request
$length = 7 + strlen($body) / 2; $length = 7 + strlen($body) / 2;
$message = 'ffaa' . $this->commandInstance->getEncrypt() . ToHex::toHex($length, 2) . $nonce . $body; $message = 'ffaa' . $this->commandInstance->getEncrypt() . ToHex::toHex($length, 2) . $nonce . $body;
Log::debug($message);
if ($this->commandInstance->getEncrypt() === '04') { if ($this->commandInstance->getEncrypt() === '04') {
$this->command = [ $this->command = [
'serviceId' => $this->commandInstance->getServiceId(), 'serviceId' => $this->commandInstance->getServiceId(),
...@@ -179,7 +181,8 @@ class Send implements Request ...@@ -179,7 +181,8 @@ class Send implements Request
/** /**
* @return string * @return string
*/ */
public function getContentType(): string public
function getContentType(): string
{ {
return $this->contentType; return $this->contentType;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Lib\rabbitmq; namespace Lib\rabbitmq;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
class MyRabbitMq class MyRabbitMq
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Lib\rabbitmq; namespace Lib\rabbitmq;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
class PublishPortShed class PublishPortShed
{ {
......
...@@ -10,7 +10,7 @@ namespace Lib\remote\api\message; ...@@ -10,7 +10,7 @@ namespace Lib\remote\api\message;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
class SendMessage class SendMessage
{ {
......
...@@ -23,7 +23,7 @@ class Gateway ...@@ -23,7 +23,7 @@ class Gateway
public function setState(int $gatewayId, int $state) public function setState(int $gatewayId, int $state)
{ {
$redis = \Events::getRedis(); $redis = app('Redis');
return $redis->zAdd(self::GATEWAY_STATE, $state, $gatewayId); return $redis->zAdd(self::GATEWAY_STATE, $state, $gatewayId);
......
...@@ -10,7 +10,8 @@ namespace Lib\station\gateway\port; ...@@ -10,7 +10,8 @@ namespace Lib\station\gateway\port;
use Application\model\DeviceModel; use Application\model\DeviceModel;
use Lib\log\Log; use Illuminate\Support\Facades\Log;
use Lib\Session;
use Lib\StateCode; use Lib\StateCode;
use Lib\station\gateway\Gateway; use Lib\station\gateway\Gateway;
use Lib\station\Station; use Lib\station\Station;
...@@ -79,14 +80,15 @@ class Port ...@@ -79,14 +80,15 @@ class Port
*/ */
public function updatePortState(int $orderId = 0) public function updatePortState(int $orderId = 0)
{ {
$redis = \Events::getRedis(); $redis = app('Redis');
$redis->zAdd(self::PORT_STATE, $this->state, $this->portId); $redis->zAdd(self::PORT_STATE, $this->state, $this->portId);
if ($this->stationId === 0 || $this->gatewayId === 0) { if ($this->stationId === 0 || $this->gatewayId === 0) {
if (isset($_SESSION['gateway_id']) && isset($_SESSION['station_id'])) { if (filled(Session::get('gateway_id')) && filled(Session::get('station_id'))) {
$this->stationId = $_SESSION['station_id']; $this->stationId = Session::get('station_id');
$this->gatewayId = $_SESSION['gateway_id']; $this->gatewayId = Session::get('gateway_id');
} else { } else {
Log::error('can not find gateway_id or station_id from session'); Log::error('can not find gateway_id or station_id from session');
return; return;
...@@ -98,9 +100,9 @@ class Port ...@@ -98,9 +100,9 @@ class Port
$portModel = new DeviceModel(); $portModel = new DeviceModel();
$portModel->update([ $portModel->update([
'state' => $this->state, 'state' => $this->state,
'updated_at' => date('Y-m-d H:i:s') 'updated_at' => date('Y-m-d H:i:s')
], 'id = ' . $this->portId); ], 'id=' . $this->portId);
if ($orderId !== 0) { if ($orderId !== 0) {
$redis->zAdd('cdz:order:state:zset', $this->state, $orderId); $redis->zAdd('cdz:order:state:zset', $this->state, $orderId);
...@@ -113,7 +115,7 @@ class Port ...@@ -113,7 +115,7 @@ class Port
*/ */
public function getPortUsingOrderId() public function getPortUsingOrderId()
{ {
$redis = \Events::getRedis(); $redis = app('Redis');
return $redis->hGet(self::USING_ORDER_ID, $this->portId); return $redis->hGet(self::USING_ORDER_ID, $this->portId);
...@@ -127,7 +129,7 @@ class Port ...@@ -127,7 +129,7 @@ class Port
{ {
\Events::pipe(); \Events::pipe();
$redis = \Events::getRedis(); $redis = app('Redis');
$this->state = StateCode::PORT_ONLINE; $this->state = StateCode::PORT_ONLINE;
...@@ -155,7 +157,7 @@ class Port ...@@ -155,7 +157,7 @@ class Port
\Events::pipe(); \Events::pipe();
$redis = \Events::getRedis(); $redis = app('Redis');
$redis->zDelete(self::USING_USER_ID, $this->portId); $redis->zDelete(self::USING_USER_ID, $this->portId);
...@@ -264,7 +266,7 @@ class Port ...@@ -264,7 +266,7 @@ class Port
public function addUsingOrder(int $portId, int $orderId) public function addUsingOrder(int $portId, int $orderId)
{ {
$redis = \Events::getRedis(); $redis = app('Redis');
$redis->hSet(self::USING_ORDER_ID, $portId, $orderId); $redis->hSet(self::USING_ORDER_ID, $portId, $orderId);
......
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
$router->get('/', function () use ($router) { $router->get('/', function () use ($router) {
\Illuminate\Support\Facades\Log::debug('hello');
return $router->app->version(); return $router->app->version();
}); });
...@@ -30,6 +28,9 @@ $router->post('subscriber/setting', ['uses' => 'subscribe\SettingController@set' ...@@ -30,6 +28,9 @@ $router->post('subscriber/setting', ['uses' => 'subscribe\SettingController@set'
$router->get('subscriber/display/mass', ['uses' => 'subscribe\QueryController@mass']); $router->get('subscriber/display/mass', ['uses' => 'subscribe\QueryController@mass']);
$router->post('device/update', 'device\MessageController@receiver'); $router->post('device/update', 'device\MessageController@receiver');
$router->get('device/update', 'device\MessageController@receiver');
$router->post('message/register', 'TestController@test');
class Application{
}
\ No newline at end of file
...@@ -5,7 +5,7 @@ namespace Src\response; ...@@ -5,7 +5,7 @@ namespace Src\response;
use Application\controller\Controller; use Application\controller\Controller;
use Src\request\Request; use Src\request\Request;
use Lib\Crc; use Lib\Crc;
use Lib\Gateway; use Application\Gateway;
class Response class Response
{ {
...@@ -68,7 +68,7 @@ class Response ...@@ -68,7 +68,7 @@ class Response
/** /**
* @var string * @var string
*/ */
private $clientId =''; private $clientId = '';
public function __construct(string $clientId, string $headerFlag) public function __construct(string $clientId, string $headerFlag)
{ {
...@@ -125,8 +125,6 @@ class Response ...@@ -125,8 +125,6 @@ class Response
} }
} }
......
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