helper.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. $result = json_decode($response->getBody()->getContents(), true);
  36. if ($result['status_code'] == 200) {
  37. return $result['data'];
  38. } else {
  39. return [];
  40. }
  41. } catch (\Exception $exception) {
  42. return [];
  43. }
  44. }