123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?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 generateSign(array $params, $secret_key)
- {
- unset($params['sign']);
-
- $params = array_filter($params);
-
- ksort($params);
-
- $params['chxq_key'] = $secret_key;
-
- $str = http_build_query($params);
- $str = urldecode($str);
-
- return strtoupper(MD5($str));
- }
- function verifySign($sign, $params, $secret_key)
- {
- if ($sign == generateSign($params, $secret_key)) {
- return true;
- } else {
- return false;
- };
- }
- function jsonSuccess($data = [], $msg = "成功")
- {
- $response = array(
- 'code' => 0,
- 'msg' => $msg,
- 'data' => []
- );
- if ($data) {
- if (is_array($data)) {
-
- if (isset($data['meta'])) {
-
- $temp = array(
- 'data' => array(
- 'data' => $data['data'],
- 'pagination' => $data['meta']['pagination']
- )
- );
- $response = array_merge($response, $temp);
- } elseif(isset($data['data'])) {
- $response = array_merge($response, $data);
- }else{
- $temp = array(
- 'data' => $data
- );
- $response = array_merge($response, $temp);
- }
- } else {
- $response['data'] = $data;
- }
- }
- return $response;
- }
- function jsonError($msg)
- {
- $response = array(
- 'code' => 1,
- 'msg' => $msg,
- 'data' => ""
- );
- return $response;
- }
- function http($url, $param, $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 (isset($result['code']) && $result['code'] == 0) {
- return $result['data'];
- } else {
- return [];
- }
- } catch (\Exception $exception) {
- return [];
- }
- }
|