| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace Modules\OpcData\Http\Controllers\Api;
- use App\Http\Controllers\Api\BaseController;
- use Illuminate\Contracts\Support\Renderable;
- use Illuminate\Http\Request;
- use Illuminate\Routing\Controller;
- class OPCDataTurboController extends BaseController
- {
- public function getData(Request $request) {
- $sys_key = $request->sys_key;
- $sys_name = $request->sys_name;
- if (!isset($sys_key) || !isset($sys_name)) {
- return $this->error(-1, '参数错误');
- }
- $db_conf = config('database');
- $api_url = 'http://'.$db_conf['python_api'][$sys_key]['url'].'/get/?sys_key='.$sys_key.'&sys_name='.$sys_name;
- $response = $this->request_post($api_url);
- if (gettype($response) == 'integer') {
- switch ($response) {
- case 3:
- $error_info = 'CURLE_URL_MALFORMAT';
- break;
- case 7:
- $error_info = 'CURLE_COULDNT_CONNECT';
- break;
- default:
- $error_info = '未知错误:'.$response;
- }
- return $this->error($response, $error_info);
- } else {
- $data = json_decode($response);
- if ($data == null) {
- return $this->error(500, preg_replace('/<[^>]*>/','',$response));
- } else {
- return $this->success($data);
- }
- }
- }
- private function request_post($url = '', $param = '') {
- if (empty($url)) {
- return false;
- }
- $postUrl = $url;
- $curlPost = $param;
- $curl = curl_init();//初始化curl
- curl_setopt($curl, CURLOPT_URL,$postUrl);//抓取指定网页
- curl_setopt($curl, CURLOPT_HEADER, 0);//设置header
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
- curl_setopt($curl, CURLOPT_POST, 1);//post提交方式
- curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);//提交的参数
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- // curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- $data = curl_exec($curl);//运行curl
- $errno = curl_errno($curl);
- curl_close($curl);
- if ($errno > 0) return $errno;
- return $data;
- }
- /**
- * Display a listing of the resource.
- * @return Renderable
- */
- public function index()
- {
- return view('opcdata::index');
- }
- /**
- * Show the form for creating a new resource.
- * @return Renderable
- */
- public function create()
- {
- return view('opcdata::create');
- }
- /**
- * Store a newly created resource in storage.
- * @param Request $request
- * @return Renderable
- */
- public function store(Request $request)
- {
- //
- }
- /**
- * Show the specified resource.
- * @param int $id
- * @return Renderable
- */
- public function show($id)
- {
- return view('opcdata::show');
- }
- /**
- * Show the form for editing the specified resource.
- * @param int $id
- * @return Renderable
- */
- public function edit($id)
- {
- return view('opcdata::edit');
- }
- /**
- * Update the specified resource in storage.
- * @param Request $request
- * @param int $id
- * @return Renderable
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * Remove the specified resource from storage.
- * @param int $id
- * @return Renderable
- */
- public function destroy($id)
- {
- //
- }
- }
|