helper.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. if (! function_exists('public_path')) {
  19. /**
  20. * Get the path to the public folder.
  21. *
  22. * @param string $path
  23. * @return string
  24. */
  25. function public_path($path = '')
  26. {
  27. return app()->basePath() . '/public' . ($path ? '/' . $path : $path);
  28. }
  29. }
  30. function http($url, $param, $method = 'post')
  31. {
  32. try {
  33. $client = new \GuzzleHttp\Client();
  34. $response = $client->request($method, $url, $param);
  35. \Illuminate\Support\Facades\Log::debug($response);
  36. $result = json_decode($response->getBody()->getContents(), true);
  37. \Illuminate\Support\Facades\Log::debug(\GuzzleHttp\json_encode($result));
  38. if ($result['code'] == 0) {
  39. \Illuminate\Support\Facades\Log::debug(\GuzzleHttp\json_encode($result['data']));
  40. return $result['data'];
  41. } else {
  42. return [];
  43. }
  44. } catch (\Exception $exception) {
  45. return [];
  46. }
  47. }