public static function GetAccessToken($corpid, $corpsecret)
 {
     $api = sprintf('%s/gettoken?corpid=%s&corpsecret=%s', WeiXin_Enteprise_Client::$baseURL, $corpid, $corpsecret);
     $tokenInfo = Util_HttpRequest::Get($api);
     if ($tokenInfo) {
         return json_decode($tokenInfo, true);
     }
     return array();
 }
Beispiel #2
0
 /**
  * 请求
  */
 public static function Request($url, $param, $method = 'GET')
 {
     $result = Util_HttpRequest::Request($url, $method, $param);
     $result = str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $result);
     $result = str_replace('<string xmlns="http://entinfo.cn/">', '', $result);
     $result = str_replace('</string>', '', $result);
     $result = trim($result);
     return $result;
 }
Beispiel #3
0
 public static function GetShorTen($url, $one = true, $source = '5786724301')
 {
     $uTpl = 'https://api.weibo.com/2/short_url/shorten.json?source=%s&url_long=%s';
     $link = sprintf($uTpl, $source, urlencode($url));
     $ret = Util_HttpRequest::Get($link);
     if ($ret) {
         $ret = json_decode($ret, true);
     }
     $urls = array_get($ret, 'urls');
     return $one ? Util_Array::GetFristItem($urls) : $urls;
 }
Beispiel #4
0
 public function request($param)
 {
     $param = $param ? $param : array();
     if ($this->useMultiSend) {
         $param['api_user'] = $this->multi_api_user;
     } else {
         $param['api_user'] = $this->api_user;
     }
     $param['api_key'] = $this->api_key;
     $result = Util_HttpRequest::Http(self::$url, 'POST', $param);
     if ($result) {
         $result = json_decode($result, true);
     }
     return $result;
 }
 public static function Http($url, $method, $postFields = null, $header = array())
 {
     self::$request_number++;
     $ci = curl_init();
     curl_setopt($ci, CURLOPT_CONNECTTIMEOUT_MS, self::$connecttimeout);
     // 链接超时
     curl_setopt($ci, CURLOPT_TIMEOUT_MS, self::$timeout);
     curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, FALSE);
     //cloopen 设置
     curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, self::$ssl_verifypeer);
     curl_setopt($ci, CURLOPT_HEADER, FALSE);
     curl_setopt($ci, CURLOPT_HTTPHEADER, $header);
     curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
     curl_setopt($ci, CURLOPT_URL, $url);
     switch ($method) {
         case 'POST':
             curl_setopt($ci, CURLOPT_POST, TRUE);
             if ($postFields) {
                 curl_setopt($ci, CURLOPT_POSTFIELDS, $postFields);
             }
             break;
         case 'DELETE':
             curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
             if ($postFields) {
                 $url = "{$url}?{$postFields}";
             }
             break;
     }
     $response = curl_exec($ci);
     if (self::$record) {
         self::$http_code[self::$request_number] = curl_getinfo($ci, CURLINFO_HTTP_CODE);
         self::$http_info[self::$request_number] = curl_getinfo($ci);
         self::$url[self::$request_number] = $url;
         self::$http_response[self::$request_number] = $response;
         self::$http_postdata[self::$request_number] = $postFields;
     }
     if (!$response) {
         self::$error = curl_error($ci);
     }
     curl_close($ci);
     return $response;
 }
Beispiel #6
0
 /**
  * 请求
  * @param string $action 请求方法
  * @param array $data 请求参数  
  * @param string $method GET?/POST
  * @param boolean $sub 是否使用子账号
  * @return mixed
  */
 public function request($action, $data = null, $method = "POST", $main = true, $format = 'json')
 {
     $url = $this->restUrl;
     $timeStr = date('YmdHis');
     $softVersion = $this->softVersion;
     if ($main) {
         //主账号
         $account = $this->mainAccount;
         $token = $this->mainToken;
         $accountType = "Accounts";
     } else {
         //
         $account = $this->subAccount;
         $token = $this->subToken;
         $accountType = "SubAccounts";
     }
     $sig = strtoupper(md5($account . $token . $timeStr));
     $url = "{$url}/{$softVersion}/{$accountType}/{$account}/{$action}?sig={$sig}";
     $authen = base64_encode("{$account}:{$timeStr}");
     if ($format == 'xml') {
         $header = array("Accept:application/xml", "Content-Type:application/xml;charset=utf-8", "Authorization:{$authen}");
     } else {
         //json
         $header = array("Accept:application/json", "Content-Type:application/json;charset=utf-8", "Authorization:{$authen}");
         if ($data) {
             $data = json_encode($data);
         }
     }
     $result = Util_HttpRequest::Http($url, $method, $data, $header);
     if ($result) {
         if ($format == 'xml') {
             $result = simplexml_load_string($result);
             $result = $result ? Util_Array::ObjectToArray($result) : $result;
         } else {
             $result = json_decode($result, true);
         }
     }
     return $result;
 }
Beispiel #7
0
 public static function Request($url, $param, $method = 'GET')
 {
     $result = Util_HttpRequest::Request($url, $method, $param);
     $result = simplexml_load_string($result);
     return $result;
 }
Beispiel #8
0
 /**
  * 获取验证信息
  * 
  * @param unknown $notifyID
  */
 public function getNotifyResponse($notifyID)
 {
     $url = $this->httpVerifyURL;
     $partner = trim($this->partner);
     $param = array('partner' => $partner, 'notify_id' => $notifyID);
     Util_HttpRequest::Request($url, 'get', $param);
 }
Beispiel #9
0
 private function getUrl()
 {
     $uri = Utility::getRequestURI();
     $uriInfo = parse_url($uri);
     parse_str($uriInfo['query'], $queryInfo);
     unset($queryInfo['page_no']);
     $url = $uriInfo['path'] . '?' . Util_HttpRequest::BuildHttpQuery($queryInfo);
     return $url;
 }
 public function http($url, $method, $params = array(), $header = array())
 {
     $url = $this->base_url . $url;
     $j = Util_HttpRequest::Http($url, $method, $params, $header);
     return $this->render($j);
 }