12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 流年 <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- // 应用公共文件
- function curl(string $url, $data, $type = 'form') {
- switch ($type) {
- case 'json':
- $data = json_encode($data);
- $header = ['Content-Type: application/json', 'Content-Length:' . strlen($data)];
- break;
- case 'form':
- $data = http_build_query($data);
- $header = ['Content-Type: application/x-www-form-urlencoded'];
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_POSTFIELDS , $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
|