public function testMobileValidate() { $sender = new Sender(); $this->assertFalse($sender->isMobileNumberValid('abc')); $this->assertFalse($sender->isMobileNumberValid('+8612345678')); $this->assertFalse($sender->isMobileNumberValid('+abc')); $this->assertTrue($sender->isMobileNumberValid('+8618512345678')); }
public function setUp() { $this->mock = new Mock([new Response(200, ['Content-Type' => 'javascript'], Stream::factory('{"status":"success"}')), new Response(200, ['Content-Type' => 'javascript'], Stream::factory('{"status":"error"}'))]); $this->submail = new Submail('key', 'secret'); $client = Sender::getHttpClient(); $client->getEmitter()->attach($this->mock); }
/** * @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; }
public function diSmsSender() { $config = $this->getDI()->getConfig(); $adapterMapping = array('submail' => 'Eva\\EvaSms\\Providers\\Submail'); $adapterKey = $config->smsSender->provider; $adapterKey = false === strpos($adapterKey, '\\') ? strtolower($adapterKey) : $adapterKey; $adapterClass = empty($adapterMapping[$adapterKey]) ? $adapterKey : $adapterMapping[$adapterKey]; if (false === class_exists($adapterClass)) { throw new Exception\RuntimeException(sprintf('No sms provider found by %s', $adapterClass)); } $sender = new Sender(); $sender->setProvider(new $adapterClass($config->smsSender->appid, $config->smsSender->appkey)); if ($config->smsSender->timeout) { $sender::setDefaultTimeout($config->smsSender->timeout); } return $sender; }
protected function mock(Response $response) { $client = Sender::getHttpClient(); $client->getConfig('handler')->setHandler(new MockHandler([$response])); }