123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- /**
- * 添加自定义辅助函数
- */
- if ( ! function_exists('config_path'))
- {
- /**
- * Get the configuration path.
- *
- * @param string $path
- * @return string
- */
- function config_path($path = '')
- {
- return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
- }
- }
- /**
- * @param $url 地址
- * @param $param 参数
- * @param bool $isCheck 是否检查返回结果
- * @param string $method 请求方式
- * @return array|mixed
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- function http($url, $param, $isCheck = true, $method = 'post')
- {
- try {
- $client = new \GuzzleHttp\Client();
- $response = $client->request($method, $url, $param);
- $result = json_decode($response->getBody()->getContents(), true);
- \Illuminate\Support\Facades\Log::debug('url:'.$url.'param:'.json_encode($param).'response:'.json_encode($result));
- if ($isCheck == true) {
- return $result['data'];
- } else {
- return $result;
- }
- } catch (\Exception $exception) {
- return [];
- }
- }
|