Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cdz_nb
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨苏杭
cdz_nb
Commits
9986903a
Commit
9986903a
authored
Sep 30, 2018
by
banice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command创建成
parent
9289eba3
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
313 additions
and
19 deletions
+313
-19
app/Http/Controllers/access/AccessController.php
+1
-0
app/Http/Controllers/device/ChargerController.php
+31
-2
lib/iot/AccessToken.php
+13
-3
lib/iot/IotClient.php
+14
-4
lib/iot/RefreshToken.php
+0
-0
lib/iot/Request.php
+2
-0
lib/iot/command/ChargerCommand.php
+65
-0
lib/iot/command/Send.php
+186
-10
routes/web.php
+1
-0
No files found.
app/Http/Controllers/access/AccessController.php
View file @
9986903a
...
@@ -20,6 +20,7 @@ class AccessController extends Controller
...
@@ -20,6 +20,7 @@ class AccessController extends Controller
public
function
accessToken
(
AccessToken
$accessToken
)
public
function
accessToken
(
AccessToken
$accessToken
)
{
{
$iotClient
=
new
IotClient
(
$accessToken
);
$iotClient
=
new
IotClient
(
$accessToken
);
if
(
$iotClient
->
request
()
===
true
)
{
if
(
$iotClient
->
request
()
===
true
)
{
...
...
app/Http/Controllers/device/ChargerController.php
View file @
9986903a
...
@@ -11,14 +11,42 @@ namespace App\Http\Controllers\device;
...
@@ -11,14 +11,42 @@ namespace App\Http\Controllers\device;
use
App\Http\Controllers\Controller
;
use
App\Http\Controllers\Controller
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Log
;
use
Lib\iot\command\ChargerCommand
;
use
Lib\iot\command\Send
;
class
ChargerController
extends
Controller
class
ChargerController
extends
Controller
{
{
public
function
charger
(
Request
$request
)
/**
* @param Request $request
* @param ChargerCommand $chargerCommand
* @throws \Exception
*/
public
function
charger
(
Request
$request
,
ChargerCommand
$chargerCommand
)
{
{
$chargerCommand
->
setOrderId
(
123
);
$chargerCommand
->
setTime
(
12
);
$chargerCommand
->
setPortLogic
(
1
);
$chargerCommand
->
setServiceId
(
'Transmission'
);
$chargerCommand
->
setMethod
(
'Cmd_Res'
);
$send
=
new
Send
(
$chargerCommand
);
$send
->
setCallBackUrl
(
route
(
'deviceChargerReceiver'
));
$send
->
setDeviceId
(
'd245d3fd-26e1-4818-95b9-37e6af3cfcf7'
);
if
(
$send
->
send
()
===
true
)
{
dd
(
'success'
);
dd
(
1
);
}
}
public
function
receiver
(
Request
$request
)
{
Log
::
debug
(
$request
->
all
());
}
}
}
}
\ No newline at end of file
lib/iot/AccessToken.php
View file @
9986903a
...
@@ -35,16 +35,23 @@ class AccessToken implements Request
...
@@ -35,16 +35,23 @@ class AccessToken implements Request
public
function
__construct
()
public
function
__construct
()
{
{
$this
->
appId
=
env
(
'APP_ID'
);
$this
->
appId
=
env
(
'
IOT_
APP_ID'
);
$this
->
appSecret
=
env
(
'APP_SECRET'
);
$this
->
appSecret
=
env
(
'
IOT_
APP_SECRET'
);
}
}
public
function
isJson
()
:
bool
{
return
false
;
}
public
function
parseResponse
(
ResponseInterface
$response
)
public
function
parseResponse
(
ResponseInterface
$response
)
{
{
$body
=
json_decode
(
$response
->
getBody
(),
true
);
$body
=
json_decode
(
$response
->
getBody
(),
true
);
$this
->
accessToken
=
$body
[
'accessToken'
];
$this
->
accessToken
=
$body
[
'accessToken'
];
$expiresLn
=
$body
[
'expires
L
n'
];
$expiresLn
=
$body
[
'expires
I
n'
];
$this
->
refreshToken
=
$body
[
'refreshToken'
];
$this
->
refreshToken
=
$body
[
'refreshToken'
];
Cache
::
put
(
self
::
ACCESS_CACHE_KEY
,
$this
->
accessToken
,
$expiresLn
/
60
);
Cache
::
put
(
self
::
ACCESS_CACHE_KEY
,
$this
->
accessToken
,
$expiresLn
/
60
);
Cache
::
put
(
self
::
REFRESH_ACCESS_CACHE_KEY
,
$this
->
refreshToken
,
28
*
24
*
60
);
Cache
::
put
(
self
::
REFRESH_ACCESS_CACHE_KEY
,
$this
->
refreshToken
,
28
*
24
*
60
);
...
@@ -54,6 +61,9 @@ class AccessToken implements Request
...
@@ -54,6 +61,9 @@ class AccessToken implements Request
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
)
{
if
(
Cache
::
has
(
self
::
ACCESS_CACHE_KEY
)
===
true
)
{
return
Cache
::
get
(
self
::
ACCESS_CACHE_KEY
);
return
Cache
::
get
(
self
::
ACCESS_CACHE_KEY
);
...
...
lib/iot/IotClient.php
View file @
9986903a
...
@@ -43,14 +43,11 @@ class IotClient
...
@@ -43,14 +43,11 @@ class IotClient
$client
=
new
Client
();
$client
=
new
Client
();
Log
::
debug
(
storage_path
(
'cert/key.pem'
));
$request
=
[
$request
=
[
'form_params'
=>
$this
->
request
->
getFormData
(),
'verify'
=>
false
,
'verify'
=>
false
,
'cert'
=>
[
'cert'
=>
[
config
(
'
cer
t.cert_path'
),
config
(
'
io
t.cert_path'
),
'IoM@1234'
,
'IoM@1234'
,
]
]
];
];
...
@@ -58,7 +55,20 @@ class IotClient
...
@@ -58,7 +55,20 @@ class IotClient
$request
[
'headers'
]
=
$this
->
headers
;
$request
[
'headers'
]
=
$this
->
headers
;
}
}
if
(
$this
->
request
->
isJson
()
===
false
)
{
$request
[
'form_params'
]
=
$this
->
request
->
getFormData
();
$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
{
$request
[
'json'
]
=
$this
->
request
->
getFormData
();
Log
::
debug
(
$request
);
$this
->
response
=
$client
->
request
(
$this
->
request
->
getMethod
(),
config
(
'iot.host'
)
.
$this
->
request
->
getUrl
(),
$request
);
}
Log
::
debug
(
$request
);
Log
::
debug
(
$this
->
response
->
getBody
());
return
$this
->
response
->
getStatusCode
()
===
200
;
return
$this
->
response
->
getStatusCode
()
===
200
;
...
...
lib/iot/RefreshToken.php
View file @
9986903a
lib/iot/Request.php
View file @
9986903a
...
@@ -22,5 +22,6 @@ interface Request
...
@@ -22,5 +22,6 @@ interface Request
public
function
parseResponse
(
ResponseInterface
$response
);
public
function
parseResponse
(
ResponseInterface
$response
);
public
function
isJson
()
:
bool
;
}
}
\ No newline at end of file
lib/iot/command/ChargerCommand.php
View file @
9986903a
...
@@ -31,5 +31,69 @@ class ChargerCommand extends Command
...
@@ -31,5 +31,69 @@ class ChargerCommand extends Command
}
}
/**
* @return int
*/
public
function
getType
()
:
int
{
return
$this
->
type
;
}
/**
* @param int $type
*/
public
function
setType
(
int
$type
)
:
void
{
$this
->
type
=
$type
;
}
/**
* @return int
*/
public
function
getPortLogic
()
:
int
{
return
$this
->
portLogic
;
}
/**
* @param int $portLogic
*/
public
function
setPortLogic
(
int
$portLogic
)
:
void
{
$this
->
portLogic
=
$portLogic
;
}
/**
* @return int
*/
public
function
getOrderId
()
:
int
{
return
$this
->
orderId
;
}
/**
* @param int $orderId
*/
public
function
setOrderId
(
int
$orderId
)
:
void
{
$this
->
orderId
=
$orderId
;
}
/**
* @return int
*/
public
function
getTime
()
:
int
{
return
$this
->
time
;
}
/**
* @param int $time
*/
public
function
setTime
(
int
$time
)
:
void
{
$this
->
time
=
$time
;
}
}
}
\ No newline at end of file
lib/iot/command/Send.php
View file @
9986903a
...
@@ -51,6 +51,9 @@ class Send implements Request
...
@@ -51,6 +51,9 @@ class Send implements Request
*/
*/
public
function
__construct
(
Command
$command
)
public
function
__construct
(
Command
$command
)
{
{
$this
->
appId
=
env
(
'IOT_APP_ID'
);
$this
->
appKey
=
env
(
'IOT_APP_ID'
);
$this
->
commandInstance
=
$command
;
$this
->
commandInstance
=
$command
;
$body
=
$this
->
commandInstance
->
getMessage
();
$body
=
$this
->
commandInstance
->
getMessage
();
...
@@ -62,7 +65,7 @@ class Send implements Request
...
@@ -62,7 +65,7 @@ class Send implements Request
$this
->
command
=
[
$this
->
command
=
[
'serviceId'
=>
$this
->
commandInstance
->
getServiceId
(),
'serviceId'
=>
$this
->
commandInstance
->
getServiceId
(),
'method'
=>
$this
->
commandInstance
->
getMethod
(),
'method'
=>
$this
->
commandInstance
->
getMethod
(),
'paras'
=>
json_encode
(
$message
),
// 'paras' => json_encode(['downData' => $message]
),
];
];
}
else
{
}
else
{
...
@@ -71,14 +74,15 @@ class Send implements Request
...
@@ -71,14 +74,15 @@ class Send implements Request
}
}
}
}
public
function
send
()
public
function
send
()
:
bool
{
{
$iotClient
=
new
IotClient
(
$this
);
$iotClient
=
new
IotClient
(
$this
);
$iotClient
->
setHeaders
([
$iotClient
->
setHeaders
([
'app_key'
=>
env
(
'IOT_APP_KEY'
),
'app_key'
=>
$this
->
appKey
,
'Authorization'
=>
'Bearer'
.
AccessToken
::
getAccessTokenCache
(),
'Authorization'
=>
'Bearer '
.
AccessToken
::
getAccessTokenCache
(),
// 'Authorization' => 'Bearer ' . '60fe212de43e9615cf342d0e354441c',
'Content-Type'
=>
'application/json'
'Content-Type'
=>
'application/json'
]);
]);
...
@@ -88,8 +92,13 @@ class Send implements Request
...
@@ -88,8 +92,13 @@ class Send implements Request
Log
::
debug
(
$response
->
getBody
());
Log
::
debug
(
$response
->
getBody
());
return
true
;
}
}
return
false
;
}
}
public
function
getUrl
()
:
string
public
function
getUrl
()
:
string
...
@@ -98,6 +107,12 @@ class Send implements Request
...
@@ -98,6 +107,12 @@ class Send implements Request
}
}
public
function
isJson
()
:
bool
{
return
true
;
}
public
function
getMethod
()
:
string
public
function
getMethod
()
:
string
{
{
return
'POST'
;
return
'POST'
;
...
@@ -108,12 +123,12 @@ class Send implements Request
...
@@ -108,12 +123,12 @@ class Send implements Request
public
function
getFormData
()
:
array
public
function
getFormData
()
:
array
{
{
return
[
return
[
'appId'
=>
env
(
'IOT_APP_ID'
)
,
// 'appId' => $this->appId
,
'deviceId'
=>
$this
->
deviceId
,
'deviceId'
=>
$this
->
deviceId
,
'command'
=>
json_encode
(
$this
->
command
)
,
'command'
=>
$this
->
command
,
'callbackUrl'
=>
$this
->
callBackUrl
,
// 'callbackUrl'
=> $this->callBackUrl,
'expireTime'
=>
$this
->
expireTime
,
// 'expireTime'
=> $this->expireTime,
'maxRetransmit'
=>
$this
->
maxRetransmit
,
//
'maxRetransmit' => $this->maxRetransmit,
];
];
}
}
...
@@ -123,5 +138,165 @@ class Send implements Request
...
@@ -123,5 +138,165 @@ class Send implements Request
// TODO: Implement parseResponse() method.
// TODO: Implement parseResponse() method.
}
}
/**
* @return string
*/
public
function
getAccessToken
()
:
string
{
return
$this
->
accessToken
;
}
/**
* @param string $accessToken
*/
public
function
setAccessToken
(
string
$accessToken
)
:
void
{
$this
->
accessToken
=
$accessToken
;
}
/**
* @return string
*/
public
function
getAppKey
()
:
string
{
return
$this
->
appKey
;
}
/**
* @param string $appKey
*/
public
function
setAppKey
(
string
$appKey
)
:
void
{
$this
->
appKey
=
$appKey
;
}
/**
* @return string
*/
public
function
getContentType
()
:
string
{
return
$this
->
contentType
;
}
/**
* @param string $contentType
*/
public
function
setContentType
(
string
$contentType
)
:
void
{
$this
->
contentType
=
$contentType
;
}
/**
* @return string
*/
public
function
getAppId
()
:
string
{
return
$this
->
appId
;
}
/**
* @param string $appId
*/
public
function
setAppId
(
string
$appId
)
:
void
{
$this
->
appId
=
$appId
;
}
/**
* @return string
*/
public
function
getDeviceId
()
:
string
{
return
$this
->
deviceId
;
}
/**
* @param string $deviceId
*/
public
function
setDeviceId
(
string
$deviceId
)
:
void
{
$this
->
deviceId
=
$deviceId
;
}
/**
* @return array|string
*/
public
function
getCommand
()
{
return
$this
->
command
;
}
/**
* @param array|string $command
*/
public
function
setCommand
(
$command
)
:
void
{
$this
->
command
=
$command
;
}
/**
* @return Command
*/
public
function
getCommandInstance
()
:
Command
{
return
$this
->
commandInstance
;
}
/**
* @param Command $commandInstance
*/
public
function
setCommandInstance
(
Command
$commandInstance
)
:
void
{
$this
->
commandInstance
=
$commandInstance
;
}
/**
* @return string
*/
public
function
getCallBackUrl
()
:
string
{
return
$this
->
callBackUrl
;
}
/**
* @param string $callBackUrl
*/
public
function
setCallBackUrl
(
string
$callBackUrl
)
:
void
{
$this
->
callBackUrl
=
$callBackUrl
;
}
/**
* @return int
*/
public
function
getExpireTime
()
:
int
{
return
$this
->
expireTime
;
}
/**
* @param int $expireTime
*/
public
function
setExpireTime
(
int
$expireTime
)
:
void
{
$this
->
expireTime
=
$expireTime
;
}
/**
* @return int
*/
public
function
getMaxRetransmit
()
:
int
{
return
$this
->
maxRetransmit
;
}
/**
* @param int $maxRetransmit
*/
public
function
setMaxRetransmit
(
int
$maxRetransmit
)
:
void
{
$this
->
maxRetransmit
=
$maxRetransmit
;
}
}
}
\ No newline at end of file
routes/web.php
View file @
9986903a
...
@@ -22,3 +22,4 @@ $router->get('access', 'access\AccessController@accessToken');
...
@@ -22,3 +22,4 @@ $router->get('access', 'access\AccessController@accessToken');
$router
->
post
(
'device/power/on'
,
'device\ChargerController@charger'
);
$router
->
post
(
'device/power/on'
,
'device\ChargerController@charger'
);
$router
->
post
(
'device/power/on/receiver'
,
[
'uses'
=>
'device\ChargerController@receiver'
,
'as'
=>
'deviceChargerReceiver'
]);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment