예제 #1
0
 public function testSimpleXMLElements()
 {
     $xml = new SimpleXMLExtended('<?xml version="1.0" encoding="utf-8" ?><empty></empty>');
     $this->assertXmlStringEqualsXmlString('<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<empty></empty>', $xml->saveXML());
     $cdata = $xml->addChild('cdata');
     $cdata->addCData('some ··· cdata string & <s>sdsd</s>');
     $this->assertXmlStringEqualsXmlString('<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<empty><cdata><![CDATA[some ··· cdata string & <s>sdsd</s>]]></cdata></empty>', $xml->saveXML());
 }
예제 #2
0
 /**
  * {@inheritDoc}
  *
  * @see UnwireProvider::sendOne()
  */
 public function send($dry_run = false)
 {
     switch (count($this->messages)) {
         case 0:
             throw new RuntimeException("No messages to send.");
         case 1:
             return $this->sendOne($dry_run);
     }
     $xml = new SimpleXMLExtended('<?xml version="1.0" encoding="utf-8" ?><messages></messages>');
     $xml->addAttribute('xmlns', 'http://www.unwire.com/UM/core/v1.3');
     $xml->addAttribute('xsi:schemaLocation', 'http://www.unwire.com/UM/core/v1.3 https://gw.unwire.com/service/xmlinterface/core-1.3.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
     $xml->addAttribute('count', count($this->messages));
     $xml->addAttribute('service', 'mt');
     $xml->addAttribute('sessionid', session_id() ?: time());
     $default = $xml->addChild('defaultvalues');
     $default->addAttribute('type', 'text');
     // set default values
     foreach ($this->getDefaultValues() as $key => $value) {
         if ($key == 'content') {
             $content = $default->addChild($key);
             $content->addChild('text', $value);
         } else {
             if ($key == 'price') {
                 $price = $default->addChild('price', $value['amount']);
                 $price->addAttribute('currency', $value['currency']);
                 if (!is_null($value['vat'])) {
                     $price->addAttribute('vat', $value['vat']);
                 }
             } else {
                 if ($value) {
                     $default->addChild($key, $value);
                 }
             }
         }
     }
     $i = 1;
     // add messages
     foreach ($this->messages as $message) {
         $msg = $xml->addChild('sms');
         $msg->addAttribute('id', $i);
         $msg->addAttribute('type', 'text');
         $msg->addChild('msisdn', $message->to);
         if (empty($this->defaults['content'])) {
             $content = $msg->addChild('content');
             $content->addChild('text', $message->message);
         }
         if (empty($this->defaults['operator']) && isset($message->options['smsc'])) {
             $msg->addChild('operator', $message->options['smsc']);
         }
         if (isset($message->options['shortcode'])) {
             $msg->addChild('mediacode', $message->options['shortcode']);
         } else {
             if (empty($this->defaults['shortcode'])) {
                 $msg->addChild('shortcode', $this->config['appnr']);
             }
         }
         if (isset($message->options['mediacode'])) {
             $msg->addChild('mediacode', $message->options['mediacode']);
         } else {
             if (empty($this->defaults['mediacode'])) {
                 $msg->addChild('mediacode', $this->config['mediacode']);
             }
         }
         if (isset($message->options['price'])) {
             preg_match('/([0-9.]+)([A-Z]{3})/', $message->options['price'], $matches);
             $price = $msg->addChild('price', $matches[1]);
             $price->addAttribute('currency', $matches[2]);
             if (!is_null($this->defaults['price']['vat'])) {
                 $price->addAttribute('vat', $this->defaults['price']['vat']);
             }
         }
         $i++;
     }
     $endpoint = str_replace('://', '://' . $this->config['user'] . ':' . $this->config['password'] . '@', self::BATCH_ENDPOINT);
     $adapter = $this->getAdapter();
     $adapter->setEndpoint($endpoint);
     $adapter->setBody($xml->asXML());
     if ($dry_run) {
         $response = $adapter->dryRun();
     } else {
         $response = $adapter->post();
     }
     // empty query
     $this->messages = array();
     return $response;
 }
예제 #3
0
 /**
  * {@inheritDoc}
  */
 public function send($dry_run = false)
 {
     switch (count($this->messages)) {
         case 0:
             throw new \RuntimeException("No messages to send.");
         case 1:
             return $this->sendOne($dry_run);
     }
     // create xml document
     $xml = new SimpleXMLExtended('<?xml version="1.0" encoding="utf-8" ?><push></push>');
     $xml->addChild('user', $this->config['user']);
     $xml->addChild('password', $this->config['password']);
     $xml->addChild('serviceid', $this->config['serviceid']);
     $ts = date('d-m-Y H:i:00');
     // attach messages
     foreach ($this->messages as $message) {
         $batch = $xml->addChild('smsbatch');
         $batch->addChild('sendtime', $ts);
         if ($message->options['from']) {
             $batch->addChild('sender', $message->options['from']);
         } else {
             $batch->addChild('sender', $this->config['from']);
         }
         $batch->addChild('price', $this->config['price']);
         $cdata = $batch->addChild('message');
         $cdata->addCData($message->message);
         $recipient = $batch->addChild('recipients');
         $recipient->addChild('msisdn', $message->to);
     }
     $adapter = $this->getAdapter();
     $adapter->setEndpoint(self::BATCH_ENDPOINT);
     $adapter->setBody($xml->asXML());
     if ($dry_run) {
         return $adapter->dryRun();
     } else {
         $response = $adapter->post();
     }
     /**
      * inmobile returns 2 kinds of response
      *
      * 1: integer 2 to -18 error results
      * 2: xml containing the result of your success request
      *
      * we have asked inmobile to change this in new versions to always send back xml
      */
     if (strlen($response->getBody()) <= 3) {
         $xml = new SimpleXMLExtended('<?xml version="1.0" encoding="utf-8" ?><response></response>');
         $error = $xml->addChild('error');
         $error->addChild('code', $response->getBody());
         $error->addChild('message', $this->error_codes[$response->getBody()]);
         $response = new Response($response->getHeaders(), $xml->asXML(), $response->getRequest());
     }
     return $response;
 }