75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\api\controller;
|
||
|
|
|
||
|
|
use think\Controller;
|
||
|
|
use think\Request;
|
||
|
|
use OSS\OssClient;
|
||
|
|
use think\Config;
|
||
|
|
use OSS\Core\OssException;
|
||
|
|
|
||
|
|
class Common extends Controller
|
||
|
|
{
|
||
|
|
public function message($code, $msg = '', $data = [])
|
||
|
|
{
|
||
|
|
$msg = [
|
||
|
|
'code' => $code,
|
||
|
|
'msg' => $msg,
|
||
|
|
'data' => $data
|
||
|
|
];
|
||
|
|
echo json_encode($msg);
|
||
|
|
die;
|
||
|
|
}
|
||
|
|
public function sendSuccess($data=''){
|
||
|
|
$data_ret = [
|
||
|
|
"success"=> true,
|
||
|
|
"code"=> 20000,
|
||
|
|
"message"=> "成功",
|
||
|
|
"data"=> $data
|
||
|
|
];
|
||
|
|
echo json_encode($data_ret);
|
||
|
|
die;
|
||
|
|
}
|
||
|
|
public function sendError($errorCode,$msg='',$data=null){
|
||
|
|
$data_ret = [
|
||
|
|
"success"=> false,
|
||
|
|
"code"=> $errorCode,
|
||
|
|
"message"=> $msg,
|
||
|
|
"data"=> $data
|
||
|
|
];
|
||
|
|
echo json_encode($data_ret);
|
||
|
|
die;
|
||
|
|
}
|
||
|
|
public function sendHikSuccess($data=''){
|
||
|
|
$data_ret = [
|
||
|
|
"success"=> true,
|
||
|
|
"code"=> 0,
|
||
|
|
"message"=> "成功",
|
||
|
|
"data"=> $data
|
||
|
|
];
|
||
|
|
echo json_encode($data_ret);
|
||
|
|
//die;
|
||
|
|
}
|
||
|
|
|
||
|
|
//封装一个https_request方法方便调用
|
||
|
|
public function https_request($url,$data=null,$post)
|
||
|
|
{
|
||
|
|
$curl = curl_init();
|
||
|
|
curl_setopt($curl,CURLOPT_URL,$url);
|
||
|
|
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);
|
||
|
|
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,FALSE);
|
||
|
|
if(!empty($data)){
|
||
|
|
curl_setopt($curl,CURLOPT_POST,$post);
|
||
|
|
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
|
||
|
|
}
|
||
|
|
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
|
||
|
|
//Content-Type: application/json 修改 zsh
|
||
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||
|
|
'Content-Type: application/json; charset=utf-8',
|
||
|
|
'Content-Length: ' . strlen($data)
|
||
|
|
));
|
||
|
|
$output = curl_exec($curl);
|
||
|
|
curl_close($curl);
|
||
|
|
return $output;
|
||
|
|
}
|
||
|
|
}
|