mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-22 05:15:29 +09:00
Implement mixing multiple attachments with multiple parts
This commit is contained in:
parent
8c5e34edea
commit
21317a3dc0
1 changed files with 35 additions and 21 deletions
|
|
@ -51,6 +51,7 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface
|
||||||
{
|
{
|
||||||
// Initialize the sender.
|
// Initialize the sender.
|
||||||
$sender = new \Nurigo\Api\Message($this->_config['api_key'], $this->_config['api_secret']);
|
$sender = new \Nurigo\Api\Message($this->_config['api_key'], $this->_config['api_secret']);
|
||||||
|
$status = true;
|
||||||
|
|
||||||
// Get the list of recipients.
|
// Get the list of recipients.
|
||||||
$recipients = $message->getRecipientsGroupedByCountry();
|
$recipients = $message->getRecipientsGroupedByCountry();
|
||||||
|
|
@ -96,8 +97,6 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface
|
||||||
// If the message has an attachment, it must be an MMS.
|
// If the message has an attachment, it must be an MMS.
|
||||||
if ($attachments = $message->getAttachments())
|
if ($attachments = $message->getAttachments())
|
||||||
{
|
{
|
||||||
$image = reset($attachments);
|
|
||||||
$options->image = $image->local_filename;
|
|
||||||
$options->type = 'MMS';
|
$options->type = 'MMS';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,9 +104,10 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface
|
||||||
if ($message->isForceSMS() || ($country > 0 && $country != 82))
|
if ($message->isForceSMS() || ($country > 0 && $country != 82))
|
||||||
{
|
{
|
||||||
unset($options->subject);
|
unset($options->subject);
|
||||||
unset($options->image);
|
$attachments = array();
|
||||||
$options->country = $country;
|
$options->country = $country;
|
||||||
$options->type = 'SMS';
|
$options->type = 'SMS';
|
||||||
|
$message->forceSMS();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split the message if necessary.
|
// Split the message if necessary.
|
||||||
|
|
@ -124,36 +124,50 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface
|
||||||
$content_split = array($content_full);
|
$content_split = array($content_full);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the message.
|
// Send all parts of the split message.
|
||||||
$sent_once = false;
|
$message_count = max(count($content_split), count($attachments));
|
||||||
foreach ($content_split as $i => $content)
|
$last_content = 'MMS';
|
||||||
|
for ($i = 1; $i <= $message_count; $i++)
|
||||||
{
|
{
|
||||||
// If splitting a message, don't send the subject and image more than once.
|
// Get the message content.
|
||||||
if ($sent_once)
|
if ($content = array_shift($content_split))
|
||||||
{
|
{
|
||||||
unset($options->subject);
|
$options->text = $last_content = $content;
|
||||||
unset($options->image);
|
}
|
||||||
if ($options->type === 'MMS')
|
else
|
||||||
{
|
{
|
||||||
$options->type = 'LMS';
|
$options->text = $last_content ?: 'MMS';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the content and send.
|
// Get the attachment.
|
||||||
$options->text = $content;
|
if ($attachment = array_shift($attachments))
|
||||||
$result = $sender->send($options);
|
{
|
||||||
$sent_once = true;
|
$options->image = $attachment->local_filename;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unset($options->image);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine the best message type for this combination of content and attachment.
|
||||||
|
if (!$message->isForceSMS())
|
||||||
|
{
|
||||||
|
$options->type = $attachment ? 'MMS' : ($message->checkLength($content, $this->_maxlength_sms) ? 'SMS' : 'LMS');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the current part of the message.
|
||||||
|
$result = $sender->send($options);
|
||||||
if (!$result->success_count)
|
if (!$result->success_count)
|
||||||
{
|
{
|
||||||
$message->errors[] = 'Error while sending message ' . $i . ' of ' . count($content_split) . ' to ' . $options->to;
|
$error_codes = implode(', ', $result->error_list ?: array('Unknown'));
|
||||||
return false;
|
$message->errors[] = 'Error (' . $error_codes . ') while sending message ' . $i . ' of ' . $message_count . ' to ' . $options->to;
|
||||||
|
$status = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return $status;
|
||||||
}
|
}
|
||||||
catch (\Nurigo\Exceptions\CoolsmsException $e)
|
catch (\Nurigo\Exceptions\CoolsmsException $e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue