mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 11:11:39 +09:00
Merge branch 'master' into pr/manager-scopes
This commit is contained in:
commit
2620049b4e
18 changed files with 136 additions and 202 deletions
|
|
@ -209,9 +209,10 @@ class HTTP
|
|||
];
|
||||
|
||||
// Add proxy settings.
|
||||
if (defined('__PROXY_SERVER__'))
|
||||
$proxy = config('other.proxy') ?: (defined('__PROXY_SERVER__') ? constant('__PROXY_SERVER__') : '');
|
||||
if ($proxy !== '')
|
||||
{
|
||||
$proxy = parse_url(constant('__PROXY_SERVER__'));
|
||||
$proxy = parse_url($proxy);
|
||||
$proxy_scheme = preg_match('/^(https|socks)/', $proxy['scheme'] ?? '') ? ($proxy['scheme'] . '://') : 'http://';
|
||||
$proxy_auth = (!empty($proxy['user']) && !empty($proxy['pass'])) ? ($proxy['user'] . ':' . $proxy['pass'] . '@') : '';
|
||||
$settings['proxy'] = sprintf('%s%s%s:%s', $proxy_scheme, $proxy_auth, $proxy['host'], $proxy['port']);
|
||||
|
|
|
|||
|
|
@ -7,15 +7,6 @@ namespace Rhymix\Framework\Drivers\Mail;
|
|||
*/
|
||||
class MailFunction extends Base implements \Rhymix\Framework\Drivers\MailInterface
|
||||
{
|
||||
/**
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
include_once \RX_BASEDIR . 'common/libraries/swift_mail.php';
|
||||
$this->_mailer = new \Swift_Mailer(new \Swift_MailTransport);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the human-readable name of this mail driver.
|
||||
*
|
||||
|
|
@ -58,6 +49,12 @@ class MailFunction extends Base implements \Rhymix\Framework\Drivers\MailInterfa
|
|||
*/
|
||||
public function send(\Rhymix\Framework\Mail $message)
|
||||
{
|
||||
if ($this->_mailer === null)
|
||||
{
|
||||
include_once \RX_BASEDIR . 'common/libraries/swift_mail.php';
|
||||
$this->_mailer = new \Swift_Mailer(new \Swift_MailTransport);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$errors = [];
|
||||
|
|
|
|||
|
|
@ -7,23 +7,6 @@ namespace Rhymix\Framework\Drivers\Mail;
|
|||
*/
|
||||
class SMTP extends Base implements \Rhymix\Framework\Drivers\MailInterface
|
||||
{
|
||||
/**
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
protected function __construct(array $config)
|
||||
{
|
||||
$security = in_array($config['smtp_security'], ['ssl', 'tls']) ? $config['smtp_security'] : null;
|
||||
$transport = new \Swift_SmtpTransport($config['smtp_host'], $config['smtp_port'], $security);
|
||||
$transport->setUsername($config['smtp_user']);
|
||||
$transport->setPassword($config['smtp_pass']);
|
||||
$local_domain = $transport->getLocalDomain();
|
||||
if (preg_match('/^\*\.(.+)$/', $local_domain, $matches))
|
||||
{
|
||||
$transport->setLocalDomain($matches[1]);
|
||||
}
|
||||
$this->mailer = new \Swift_Mailer($transport);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of configuration fields required by this mail driver.
|
||||
*
|
||||
|
|
@ -56,9 +39,32 @@ class SMTP extends Base implements \Rhymix\Framework\Drivers\MailInterface
|
|||
*/
|
||||
public function send(\Rhymix\Framework\Mail $message)
|
||||
{
|
||||
if ($this->_mailer === null)
|
||||
{
|
||||
if (isset($this->_config['smtp_security']) && in_array($this->_config['smtp_security'], ['ssl', 'tls']))
|
||||
{
|
||||
$security = $this->_config['smtp_security'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$security = null;
|
||||
}
|
||||
|
||||
$transport = new \Swift_SmtpTransport($this->_config['smtp_host'], $this->_config['smtp_port'], $security);
|
||||
$transport->setUsername($this->_config['smtp_user']);
|
||||
$transport->setPassword($this->_config['smtp_pass']);
|
||||
$local_domain = $transport->getLocalDomain();
|
||||
if (preg_match('/^\*\.(.+)$/', $local_domain, $matches))
|
||||
{
|
||||
$transport->setLocalDomain($matches[1]);
|
||||
}
|
||||
$this->_mailer = new \Swift_Mailer($transport);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$result = $this->mailer->send($message->message, $errors);
|
||||
$errors = [];
|
||||
$result = $this->_mailer->send($message->message, $errors);
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,141 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers\SMS;
|
||||
|
||||
/**
|
||||
* The ApiStore SMS driver.
|
||||
*/
|
||||
class ApiStore extends Base implements \Rhymix\Framework\Drivers\SMSInterface
|
||||
{
|
||||
/**
|
||||
* API specifications.
|
||||
*/
|
||||
protected static $_spec = array(
|
||||
'max_recipients' => 500,
|
||||
'sms_max_length' => 90,
|
||||
'sms_max_length_in_charset' => 'CP949',
|
||||
'lms_supported' => true,
|
||||
'lms_supported_country_codes' => array(82),
|
||||
'lms_max_length' => 2000,
|
||||
'lms_max_length_in_charset' => 'CP949',
|
||||
'lms_subject_supported' => true,
|
||||
'lms_subject_max_length' => 60,
|
||||
'mms_supported' => false,
|
||||
'delay_supported' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* Config keys used by this driver are stored here.
|
||||
*/
|
||||
protected static $_required_config = array('api_user', 'api_key');
|
||||
|
||||
/**
|
||||
* Check if the current SMS driver is supported on this server.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the last response.
|
||||
*/
|
||||
protected $_last_response = '';
|
||||
|
||||
/**
|
||||
* Send a message.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param array $messages
|
||||
* @param object $original
|
||||
* @return bool
|
||||
*/
|
||||
public function send(array $messages, \Rhymix\Framework\SMS $original)
|
||||
{
|
||||
$status = true;
|
||||
|
||||
foreach ($messages as $i => $message)
|
||||
{
|
||||
$data = array();
|
||||
$data['send_phone'] = $message->from;
|
||||
$data['dest_phone'] = implode(',', $message->to);
|
||||
$data['msg_body'] = strval($message->content);
|
||||
if ($message->type !== 'SMS' && $message->subject)
|
||||
{
|
||||
$data['subject'] = $message->subject;
|
||||
}
|
||||
|
||||
$result = $this->_apiCall(sprintf('message/%s', strtolower($message->type)), $data);
|
||||
if (!$result)
|
||||
{
|
||||
$message->errors[] = 'ApiStore API returned invalid response: ' . $this->_getLastResponse();
|
||||
$status = false;
|
||||
}
|
||||
if ($result->result_message !== 'OK')
|
||||
{
|
||||
$message->errors[] = 'ApiStore API error: ' . $result->result_code . ' ' . $result->result_message;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* API call.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $data
|
||||
* @param string $method (optional)
|
||||
* @return object|false
|
||||
*/
|
||||
protected function _apiCall(string $url, array $data, string $method = 'POST')
|
||||
{
|
||||
// Build the request URL.
|
||||
if ($data['version'])
|
||||
{
|
||||
$version = $data['version'];
|
||||
unset($data['version']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$version = 1;
|
||||
}
|
||||
$url = sprintf('http://api.apistore.co.kr/ppurio/%d/%s/%s', $version, trim($url, '/'), $this->_config['api_user']);
|
||||
|
||||
// Set the API key in the header.
|
||||
$headers = array(
|
||||
'x-waple-authorization' => $this->_config['api_key'],
|
||||
);
|
||||
|
||||
// Send the API reqeust.
|
||||
if ($method === 'GET')
|
||||
{
|
||||
if ($data)
|
||||
{
|
||||
$url .= '?' . http_build_query($data);
|
||||
}
|
||||
$this->_last_response = \FileHandler::getRemoteResource($url, null, 5, $method, null, $headers) ?: '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_last_response = \FileHandler::getRemoteResource($url, $data, 5, $method, null, $headers) ?: '';
|
||||
}
|
||||
$result = @json_decode($this->_last_response);
|
||||
return $result ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the last API response.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getLastResponse()
|
||||
{
|
||||
return $this->_last_response;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue