helper.php 951 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. function subtext($text, $length)
  18. {
  19. if(mb_strlen($text, 'utf8') > $length) {
  20. return mb_substr($text, 0, $length, 'utf8').'...';
  21. } else {
  22. return $text;
  23. }
  24. }
  25. }
  26. function http($url, $param, $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. if ($result['code'] == 0) {
  33. return $result['data'];
  34. } else {
  35. return [];
  36. }
  37. } catch (\Exception $exception) {
  38. return [];
  39. }
  40. }