TdwyController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qiuzijian
  5. * Date: 3/17/22
  6. * Time: 7:01 PM
  7. */
  8. namespace Modules\Camera\Http\Controllers\Api;
  9. use App\Http\Controllers\Api\BaseController;
  10. use Illuminate\Support\Facades\Input;
  11. class TdwyController extends BaseController
  12. {
  13. protected $pre_url; // 请求地址
  14. protected $username; // 请求username
  15. protected $password; // 请求password
  16. protected $sysId; // 请求sysId
  17. public function __construct()
  18. {
  19. $this->pre_url = Input::get('url');
  20. $this->username = Input::get('username');
  21. $this->password = Input::get('password');
  22. $this->sysId = Input::get('sysId');
  23. }
  24. //登录获取token
  25. protected function loginUser()
  26. {
  27. $url = '/pangu/sdkServer/user/loginUser';
  28. $params = [
  29. 'username' => $this->username,
  30. 'password' => $this->password,
  31. 'sysId' => $this->sysId,
  32. ];
  33. $result = $this->curlPost($this->pre_url . $url, json_encode($params));
  34. $result = json_decode($result, true);
  35. return $result;
  36. }
  37. /**
  38. * 发送请求
  39. * @param string $url
  40. * @param string $postData
  41. * @param array $options
  42. * @return bool|string
  43. */
  44. public function curlPost($url = '', $postData = '', $options = array())
  45. {
  46. if (is_array($postData)) {
  47. $postData = http_build_query($postData);
  48. }
  49. $ch = curl_init();
  50. curl_setopt($ch, CURLOPT_URL, $url);
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  52. curl_setopt($ch, CURLOPT_POST, 1);
  53. curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  54. curl_setopt($ch, CURLOPT_TIMEOUT, 30); //设置cURL允许执行的最长秒数
  55. curl_setopt_array($ch, array(
  56. CURLOPT_HTTPHEADER => array(
  57. "Accept:" . '*/*',
  58. "Content-Type:" . 'application/json',
  59. "x-Ca-Key:" . $this->app_key,
  60. "X-Ca-Signature:" . $this->sign,
  61. "X-Ca-Timestamp:" . $this->time,
  62. "X-Ca-Signature-Headers:" . "x-ca-key,x-ca-timestamp",
  63. )
  64. ));
  65. //https请求 不验证证书和host
  66. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  67. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  68. $data = curl_exec($ch);
  69. curl_close($ch);
  70. return $data;
  71. }
  72. }