Пример #1
0
 public function testExport()
 {
     $Message1 = new Message('hello');
     $this->assertEquals(['charset=UTF-8', 'delay=0', 'dlr=0', 'hex=0', 'txt=hello'], $Message1->export());
     $Message2 = new Message('hi', true, 15000, Message::TYPE_BINARY);
     $this->assertEquals(['charset=UTF-8', 'delay=10080', 'dlr=1', 'hex=1', 'txt=hi'], $Message2->export());
     $Message3 = new Message('text');
     $Message3->addPhone(79031234567);
     $Message3->addPhone(79165557755);
     $this->assertEquals(['charset=UTF-8', 'delay=0', 'dlr=0', 'hex=0', 'txt=text', 'phone=79031234567', 'phone=79165557755'], $Message3->export());
     $Message4 = new Message('text');
     $Message4->addPhone(79031234567)->setCharset('UTF-16BE')->setPrefix('OPOP')->setTransactionId('s0meTr4n54CTi0N')->setUserDataHeader('AABB667788DD');
     $this->assertEquals(['charset=UTF-16BE', 'delay=0', 'dlr=0', 'hex=0', 'txt=text', 'phone=79031234567', 'p_transaction_id=s0meTr4n54CTi0N', 'pref=OPOP', 'udh=AABB667788DD'], $Message4->export());
 }
Пример #2
0
 public function testSignature()
 {
     $Class = new ReflectionClass(Client::class);
     $Method = $Class->getMethod('sign');
     $Method->setAccessible(true);
     $Client = new Client('FROM', 'login', '5eCrET');
     $Message1 = new Message('hello');
     $this->assertEquals('f4b447d259fb90514e16bebe2bf3dc7d', $Method->invoke($Client, $Message1));
     $Message2 = new Message('hello');
     $Message2->addPhone(79031234567);
     $this->assertEquals('b5c0d2b33bb1293006d803bd7c6461f1', $Method->invoke($Client, $Message2));
     $Message3 = new Message('hello');
     $Message3->addPhone(79031234567);
     $Message3->addPhone(79165557755);
     $this->assertEquals('ac989b951e5e42a3cd48b83ac40d822f', $Method->invoke($Client, $Message3));
 }
Пример #3
0
$phones = [];
$secret = '';
$text = '';
$user = '';
$Command = new CommandPosix();
$Command->appendHelpParameter('show help');
$Command->appendParameter(new Option('from', 'f', 'sender alpha-name', Option::TYPE_STRING, true), function ($name, $value) use(&$from) {
    $from = (string) $value;
});
$Command->appendParameter(new Option('phone', 'p', 'receiver phone or phones (comma-separated)', Option::TYPE_STRING, true), function ($name, $value) use(&$phones) {
    $phones = explode(',', $value);
});
$Command->appendParameter(new Option('secret', 's', 'secret key', Option::TYPE_STRING, true), function ($name, $value) use(&$secret) {
    $secret = (string) $value;
});
$Command->appendParameter(new Option('text', 't', 'message text', Option::TYPE_STRING, true), function ($name, $value) use(&$text) {
    $text = (string) $value;
});
$Command->appendParameter(new Option('user', 'u', 'sender login', Option::TYPE_STRING, true), function ($name, $value) use(&$user) {
    $user = (string) $value;
});
try {
    $Command->parse(true);
    $Message = new Message($text, true);
    $Message->setPhones($phones);
    $Client = new Client($from, $user, $secret);
    $Result = $Client->send($Message);
    printf("%s\n", (string) $Result);
} catch (RequiredOptionException $Ex) {
    $Command->displayHelp();
}
Пример #4
0
 /**
  * Sign message method
  * @param Message $Message message instance
  * @return string message signature
  */
 private function sign(Message $Message)
 {
     return md5($this->user . $this->from . implode($Message->getPhones()) . $Message->getText() . $this->secret);
 }