123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- declare (strict_types=1);
- namespace library\lib;
- // +----------------------------------------------------------------------
- // | [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2018-2020 rights reserved.
- // +----------------------------------------------------------------------
- // | Author: TABLE ME
- // +----------------------------------------------------------------------
- // | Date: 2020-12-15 16:46
- // +----------------------------------------------------------------------
- class expInfo {
- //host
- private $host = "http://ali-deliver.showapi.com/";
- private $appcode = 'd86b3854113a4da38346d078fafc4a9d';
- /**
- * @param $code
- */
- public function showapiExpInfo($code,$com = 'auto'){
- $querys = "com=" . $com . "&nu=".$code;
- $data = $this->httpGet('showapi_expInfo',$querys);
- return json_decode($data,true);
- }
- /**
- * @param $url
- * @param $query
- * @return bool|string
- */
- private function httpGet($url,$query) {
- $headers = array();
- array_push($headers, "Authorization:APPCODE " . $this->appcode);
- $url = $this->host . $url . '?' . $query;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_FAILONERROR, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, false);
- if (1 == strpos("$".$this->host, "https://"))
- {
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- }
- $res = curl_exec($curl);
- curl_close($curl);
- return $res;
- }
- function curlPost($url, $post_data = array(), $timeout = 5, $data_type = "") {
- //支持json数据数据提交
- if($data_type == 'json'){
- $post_string = json_encode($post_data);
- }elseif($data_type == 'array') {
- $post_string = $post_data;
- }elseif(is_array($post_data)){
- $post_string = http_build_query($post_data, '', '&');
- $post_string = urldecode($post_string);
- }
- $ch = curl_init(); // 启动一个CURL会话
- curl_setopt($ch, CURLOPT_URL, $url); // 要访问的地址
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 // https请求 不验证证书和hosts
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
- curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的Post请求
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); // Post提交的数据包
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // 设置超时限制防止死循环
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
- }
|