make compatible between different SMS types
Cette révision appartient à :
Parent
fae19607c2
révision
6854f12e13
@ -23,6 +23,8 @@ use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
||||
use D3\LinkmobilityClient\Response\ResponseInterface;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessageAbstract;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
|
||||
use D3\LinkmobilityClient\ValueObject\StringValueObject;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use InvalidArgumentException;
|
||||
@ -30,7 +32,7 @@ use InvalidArgumentException;
|
||||
abstract class Request implements RequestInterface
|
||||
{
|
||||
/**
|
||||
* @var StringValueObject
|
||||
* @var SmsMessageInterface
|
||||
*/
|
||||
private $message;
|
||||
|
||||
@ -105,9 +107,9 @@ abstract class Request implements RequestInterface
|
||||
private $maxSmsPerMessage = 0;
|
||||
|
||||
/**
|
||||
* @param StringValueObject $message
|
||||
* @param SmsMessageAbstract $message
|
||||
*/
|
||||
public function __construct(StringValueObject $message)
|
||||
public function __construct(SmsMessageInterface $message)
|
||||
{
|
||||
$this->recipientsList = new RecipientsList();
|
||||
$this->setMessage( $message );
|
||||
@ -148,9 +150,7 @@ abstract class Request implements RequestInterface
|
||||
return [
|
||||
'clientMessageId' => $this->getClientMessageId(),
|
||||
'contentCategory' => $this->getContentCategory(),
|
||||
'maxSmsPerMessage' => $this->getMaxSmsPerMessage(),
|
||||
'messageContent' => (string) $this->getMessage(),
|
||||
'messageType' => $this->getMessageType(),
|
||||
'messageContent' => $this->getMessage()->getMessageContent(),
|
||||
'notificationCallbackUrl' => $this->getNotificationCallbackUrl(),
|
||||
'priority' => $this->getPriority(),
|
||||
'recipientAddressList' => $this->getRecipientsList()->getRecipients(),
|
||||
@ -201,7 +201,7 @@ abstract class Request implements RequestInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMessage(): StringValueObject
|
||||
public function getMessage(): SmsMessageInterface
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
59
src/SMS/BinaryRequest.php
Fichier normal
59
src/SMS/BinaryRequest.php
Fichier normal
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\LinkmobilityClient\Request\Request;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessage;
|
||||
|
||||
class BinaryRequest extends Request implements SmsRequestInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUri(): string
|
||||
{
|
||||
return '/rest/smsmessaging/binary';
|
||||
}
|
||||
|
||||
public function getRawBody() : array
|
||||
{
|
||||
return array_merge(
|
||||
parent::getRawBody(),
|
||||
[
|
||||
'userDataHeaderPresent' => true
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function validate()
|
||||
{
|
||||
parent::validate();
|
||||
|
||||
Assert::thatNullOr( $this->getMessage() )->isInstanceOf(SmsBinaryMessage::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResponseClass(): string
|
||||
{
|
||||
return Response::class;
|
||||
}
|
||||
}
|
57
src/SMS/RequestFactory.php
Fichier normal
57
src/SMS/RequestFactory.php
Fichier normal
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
||||
use Phlib\SmsLength\SmsLength;
|
||||
|
||||
class RequestFactory
|
||||
{
|
||||
/**
|
||||
* @deprecated is SmsLength constant from version 2.1
|
||||
*/
|
||||
const GSM_7BIT = '7-bit';
|
||||
|
||||
/**
|
||||
* @deprecated is SmsLength constant from version 2.1
|
||||
*/
|
||||
const GSM_UCS2 = 'ucs-2';
|
||||
|
||||
private $message;
|
||||
|
||||
public function __construct($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SmsRequestInterface
|
||||
*/
|
||||
public function getRequest() : SmsRequestInterface
|
||||
{
|
||||
$smsLength = new SmsLength($this->message);
|
||||
if ($smsLength->getEncoding() === self::GSM_7BIT) {
|
||||
$message = new SmsTextMessage($this->message);
|
||||
return new TextRequest($message);
|
||||
}
|
||||
|
||||
$message = new SmsBinaryMessage($this->message);
|
||||
return new BinaryRequest($message);
|
||||
}
|
||||
}
|
@ -13,24 +13,15 @@
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessage;
|
||||
|
||||
class Request
|
||||
interface RequestFactoryInterface
|
||||
{
|
||||
public function __construct( Sender $sender, SmsMessage $message)
|
||||
{
|
||||
// use factory pattern
|
||||
public function __construct(SmsMessage $message);
|
||||
|
||||
//$this = new TextRequest($sender, $message);
|
||||
/*
|
||||
if ($message->isGsm7()) {
|
||||
return new TextRequest($sender, $message);
|
||||
}
|
||||
|
||||
return new TextRequest($sender, $message);
|
||||
*/
|
||||
}
|
||||
public function getRequest() : SmsRequestInterface;
|
||||
}
|
23
src/SMS/SmsRequestInterface.php
Fichier normal
23
src/SMS/SmsRequestInterface.php
Fichier normal
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
|
||||
|
||||
interface SmsRequestInterface
|
||||
{
|
||||
public function __construct(SmsMessageInterface $message);
|
||||
}
|
@ -18,9 +18,11 @@ declare( strict_types = 1 );
|
||||
namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessage;
|
||||
use D3\LinkmobilityClient\Request\Request;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
||||
|
||||
class TextRequest extends \D3\LinkmobilityClient\Request\Request
|
||||
class TextRequest extends Request implements SmsRequestInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
@ -34,7 +36,7 @@ class TextRequest extends \D3\LinkmobilityClient\Request\Request
|
||||
{
|
||||
parent::validate();
|
||||
|
||||
Assert::thatNullOr( $this->getMessage() )->isInstanceOf(SmsMessage::class);
|
||||
Assert::thatNullOr( $this->getMessage() )->isInstanceOf(SmsTextMessage::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,4 +46,15 @@ class TextRequest extends \D3\LinkmobilityClient\Request\Request
|
||||
{
|
||||
return Response::class;
|
||||
}
|
||||
|
||||
public function getRawBody() : array
|
||||
{
|
||||
return array_merge(
|
||||
parent::getRawBody(),
|
||||
[
|
||||
'maxSmsPerMessage' => $this->getMaxSmsPerMessage(),
|
||||
'messageType' => $this->getMessageType(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
29
src/ValueObject/SmsBinaryMessage.php
Fichier normal
29
src/ValueObject/SmsBinaryMessage.php
Fichier normal
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Phlib\SmsLength\SmsLength;
|
||||
|
||||
class SmsBinaryMessage extends SmsMessageAbstract
|
||||
{
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function __construct(string $message)
|
||||
{
|
||||
parent::__construct( $message);
|
||||
|
||||
$smsLength = new SmsLength($this->value);
|
||||
$smsLength->validate();
|
||||
}
|
||||
|
||||
public function getMessageContent()
|
||||
{
|
||||
return str_split(
|
||||
base64_encode($this->value),
|
||||
SmsLength::MAXIMUM_CHARACTERS_UCS2_SINGLE
|
||||
);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Phlib\SmsLength\SmsLength;
|
||||
|
||||
class SmsMessage extends StringValueObject
|
||||
{
|
||||
const GSM_7BIT = '7-bit';
|
||||
const GSM_UCS2 = 'ucs-2';
|
||||
|
||||
public function __construct(string $number)
|
||||
{
|
||||
parent::__construct( $number);
|
||||
|
||||
$smsLength = new SmsLength($this->value);
|
||||
$smsLength->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $gsm7;
|
||||
|
||||
public function chunkCount() : int
|
||||
{
|
||||
$smsLength = new SmsLength($this->value);
|
||||
return $smsLength->getMessageCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function length() : int
|
||||
{
|
||||
$smsLength = new SmsLength($this->value);
|
||||
return $smsLength->getSize();
|
||||
}
|
||||
|
||||
public function isGsm7() : bool
|
||||
{
|
||||
$smsLength = new SmsLength($this->value);
|
||||
if (is_null($this->gsm7)) {
|
||||
$this->gsm7 = $smsLength->getEncoding() === self::GSM_7BIT;
|
||||
}
|
||||
|
||||
return $this->gsm7;
|
||||
}
|
||||
|
||||
public function isUnicode() : bool
|
||||
{
|
||||
return !$this->isGsm7();
|
||||
}
|
||||
}
|
33
src/ValueObject/SmsMessageAbstract.php
Fichier normal
33
src/ValueObject/SmsMessageAbstract.php
Fichier normal
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Phlib\SmsLength\SmsLength;
|
||||
|
||||
abstract class SmsMessageAbstract extends StringValueObject implements SmsMessageInterface
|
||||
{
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function chunkCount() : int
|
||||
{
|
||||
$smsLength = new SmsLength($this->value);
|
||||
return $smsLength->getMessageCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function length() : int
|
||||
{
|
||||
$smsLength = new SmsLength($this->value);
|
||||
return $smsLength->getSize();
|
||||
}
|
||||
|
||||
public function getMessageContent()
|
||||
{
|
||||
return (string) $this->value;
|
||||
}
|
||||
}
|
25
src/ValueObject/SmsMessageInterface.php
Fichier normal
25
src/ValueObject/SmsMessageInterface.php
Fichier normal
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
interface SmsMessageInterface
|
||||
{
|
||||
public function chunkCount() : int;
|
||||
|
||||
public function length() : int;
|
||||
|
||||
public function getMessageContent();
|
||||
}
|
21
src/ValueObject/SmsTextMessage.php
Fichier normal
21
src/ValueObject/SmsTextMessage.php
Fichier normal
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Phlib\SmsLength\SmsLength;
|
||||
|
||||
class SmsTextMessage extends SmsMessageAbstract
|
||||
{
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function __construct(string $message)
|
||||
{
|
||||
parent::__construct( $message);
|
||||
|
||||
$smsLength = new SmsLength($this->value);
|
||||
$smsLength->validate();
|
||||
}
|
||||
}
|
Chargement…
x
Référencer dans un nouveau ticket
Bloquer un utilisateur