Dahua.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\admin\controller;
  3. use GuzzleHttp\Client;
  4. use think\Controller;
  5. use think\Db;
  6. class Dahua extends Base
  7. {
  8. public function index(){
  9. $content = file_get_contents('http://127.0.0.1:4481/demo.php');
  10. $this->assign('content',$content);
  11. return $this->fetch();
  12. }
  13. public function token(){
  14. $client_id = "re4e28ee63ef094215b80fb92eb938bdb9";
  15. $client_secret = "9c6570bc78215b6c84e0a0639d50c91a";
  16. // $client_id = "re4e28ee63ef094215b80fb92eb938bdb9";
  17. // $client_secret = "9c6570bc78215b6c84e0a0639d50c91a";
  18. $url = "https://www.cloud-dahua.com/gateway/auth/oauth/token?grant_type=client_credentials&scope=server&client_id={$client_id}&client_secret={$client_secret}";
  19. $ret = curl_post($url,[]);
  20. $ret = json_decode($ret,true);
  21. return json($ret);
  22. }
  23. public function device(){
  24. $authorization = request()->header()['authorization'];
  25. // $authorization = "Bearer 2d99f770-81f3-4921-be31-2d766db87323";
  26. $url = "https://www.cloud-dahua.com/gateway/device/api/page";
  27. $data = [
  28. 'pageNum' => 1,
  29. 'pageSize' => 200
  30. ];
  31. $ret = curl_post($url,json_encode($data),['Content-Type: application/json','Authorization:'.$authorization]);
  32. // halt($ret);
  33. $ret = json_decode($ret,true);
  34. return json($ret);
  35. }
  36. public function lechange(){
  37. $authorization = request()->header()['authorization'];
  38. $url = "https://www.cloud-dahua.com/gateway/device/api/lechangeToken";
  39. $ret = curl_post($url,[],['Content-Type: application/json','Authorization:'.$authorization]);
  40. $ret = json_decode($ret,true);
  41. return json($ret);
  42. }
  43. }