123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- if ( ! function_exists('config_path'))
- {
-
- function config_path($path = '')
- {
- return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
- }
- }
- if (! function_exists('public_path')) {
-
- function public_path($path = '')
- {
- return app()->basePath() . '/public' . ($path ? '/' . $path : $path);
- }
- }
- function subtext($text, $length)
- {
- if(mb_strlen($text, 'utf8') > $length) {
- return mb_substr($text, 0, $length, 'utf8').'...';
- } else {
- return $text;
- }
- }
- 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) {
- if ($result['code'] == 0) {
- return $result['data'];
- } else {
- return [];
- }
- } else {
- return $result;
- }
- } catch (\Exception $exception) {
- \Illuminate\Support\Facades\Log::debug('http-exception:'.$exception->getMessage());
- return [];
- }
- }
- function generateSign(array $params, $secret_key)
- {
- unset($params['sign']);
-
- $params = array_filter($params);
-
- ksort($params);
-
- $params['chxq_key'] = $secret_key;
- \Illuminate\Support\Facades\Log::debug($params);
-
- $str = http_build_query($params);
- $str = urldecode($str);
- \Illuminate\Support\Facades\Log::debug($str);
-
-
-
- return strtoupper(MD5($str));
- }
|