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;
         }
     }
 }
 public function getMessageStatus($msgId)
 {
     $timeStamp = time();
     $client = ZaloSdkHelper::buildRequestD($this->pageId, CommonInfo::$ACT_STT, CommonInfo::$SER_QUERY, $timeStamp);
     //plus param
     ValidateFunc::checkEmptyString($msgId, "Message can't be empty");
     ZaloSdkHelper::addParamsHttpGet($client, CommonInfo::$URL_MSGID, $msgId);
     //build Mac
     $lstParams = array($this->pageId, $msgId, $timeStamp, $this->secretKey);
     $mac = ZaloSdkHelper::buildMacForAuthentication($lstParams);
     ZaloSdkHelper::addParamsHttpGet($client, CommonInfo::$URL_MAC, $mac);
     return ZaloSdkHelper::sendQueryStatusMsgPage($client);
 }
 public function removeFanPageByPhoneNum($phoneNum)
 {
     $timeStamp = time();
     $client = ZaloSdkHelper::buildRequestD($this->pageId, CommonInfo::$ACT_REMOVE_PHONE, CommonInfo::$SER_FAN, $timeStamp);
     //plus param
     ValidateFunc::checkNotNull($phoneNum, "List phone numbers can't be null");
     ValidateFunc::checkListNotEmpty($phoneNum, "List phone numbers can't be empty");
     $strPhoneNums = $this->convertListToArray($phoneNum);
     ZaloSdkHelper::addParamsHttpGet($client, CommonInfo::$URL_UIDS, $strPhoneNums);
     //build Mac
     $lstParams = array($this->pageId, $strPhoneNums, $timeStamp, $this->secretKey);
     $mac = ZaloSdkHelper::buildMacForAuthentication($lstParams);
     ZaloSdkHelper::addParamsHttpGet($client, CommonInfo::$URL_MAC, $mac);
     return ZaloSdkHelper::sendRemoveFan($client);
 }
 public function pushLinkFeed($message, $link, $linkTitle, $linkDesc, $linkThumb)
 {
     $timeStamp = time();
     $client = ZaloSdkHelper::buildRequestC($this->pageId, $message, CommonInfo::$ACT_LINK, CommonInfo::$SER_SOCIAL, $timeStamp);
     //plus param
     ValidateFunc::checkEmptyString($link, "Link can't be empty");
     ValidateFunc::checkEmptyString($linkDesc, "Link description can't be empty");
     ValidateFunc::checkEmptyString($linkThumb, "Link thumbnail can't be empty");
     ValidateFunc::checkEmptyString($linkTitle, "Link title can't be empty");
     ZaloSdkHelper::addParamsHttpGet($client, CommonInfo::$URL_LINK, $link);
     ZaloSdkHelper::addParamsHttpGet($client, CommonInfo::$URL_LINKTITLE, $linkTitle);
     ZaloSdkHelper::addParamsHttpGet($client, CommonInfo::$URL_LINKDES, $linkDesc);
     ZaloSdkHelper::addParamsHttpGet($client, CommonInfo::$URL_LINKTHUMB, $linkThumb);
     //build Mac
     $lstParams = array($this->pageId, $message, $link, $linkTitle, $linkDesc, $linkThumb, $timeStamp, $this->secretKey);
     $mac = ZaloSdkHelper::buildMacForAuthentication($lstParams);
     ZaloSdkHelper::addParamsHttpGet($client, CommonInfo::$URL_MAC, $mac);
     return ZaloSdkHelper::sendMessage($client);
 }
Example #5
0
 public static function sendQueryStatusMsgPage($client)
 {
     $request = $client->get();
     $response = $request->send()->json();
     $zaloMsgSttResult = new ZaloMsgSttResult();
     $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 {
             $zaloMsgSttResult->setError(ZaloSdkHelper::getMsgStatusFrResponse($error));
             $zaloMsgSttResult->setStatus(ZaloSdkHelper::getStringStatusFrResponse($error));
         }
     }
     return $zaloMsgSttResult;
 }
 public function getPageInfoOnbehaft()
 {
     $timeStamp = time();
     ValidateFunc::checkNotNull($this->pageId, "Page id can't be null");
     ValidateFunc::checkNotNull($this->appId, "App id can't be null");
     ValidateFunc::checkEmptyString($this->accessToken, "Access token can't be empty");
     if ($smsMsg == null) {
         $smsMsg = "";
     }
     $client = new Client(CommonInfo::$DOMAIN . CommonInfo::$SER_ONBEHALF);
     $params = array(CommonInfo::$URL_ACT => CommonInfo::$ACT_PROFILE, CommonInfo::$URL_PAGEID => $this->pageId, CommonInfo::$URL_APPID => $this->appId, CommonInfo::$URL_ACCESSTOK => $this->accessToken, CommonInfo::$URL_TIMESTAMP => $timeStamp);
     $client->setDefaultOption('query', $params);
     $profileResult = new ZaloProfileResult();
     $profileResult->setErr(-1);
     $profile = ZaloSdkHelper::sendQueryProfile($client);
     if ($profile != null) {
         $profileResult->setProfile($profile);
         $profileResult->setErr(0);
     }
     return $profileResult;
 }