TdwyController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. public 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. )
  60. ));
  61. //https请求 不验证证书和host
  62. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  63. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  64. $data = curl_exec($ch);
  65. curl_close($ch);
  66. return $data;
  67. }
  68. }