コード例 #1
0
 protected function doSendRequest(ApeRequest $request)
 {
     $data = $request->getUrlString();
     try {
         $res = @file_get_contents($this->getUrl() . $data);
     } catch (Exception $e) {
         throw new ApeException('Could not create Response: ' . $e->getMessage());
     }
     return $res;
 }
コード例 #2
0
 protected function doSendRequest(ApeRequest $request)
 {
     if (!$this->ch) {
         $this->ch = curl_init();
         // error_log("new curl");
     }
     $ch = $this->ch;
     //$rawData = $request->getRawData();
     //if (empty($rawData))
     $rawData = $request->getJsonString();
     if ($ch) {
         $headers = array();
         $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
         $header[] = "Accept-Language: en-us,en;q=0.5";
         $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $rawData);
         curl_setopt($ch, CURLOPT_URL, $this->getUrl());
         // set url to post to
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 1);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_ENCODING, "");
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
         curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
         curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 1);
         if (isset($this->proxy)) {
             curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
         }
         $data = curl_exec($ch);
         $results = false;
         if (!curl_errno($ch)) {
             $results = $data;
         } else {
             error_log(print_r(curl_error($ch), 1));
             throw new ApeException('CURL ERROR ' . print_r(curl_error($ch), 1));
         }
         //curl_close($ch);
         return $results;
     } else {
         throw new ApeException('CURL error: Could not init CURL! ');
     }
 }
コード例 #3
0
ファイル: STB.inc.php プロジェクト: KevinStoneCode/twmap
function notify_web($channel, $rawmsg, $debug = 0)
{
    $connection = new ApeCurlConnection(APE_HOST, 80);
    $client = new ApeClient($connection);
    $request = new ApeRequest("xxx", array("abc"));
    list($email, $msg_prefix) = explode(":", $channel);
    foreach ($rawmsg as $msg) {
        // 加上 prefix
        $msg = $msg_prefix . ":" . $msg;
        $data = array(array('cmd' => 'CONNECT', "chl" => 1, "params" => array("name" => substr(md5(time()), 0, 8))), array('cmd' => 'JOIN', "chl" => 2, "params" => array("channels" => md5($email))));
        //      $start_time = time();
        $request->setRawData(json_encode($data));
        $response = $client->sendRequest($request);
        if (empty($response)) {
            MyErrorLog("notify_agent", "connect fail");
            return false;
        }
        // MyErrorLog("notify_agent response", $response);
        if ($response->isSuccess() == 1) {
            $result = json_decode($response->getRawresult(), true);
            $pubid = $result[2]['data']['pipe']['pubid'];
            $sessid = $result[0]['data']['sessid'];
            $users = count($result[2]['data']['users']);
            if ($debug) {
                MyErrorLog("notify_agent", array("users=>{$users}", $request, $response));
            }
            $data = array(array('cmd' => 'SEND', 'chl' => 3, "params" => array("msg" => str_replace("'", "\\u0027", $msg), "pipe" => $pubid), "sessid" => $sessid), array('cmd' => 'LEFT', "chl" => 4, "params" => array("channel" => md5($email))));
            $request->setRawData(json_encode($data));
            $response = $client->sendRequest($request);
            if ($debug) {
                MyErrorLog("notify_agent", array($request, $response, strlen($msg)));
            }
        } else {
            $fail++;
        }
    }
    return true;
}