|
@@ -17,6 +17,21 @@ if ( ! function_exists('config_path'))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+if (! function_exists('public_path')) {
|
|
|
+ /**
|
|
|
+ * Get the path to the public folder.
|
|
|
+ *
|
|
|
+ * @param string $path
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ function public_path($path = '')
|
|
|
+ {
|
|
|
+ return app()->basePath() . '/public' . ($path ? '/' . $path : $path);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 参数签名校验
|
|
|
* @param array $params
|
|
@@ -59,46 +74,64 @@ function verifySign($sign, $params, $secret_key)
|
|
|
|
|
|
}
|
|
|
|
|
|
- function jsonSuccess($data = [], $msg = "成功")
|
|
|
- {
|
|
|
- $response = array(
|
|
|
- 'code' => 0,
|
|
|
- 'msg' => $msg,
|
|
|
- 'data' => []
|
|
|
- );
|
|
|
- if ($data) {
|
|
|
- if (is_array($data)) {
|
|
|
- //带有分页格式转换
|
|
|
- if (isset($data['meta'])) {
|
|
|
- // 更改元数据格式,全部包含在data下
|
|
|
- $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;
|
|
|
+ function jsonSuccess($data = [], $msg = "成功")
|
|
|
+{
|
|
|
+ $response = array(
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => $msg,
|
|
|
+ 'data' => []
|
|
|
+ );
|
|
|
+ if ($data) {
|
|
|
+ if (is_array($data)) {
|
|
|
+ //带有分页格式转换
|
|
|
+ if (isset($data['meta'])) {
|
|
|
+ // 更改元数据格式,全部包含在data下
|
|
|
+ $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;
|
|
|
}
|
|
|
+ return $response;
|
|
|
+}
|
|
|
+
|
|
|
+function jsonError($msg)
|
|
|
+{
|
|
|
+ $response = array(
|
|
|
+ 'code' => 1,
|
|
|
+ 'msg' => $msg,
|
|
|
+ '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 [];
|
|
|
+ }
|
|
|
+
|
|
|
+}
|