Пример #1
0
 public function testResult()
 {
     $message = new StandardMessage('+8615212345678', 'MessageBody');
     $result = new StandardResult($message, new Response(200));
     $this->assertTrue(is_numeric($result->getSentTimestamp()));
     $this->assertJson($result->__toString());
     $this->assertJson($message->__toString());
 }
Пример #2
0
 /**
  * @param TemplateMessage $message
  * @return StandResult
  */
 public function sendTemplateMessage(TemplateMessage $message)
 {
     $number = $message->getRecipient();
     if (!$this->isNumberValid($number)) {
         throw new InvalidNumberException(sprintf('Mobile number %s not valid by provider %s', $number, 'submail'));
     }
     if (!$this->isCountrySupported($number)) {
         throw new UnsupportedException(sprintf('Mobile number %s not supported by provider %s', $number, 'submail'));
     }
     //Raw auth by appkey
     $params = array('appid' => $this->appid, 'to' => $number, 'project' => $message->getTemplateId(), 'vars' => json_encode($message->getVars()), 'signature' => $this->appkey);
     /*
     $params = array(
         'appid' => $this->appid,
         'to' => $number,
         'project' => $message->getTemplateId(),
         'vars' => json_encode($message->getVars()),
         'timestamp' => time(),
         'sige_type' => 'md5',
     )
     $signature = $this->getSignature($params);
     $params['signature'] = $signature;
     */
     $client = Sender::getHttpClient();
     $response = $client->post(self::API_URL, array('body' => $params));
     $responseArr = $response->json();
     $result = new StandardResult($message, $response);
     if (isset($responseArr['status'])) {
         if ($responseArr['status'] == 'success') {
             $result->setStatus(ResultInterface::STATUS_DELIVERED);
         } elseif ($responseArr['status'] == 'error') {
             $result->setStatus(ResultInterface::STATUS_FAILED);
         }
     }
     return $result;
 }