TdwyController.php 2.3 KB

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