123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- 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;
- }
|