Exemplo n.º 1
0
 public function sendMMS($senderAddress, $addressList, $message, $attachments, $senderName, $clientCorrelator, $notifyURL, $callbackData)
 {
     $sendMMSResponse = null;
     if ($senderAddress && $addressList && ($message || $attachments)) {
         if (!is_null($this->endpoint) && property_exists($this->endpoint, 'SendSMS')) {
             $url = $this->endpoint->getSendMMSEndpoint();
         } else {
             $url = 'http://localhost:8080/oneapiserver/SendMMSService/1/messaging/outbound/{senderAddress}/requests';
         }
         $url = str_replace('{senderAddress}', urlencode($senderAddress), $url);
         $formParameters = new FormParameters();
         $formParameters->put("senderAddress", $senderAddress);
         for ($i = 0; $i < count($addressList); $i++) {
             $formParameters->put("address", $addressList[$i]);
         }
         $formParameters->put("message", $message);
         $formParameters->put("clientCorrelator", $clientCorrelator);
         $formParameters->put("notifyURL", $notifyURL);
         $formParameters->put("senderName", $senderName);
         $formParameters->put("callbackData", $callbackData);
         $params = array();
         $params['content_type'] = 'multipart/mixed';
         $requestBody = new Mail_mimePart('', $params);
         $params['content_type'] = 'application/x-www-form-urlencoded';
         //$params['encoding']     = '8bit';
         $params['disposition'] = 'form-data; name="root-fields"';
         $text = $requestBody->addSubPart($formParameters->encodeParameters(), $params);
         error_log('Processing attachments');
         if ($attachments && is_array($attachments) && count($attachments) > 0) {
             for ($i = 0; $i < count($attachments); $i++) {
                 error_log('Processing file ' . $i);
                 $file = $attachments[$i];
                 if ($file && is_array($file) && isset($file['error']) && $file['error'] == UPLOAD_ERR_OK) {
                     error_log('Have attachment name=' . $file['name'] . ' type=' . $file['type'] . ' size=' . $file['size']);
                     $params['content_type'] = $file['type'];
                     $params['encoding'] = 'base64';
                     $params['disposition'] = 'form-data; name="' . $file['name'] . '"';
                     $contents = file_get_contents($file['tmp_name']);
                     $attach =& $requestBody->addSubPart($contents, $params);
                 }
             }
         }
         $content = $requestBody->encode();
         $contentType = $content['headers']['Content-Type'];
         $data = $content['body'];
         error_log('Generated...\\n' . print_r($content, true));
         $request = new JSONRequest($url, $this->username, $this->password, 'POST', null, $contentType, $data);
         $response = $request->execute();
         if ($response->getResponseBody()) {
             $jsondata = json_decode($response->getResponseBody());
         }
         error_log("MMSSend::sendMMS response=" . print_r($response, true));
         error_log("MMSSend::sendMMS jsondata=" . print_r($jsondata, true));
         $responseInfo = $response->getResponseInfo();
         $location = $response->getLocation();
         $sendMMSResponse = new MMSSendResponse($responseInfo["http_code"], $responseInfo["content_type"], $location, $jsondata);
         error_log("MMSSend::sendMMS sendMMSResponse=" . print_r($sendMMSResponse, true));
     }
     return $sendMMSResponse;
 }