can send Sms from user account
This commit is contained in:
@ -0,0 +1,19 @@
|
|||||||
|
<?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\Linkmobility4OXID\Application\Model\Exceptions;
|
||||||
|
|
||||||
|
interface abortSendingExceptionInterface
|
||||||
|
{}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?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\Linkmobility4OXID\Application\Model\Exceptions;
|
||||||
|
|
||||||
|
class noRecipientFoundException implements abortSendingExceptionInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -15,39 +15,51 @@
|
|||||||
|
|
||||||
namespace D3\Linkmobility4OXID\Application\Model;
|
namespace D3\Linkmobility4OXID\Application\Model;
|
||||||
|
|
||||||
|
use D3\Linkmobility4OXID\Application\Model\Exceptions\abortSendingExceptionInterface;
|
||||||
|
use D3\LinkmobilityClient\Exceptions\ApiException;
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||||
use D3\LinkmobilityClient\SMS\RequestFactory;
|
use D3\LinkmobilityClient\SMS\RequestFactory;
|
||||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
|
||||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use OxidEsales\Eshop\Application\Model\User;
|
use OxidEsales\Eshop\Application\Model\User;
|
||||||
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
|
|
||||||
class Sms
|
class Sms
|
||||||
{
|
{
|
||||||
public function sendMessageToUser(User $user, $message)
|
/**
|
||||||
|
* @param User $user
|
||||||
|
* @param $message
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function sendUserAccountMessage(User $user, $message): bool
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$configuration = oxNew( Configuration::class );
|
$configuration = oxNew( Configuration::class );
|
||||||
$client = oxNew( MessageClient::class )->getClient();
|
$client = oxNew( MessageClient::class )->getClient();
|
||||||
|
|
||||||
$request = oxNew( RequestFactory::class, $message, $client )->getSmsRequest();
|
$request = oxNew( RequestFactory::class, $message, $client )->getSmsRequest();
|
||||||
$request->setTestMode( $configuration->getTestMode())
|
$request->setTestMode( $configuration->getTestMode() )->setMethod( RequestInterface::METHOD_POST )->setSenderAddress( oxNew( Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry() ) )->setSenderAddressType( RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL );
|
||||||
->setMethod(RequestInterface::METHOD_POST)
|
|
||||||
->setSenderAddress(
|
|
||||||
oxNew(Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry())
|
|
||||||
)
|
|
||||||
->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL);
|
|
||||||
|
|
||||||
$recipientsList = $request->getRecipientsList();
|
$recipientsList = $request->getRecipientsList();
|
||||||
dumpvar($recipientsList);
|
$recipientsList->add(oxNew( UserRecipients::class, $user )->getSmsRecipient());
|
||||||
/*
|
$response = $client->request( $request );
|
||||||
foreach (oxNew(UserRecipients::class)->getSmsRecipients() as $recipient) {
|
|
||||||
$recipientsList->
|
return $response->isSuccessful();
|
||||||
|
} catch (abortSendingExceptionInterface $e) {
|
||||||
|
Registry::getLogger()->warning($e->getMessage());
|
||||||
|
Registry::getUtilsView()->addErrorToDisplay($e);
|
||||||
|
} catch (GuzzleException $e) {
|
||||||
|
Registry::getLogger()->warning($e->getMessage());
|
||||||
|
Registry::getUtilsView()->addErrorToDisplay($e);
|
||||||
|
} catch (ApiException $e) {
|
||||||
|
Registry::getLogger()->warning($e->getMessage());
|
||||||
|
Registry::getUtilsView()->addErrorToDisplay($e);
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
Registry::getLogger()->warning($e->getMessage());
|
||||||
|
Registry::getUtilsView()->addErrorToDisplay($e);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
/*
|
return false;
|
||||||
->add(oxNew(Recipient::class, '+49(0)176-21164371', 'DE'))
|
|
||||||
->add(oxNew(Recipient::class, '+49176 21164372', 'DE'))
|
|
||||||
->add(oxNew(Recipient::class, '03721268090', 'DE'))
|
|
||||||
->add(oxNew(Recipient::class, '0049176abc21164373', 'DE'));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,6 +15,9 @@
|
|||||||
|
|
||||||
namespace D3\Linkmobility4OXID\Application\Model;
|
namespace D3\Linkmobility4OXID\Application\Model;
|
||||||
|
|
||||||
|
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
||||||
|
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||||
|
use OxidEsales\Eshop\Application\Model\Country;
|
||||||
use OxidEsales\Eshop\Application\Model\User;
|
use OxidEsales\Eshop\Application\Model\User;
|
||||||
|
|
||||||
class UserRecipients
|
class UserRecipients
|
||||||
@ -29,14 +32,25 @@ class UserRecipients
|
|||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSmsRecipients()
|
/**
|
||||||
|
* @return Recipient
|
||||||
|
* @throws noRecipientFoundException
|
||||||
|
*/
|
||||||
|
public function getSmsRecipient(): Recipient
|
||||||
{
|
{
|
||||||
dumpvar(array_map(
|
foreach ($this->getSmsRecipientFields() as $fieldName)
|
||||||
function ($fieldName) {
|
{
|
||||||
dumpvar($fieldName);
|
$content = trim($this->user->getFieldData($fieldName));
|
||||||
},
|
if (strlen($content)) {
|
||||||
$this->getSmsRecipientFields()
|
|
||||||
));
|
$country = oxNew(Country::class);
|
||||||
|
$country->load($this->user->getFieldData('oxcountryid'));
|
||||||
|
|
||||||
|
return oxNew(Recipient::class, $content, $country->getFieldData('oxisoalpha2'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw oxNew(noRecipientFoundException::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,9 +64,4 @@ dumpvar($fieldName);
|
|||||||
'oxprivfon'
|
'oxprivfon'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSmsCountry()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -16,13 +16,7 @@
|
|||||||
namespace D3\Linkmobility4OXID\Modules\Application\Controller;
|
namespace D3\Linkmobility4OXID\Modules\Application\Controller;
|
||||||
|
|
||||||
use D3\Linkmobility4OXID\Application\Model\Sms;
|
use D3\Linkmobility4OXID\Application\Model\Sms;
|
||||||
use D3\LinkmobilityClient\Client;
|
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
|
||||||
use D3\LinkmobilityClient\SMS\RequestFactory;
|
|
||||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
|
||||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
|
||||||
use OxidEsales\Eshop\Application\Model\User;
|
use OxidEsales\Eshop\Application\Model\User;
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
|
||||||
|
|
||||||
class StartController extends StartController_parent
|
class StartController extends StartController_parent
|
||||||
{
|
{
|
||||||
@ -33,33 +27,8 @@ class StartController extends StartController_parent
|
|||||||
|
|
||||||
$user = oxNew(User::class);
|
$user = oxNew(User::class);
|
||||||
$user->load('oxdefaultadmin');
|
$user->load('oxdefaultadmin');
|
||||||
$sms = oxNew(Sms::class)->sendMessageToUser($user, $message);
|
$success = oxNew(Sms::class)->sendUserAccountMessage($user, $message);
|
||||||
die();
|
dumpvar($success);
|
||||||
|
|
||||||
$lmClient = oxNew(Client::class, trim(Registry::getConfig()->getConfigParam('d3linkmobility_apitoken')));
|
|
||||||
$lmClient->setLogger(Registry::getLogger());
|
|
||||||
$request = oxNew(RequestFactory::class, $message, $lmClient)->getSmsRequest();
|
|
||||||
$request->setTestMode( (bool) Registry::getConfig()->getConfigParam( 'd3linkmobility_debug'))
|
|
||||||
->setMethod(RequestInterface::METHOD_POST)
|
|
||||||
->setSenderAddress(oxNew(Sender::class, '017621164371', 'DE'))
|
|
||||||
->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL);
|
|
||||||
$request->getRecipientsList()
|
|
||||||
->add(oxNew(Recipient::class, '+49(0)176-21164371', 'DE'))
|
|
||||||
->add(oxNew(Recipient::class, '+49176 21164372', 'DE'))
|
|
||||||
->add(oxNew(Recipient::class, '03721268090', 'DE'))
|
|
||||||
->add(oxNew(Recipient::class, '0049176abc21164373', 'DE'));
|
|
||||||
|
|
||||||
try {
|
|
||||||
$response = $lmClient->request( $request );
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
dumpvar($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
dumpvar($response->isSuccessful());
|
|
||||||
dumpvar($response->getInternalStatus());
|
|
||||||
dumpvar($response->getErrorMessage());
|
|
||||||
dumpvar($response->getSmsCount());
|
|
||||||
|
|
||||||
return parent::render();
|
return parent::render();
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user