private function uploadMedia($path, $type)
 {
     //build Mac
     $timeStamp = time();
     $lstParams = array($this->pageId, $timeStamp, $this->secretKey);
     $mac = ZaloSdkHelper::buildMacForAuthentication($lstParams);
     $request = RequestFactory::getInstance()->create('POST', CommonInfo::$DOMAIN . CommonInfo::$SER_UPLOAD)->setClient(new Client())->addPostFiles(array(CommonInfo::$URL_UPLOAD => $path))->addPostFields(array(CommonInfo::$URL_ACT => $type, CommonInfo::$URL_PAGEID => $this->pageId, CommonInfo::$URL_TIMESTAMP => $timeStamp, CommonInfo::$URL_MAC => $mac));
     $response = $request->send()->json();
     $error = $response["error"];
     if ($error < 0) {
         $zaloSdkExcep = new ZaloSdkException();
         $zaloSdkExcep->setZaloSdkExceptionErrorCode($error);
         if (!empty($response["message"])) {
             $zaloSdkExcep->setZaloSdkExceptionMessage($response["message"]);
         }
         throw $zaloSdkExcep;
     } else {
         if (!empty($response["result"])) {
             return $response["result"];
         } else {
             $zaloSdkExcep = new ZaloSdkException();
             $zaloSdkExcep->setZaloSdkExceptionErrorCode(-1);
             throw zaloSdkExcep;
         }
     }
 }
Exemplo n.º 2
0
 private static function check($requirements, $error)
 {
     $message = $error == null || strlen(trim($error)) <= 0 ? ValidateFunc::$DEFAULT_MESSAGE : $error;
     if (!$requirements) {
         $zaloSdkExcep = new ZaloSdkException();
         $zaloSdkExcep->setZaloSdkExceptionMessage($error);
         $zaloSdkExcep->setZaloSdkExceptionErrorCode(-200);
         throw $zaloSdkExcep;
     }
 }
Exemplo n.º 3
0
 public static function sendQueryFeed($client)
 {
     $request = $client->get();
     $response = $request->send()->json();
     $zaloFeed = new ZaloFeed();
     $error = $response["error"];
     if ($error == -1) {
         $notExist = new MESSAGESTATUS(MESSAGESTATUS::NOT_EXIST);
         $zaloMsgSttResult->setError($notExist->getValue());
         $zaloMsgSttResult->setStatus("NOT_EXIST");
     } else {
         if ($error < 0) {
             $zaloSdkExcep = new ZaloSdkException();
             $zaloSdkExcep->setZaloSdkExceptionErrorCode($error);
             if (!empty($response["message"])) {
                 $zaloSdkExcep->setZaloSdkExceptionMessage($response["message"]);
             }
             throw $zaloSdkExcep;
         } else {
             if (!empty($response["result"])) {
                 $type = $response["result"]["type"];
                 $zaloFeed->setCreateTime($response["result"]["time"]);
                 $zaloFeed->setMessage($response["result"]["message"]);
                 if ($type == 1) {
                     $zaloFeed->setType(ZPTypeFeed::ZTF_Text);
                 } else {
                     if ($type == 2) {
                         $zaloFeed->setType(ZPTypeFeed::ZTF_Voice);
                         $zaloFeed->setVoiceURL($response["result"]["urlVoice"]);
                     } else {
                         if ($type == 3) {
                             $zaloFeed->setType(ZPTypeFeed::ZTF_Link);
                             $linkInfo = array("link" => $response["result"]["href"], "linkdes" => $response["result"]["description"], "linktitle" => $response["result"]["title"], "linkthumb" => $response["result"]["thumb"]);
                             $zaloFeed->setLinkInfo($linkInfo);
                         } else {
                             if ($type == 4) {
                                 $zaloFeed->setType(ZPTypeFeed::ZTF_Photo);
                                 $arr = $response["result"]["thumb"];
                                 if ($arr != null) {
                                     $lstImage = array();
                                     for ($i = 0; $i < count($arr); $i++) {
                                         array_push($lstImage, $arr[$i]);
                                     }
                                     $zaloFeed->setImageURL($lstImage);
                                 }
                             } else {
                                 if ($type == 5) {
                                     $zaloFeed->setType(ZPTypeFeed::ZTF_Sticker);
                                     $arr = $response["result"]["thumb"];
                                     if ($arr != null) {
                                         $lstSticker = array();
                                         for ($i = 0; $i < count($arr); $i++) {
                                             array_push($lstSticker, $arr[$i]);
                                         }
                                         $zaloFeed->setStickerURL($lstSticker);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 return $zaloFeed;
             } else {
                 $zaloSdkExcep = new ZaloSdkException();
                 $zaloSdkExcep->setZaloSdkExceptionErrorCode(-1);
                 throw zaloSdkExcep;
             }
         }
     }
     return $zaloFeed;
 }