/** * Sends a request to the API for sending MMS to the specified address. * * @param string $addr address to which MMS will be * sent. * @param string|null $subject subject of MMS. * @param string|null $priority priority of MMS * @param boolean $notifyDeliveryStatus whether the API should send a * notification after MMS has been * sent. * * @return SendMMSResponse API response. * @throws ServiceException if API request was not successful. */ public function sendMMS($addr, $fnames, $subject = null, $priority = null, $notifyDeliveryStatus = false) { $endpoint = $this->getFqdn() . '/mms/v3/messaging/outbox'; $req = new RESTFULRequest($endpoint); $req->setHeader('Content-Type', 'application/json')->setHeader('Accept', 'application/json')->setAuthorizationHeader($this->getToken()); $outboundRequest = array('address' => $addr, 'notifyDeliveryStatus' => $notifyDeliveryStatus); if ($subject != null) { $outboundRequest['subject'] = $subject; } if ($priority != null) { $outboundRequest['priority'] = $priority; } $vals = array('outboundMessageRequest' => $outboundRequest); $jvals = json_encode($vals); $mpart = new HttpMultipart(); $mpart->addJSONPart($jvals); foreach ($fnames as $fname) { $mpart->addFilePart($fname); } $result = $req->sendHttpMultipart($mpart); $arr = Service::parseJson($result); return SendMMSResponse::fromArray($arr); }
/** * Sends a message to the specified addresses. * * @param array $addresses strings that holds the addresses to which * the specified messages will be sent. * @param string|null $text text body of message or null if none * @param string|null $subject subject of message or null if none * @param array|null $fnames file names of attachments or null if none * @param bool|null $isGroup whether to send as broadcast or null to * use default * * @return string message id * @throws ServiceException if API request was not successful */ public function sendMessage($addresses, $text, $subject, $fnames = null, $isGroup = null) { $endpoint = $this->getFqdn() . '/myMessages/v2/messages'; $req = new RESTFulRequest($endpoint); $req->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/json')->setAuthorizationHeader($this->getToken()); $vals = array('addresses' => $addresses); $vals['isGroup'] = $isGroup ? 'true' : 'false'; if ($text !== null) { $vals['text'] = $text; } if ($subject !== null) { $vals['subject'] = $subject; } $messageRequest = array('messageRequest' => $vals); $jvals = json_encode($messageRequest); $result = null; if ($fnames == null) { // no attachments; send basic POST $req->setHeader('Content-Type', 'application/json'); $httpPost = new HttpPost(); $httpPost->setBody($jvals); $result = $req->sendHttpPost($httpPost); } else { // attachments; send as multipart $mpart = new HttpMultipart(); $mpart->addJSONPart($jvals); foreach ($fnames as $fname) { $mpart->addFilePart($fname); } $result = $req->sendHttpMultipart($mpart); } $responseArr = Service::parseJson($result); return $responseArr['id']; }