|
|
@ -16,15 +16,59 @@ class YingShiSdk |
|
|
*/ |
|
|
*/ |
|
|
protected static $deviceSerial = 'BB6305392'; |
|
|
protected static $deviceSerial = 'BB6305392'; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* appKey |
|
|
|
|
|
* @var string |
|
|
|
|
|
*/ |
|
|
|
|
|
protected static $appKey = '62b00fd48ad3473690ca5f3865a01713'; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* appSecret |
|
|
|
|
|
* @var string |
|
|
|
|
|
*/ |
|
|
|
|
|
protected static $appSecret = '07a97d565dd19bd8081439119c2a3d95'; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取AccessToken |
|
|
|
|
|
* @return string|void |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function getAccessToken() |
|
|
|
|
|
{ |
|
|
|
|
|
$url = 'https://open.ys7.com/api/lapp/token/get'; |
|
|
|
|
|
|
|
|
|
|
|
$result = self::curlYingshiApi($url,[ |
|
|
|
|
|
'appKey' => self::$appKey, |
|
|
|
|
|
'appSecret' => self::$appSecret |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
$err = $result['err']; |
|
|
|
|
|
|
|
|
|
|
|
if ($err) return "cURL Error #:" . $err; |
|
|
|
|
|
|
|
|
|
|
|
$response = $result['response']; |
|
|
|
|
|
|
|
|
|
|
|
$jsonResponse = json_decode($response,true); |
|
|
|
|
|
|
|
|
|
|
|
if ($jsonResponse['code'] != '200') return $jsonResponse['msg']; |
|
|
|
|
|
|
|
|
|
|
|
self::$accessToken = $jsonResponse['data']['accessToken']; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取设备状态信息 |
|
|
* 获取设备状态信息 |
|
|
* @return mixed|string |
|
|
* @return mixed|string |
|
|
*/ |
|
|
*/ |
|
|
public static function DeviceStatus() |
|
|
public static function DeviceStatus() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
self::getAccessToken(); |
|
|
|
|
|
|
|
|
$url = 'https://open.ys7.com/api/lapp/device/status/get'; |
|
|
$url = 'https://open.ys7.com/api/lapp/device/status/get'; |
|
|
|
|
|
|
|
|
$curlData = self::curlYingshiApi($url,self::$accessToken,self::$deviceSerial); |
|
|
$curlData = self::curlYingshiApi($url,[ |
|
|
|
|
|
'accessToken' => self::$accessToken, |
|
|
|
|
|
'deviceSerial' => self::$deviceSerial |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$err = $curlData['err']; |
|
|
$err = $curlData['err']; |
|
|
$response = $curlData['response']; |
|
|
$response = $curlData['response']; |
|
|
@ -45,9 +89,14 @@ class YingShiSdk |
|
|
public static function DeviceInfo() |
|
|
public static function DeviceInfo() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
self::getAccessToken(); |
|
|
|
|
|
|
|
|
$url = 'https://open.ys7.com/api/lapp/device/info'; |
|
|
$url = 'https://open.ys7.com/api/lapp/device/info'; |
|
|
|
|
|
|
|
|
$curlDataInfo = YingShiSdk::curlYingshiApi($url,self::$accessToken,self::$deviceSerial); |
|
|
$curlDataInfo = YingShiSdk::curlYingshiApi($url,[ |
|
|
|
|
|
'accessToken' => self::$accessToken, |
|
|
|
|
|
'deviceSerial' => self::$deviceSerial |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$err = $curlDataInfo['err']; |
|
|
$err = $curlDataInfo['err']; |
|
|
|
|
|
|
|
|
@ -65,22 +114,25 @@ class YingShiSdk |
|
|
/** |
|
|
/** |
|
|
* 请求接口数据 |
|
|
* 请求接口数据 |
|
|
* @param $url // 请求地址 |
|
|
* @param $url // 请求地址 |
|
|
* @param $accessToken // token |
|
|
* @param $data // 请求参数 |
|
|
* @param $deviceSerial // 设备ID |
|
|
|
|
|
* @return array |
|
|
* @return array |
|
|
*/ |
|
|
*/ |
|
|
public static function curlYingshiApi($url,$accessToken,$deviceSerial) |
|
|
public static function curlYingshiApi($url,$data,$query = 'POST') |
|
|
{ |
|
|
{ |
|
|
|
|
|
$dataArr = []; |
|
|
|
|
|
foreach ($data as $key => $value) $dataArr[] = $key . '=' . $value; |
|
|
|
|
|
$dataStr = implode('&',$dataArr); |
|
|
|
|
|
|
|
|
$curl = curl_init(); |
|
|
$curl = curl_init(); |
|
|
|
|
|
|
|
|
curl_setopt_array($curl, [ |
|
|
curl_setopt_array($curl, [ |
|
|
CURLOPT_URL => "{$url}?accessToken={$accessToken}&deviceSerial={$deviceSerial}", |
|
|
CURLOPT_URL => "{$url}?{$dataStr}", |
|
|
CURLOPT_RETURNTRANSFER => true, |
|
|
CURLOPT_RETURNTRANSFER => true, |
|
|
CURLOPT_ENCODING => "", |
|
|
CURLOPT_ENCODING => "", |
|
|
CURLOPT_MAXREDIRS => 10, |
|
|
CURLOPT_MAXREDIRS => 10, |
|
|
CURLOPT_TIMEOUT => 30, |
|
|
CURLOPT_TIMEOUT => 30, |
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
|
CURLOPT_CUSTOMREQUEST => "POST", |
|
|
CURLOPT_CUSTOMREQUEST => $query, |
|
|
CURLOPT_HTTPHEADER => [ |
|
|
CURLOPT_HTTPHEADER => [ |
|
|
"Content-Type: application/x-www-form-urlencoded" |
|
|
"Content-Type: application/x-www-form-urlencoded" |
|
|
], |
|
|
], |
|
|
|