// +---------------------------------------------------------------------- declare (strict_types=1); // 应用公共函数库文件 /** * 获取当前访问的渠道(微信小程序、H5、APP等) * @return string|null */ function getPlatform(): ?string { return 'H5'; static $value = null; // 从header中获取 channel empty($value) && $value = request()->header('platform'); // 调试模式下可通过param中获取 if (is_debug() && empty($value)) { $value = request()->param('platform'); } return $value; } /** * 使用curl函数库发送请求 */ function curl_request($url, $method = 'get', $headers = [], $params = [], $type = 'http') { /** * 初始化curl,返回资源 */ $curl = curl_init($url); /** * 默认是get请求,如果是post/put请求,设置请求方式和请求参数 */ if (strtoupper($method) == 'POST') { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $params); } if (strtoupper($method) == 'PUT') { curl_setopt($curl, CURLOPT_PUT, true); } if (!empty($headers)) { curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); } /** * 如果是HTTPS协议,禁止从服务器验证本地证书 */ if (strtoupper($type) == 'HTTPS') { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); } /** * 发送请求,返回结果 */ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); /** * 选择地址 * curl_setopt($curl,CURLOPT_URL,$url); */ $res = curl_exec($curl); /** * 关闭请求 */ curl_close($curl); return $res; }