Пример #1
0
 public function handleRquest()
 {
     if (!$this->checkSignature()) {
         return false;
     }
     /////////验证  开通开发者请求
     if ($_GET['echostr']) {
         return $_GET['echostr'];
     }
     //////
     $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
     //获取raw post数据
     if (!$postStr) {
         $result = ' ';
     } else {
         $this->postData = $postStr;
         $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
         $postArray = Util_Array::ObjectToArray($postObj);
         $this->postArray = $postArray;
         $msgType = $postArray['MsgType'];
         $result = $this->handler->handleRquest($msgType, $postArray);
     }
     Log::Set($result);
     if (!$result) {
         return self::DEFAULT_OUTPUT;
     }
     $result = self::formatResult($result);
     return $result;
 }
Пример #2
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;
 }
Пример #3
0
 public static function XMLToArray($xml)
 {
     $o = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
     return Util_Array::ObjectToArray($o);
 }