helper.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * 添加自定义辅助函数
  4. */
  5. if ( ! function_exists('config_path'))
  6. {
  7. /**
  8. * Get the configuration path.
  9. *
  10. * @param string $path
  11. * @return string
  12. */
  13. function config_path($path = '')
  14. {
  15. return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
  16. }
  17. }
  18. /**
  19. * @param $url 地址
  20. * @param $param 参数
  21. * @param bool $isCheck 是否检查返回结果
  22. * @param string $method 请求方式
  23. * @return array|mixed
  24. * @throws \GuzzleHttp\Exception\GuzzleException
  25. */
  26. function http($url, $param, $isCheck = true, $method = 'post')
  27. {
  28. try {
  29. $client = new \GuzzleHttp\Client();
  30. $response = $client->request($method, $url, $param);
  31. $result = json_decode($response->getBody()->getContents(), true);
  32. \Illuminate\Support\Facades\Log::debug('url:'.$url.'param:'.json_encode($param).'response:'.json_encode($result));
  33. if ($isCheck == true) {
  34. return $result['data'];
  35. } else {
  36. return $result;
  37. }
  38. } catch (\Exception $exception) {
  39. return [];
  40. }
  41. }