8
0
Fork 1

can send Sms from user account

Dieser Commit ist enthalten in:
Daniel Seifert 2022-07-01 16:11:40 +02:00
Ursprung b4f7d1a1bd
Commit ed1a0a15b8
Signiert von: DanielS
GPG-Schlüssel-ID: 8A7C4C6ED1915C6F
5 geänderte Dateien mit 98 neuen und 68 gelöschten Zeilen

Datei anzeigen

@ -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
{}

Datei anzeigen

@ -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
{
}

Datei anzeigen

@ -15,39 +15,51 @@
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\SMS\RequestFactory;
use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\LinkmobilityClient\ValueObject\Sender;
use GuzzleHttp\Exception\GuzzleException;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
class Sms
{
public function sendMessageToUser(User $user, $message)
/**
* @param User $user
* @param $message
*
* @return bool
*/
public function sendUserAccountMessage(User $user, $message): bool
{
$configuration = oxNew(Configuration::class);
$client = oxNew(MessageClient::class)->getClient();
try {
$configuration = oxNew( Configuration::class );
$client = oxNew( MessageClient::class )->getClient();
$request = oxNew(RequestFactory::class, $message, $client)->getSmsRequest();
$request->setTestMode( $configuration->getTestMode())
->setMethod(RequestInterface::METHOD_POST)
->setSenderAddress(
oxNew(Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry())
)
->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL);
$request = oxNew( RequestFactory::class, $message, $client )->getSmsRequest();
$request->setTestMode( $configuration->getTestMode() )->setMethod( RequestInterface::METHOD_POST )->setSenderAddress( oxNew( Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry() ) )->setSenderAddressType( RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL );
$recipientsList = $request->getRecipientsList();
dumpvar($recipientsList);
/*
foreach (oxNew(UserRecipients::class)->getSmsRecipients() as $recipient) {
$recipientsList->
$recipientsList = $request->getRecipientsList();
$recipientsList->add(oxNew( UserRecipients::class, $user )->getSmsRecipient());
$response = $client->request( $request );
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);
}
*/
/*
->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'));
*/
return false;
}
}

Datei anzeigen

@ -15,6 +15,9 @@
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;
class UserRecipients
@ -29,14 +32,25 @@ class UserRecipients
$this->user = $user;
}
public function getSmsRecipients()
/**
* @return Recipient
* @throws noRecipientFoundException
*/
public function getSmsRecipient(): Recipient
{
dumpvar(array_map(
function ($fieldName) {
dumpvar($fieldName);
},
$this->getSmsRecipientFields()
));
foreach ($this->getSmsRecipientFields() as $fieldName)
{
$content = trim($this->user->getFieldData($fieldName));
if (strlen($content)) {
$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'
];
}
public function getSmsCountry()
{
}
}

Datei anzeigen

@ -16,13 +16,7 @@
namespace D3\Linkmobility4OXID\Modules\Application\Controller;
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\Core\Registry;
class StartController extends StartController_parent
{
@ -33,33 +27,8 @@ class StartController extends StartController_parent
$user = oxNew(User::class);
$user->load('oxdefaultadmin');
$sms = oxNew(Sms::class)->sendMessageToUser($user, $message);
die();
$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());
$success = oxNew(Sms::class)->sendUserAccountMessage($user, $message);
dumpvar($success);
return parent::render();
}
}