cymapgt / notifier
一致的通信接口,允许切换第三方通信包
3.0.0
2019-09-25 00:40 UTC
Requires
- php: >=7.2.0
- phpmailer/phpmailer: ~6.0
- swiftmailer/swiftmailer: ^6.0.0
Requires (Dev)
- phpunit/phpunit: 8.*
This package is auto-updated.
Last update: 2024-09-22 22:11:02 UTC
README
使用该通知器接口封装第三方通信包,如电子邮件、短信、聊天、即时通讯、VoIP
通知器命名空间包含实现通知器接口的库。
此接口提供了一套标准的常见函数,用于发送通信。这可以是电子邮件通信或短信通信。
有关通知器接口的详细文档,请参阅通知器API。
以下提供使用说明
使用说明
1 使用SwiftMailer发送电子邮件
1.1 准备你的Autoloader
//configure the SMTP transport (wasteful but use in proto :/
// Create the Transport
$swiftMailerTransport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
->setUsername('smtpuser@smtpserver.com')
->setPassword('smtppasswordhere');
1.2 编辑你的PHP脚本
1.2.1 配置你的SMTP配置数组
这些设置可以从数据库中提取或硬编码。使用与之前部分中配置SwiftMailer传输相同的SMTP用户名和密码
$configuration = array (
'EMAIL_CLIENT' => 'SwiftMailer',
'USERNAME' => 'smtpuser@smtpserver.com',
'PASSWORD' => 'smtppasswordhere',
'HOST' => 'smtp.gmail.com',
'IS_SMTP' => true,
'SMTP_DEBUG' => 2,
'SMTP_AUTH' => true,
'PORT' => 587,
'SMTP_SECURE' => 'tls',
'LINE_ENDING' => '\n',
'CHARSET' => 'utf-8',
'RETURN_PATH' => 'smptuser@smtpserver.com',
'EMAIL_FROM' => 'smtppasswordhere',
'EMAIL_FROM_NAME' => 'Cyril Ogana',
'WORD_WRAP' => 80,
'IS_HTML' => true,
"USE_ANTIFLOOD" => false,
"ANTIFLOOD_FREQUENCY_MAILS" => null,
"ANTIFLOOD_FREQUENCY_SECONDS" => null,
"USE_THROTTLER" => false,
"THROTTLER_MAILS_PER_MINUTE" => null,
"THROTTLER_BYTES_PER_MINUTE" => null
);
1.2.2 构建你的通知器类并发送消息
//declare namespace usage
use cymapgt\core\utility\notifier\NotifierEmailSwiftMailerService;
//create notifier object. The swiftMailerTransport object we pass to it is the one we created in autoloader
$notifierObj = new NotifierEmailSwiftMailerService($swiftMailerTransport);
//our message is in the form of an array
$message = array (
"TO" => array(
array (
"name" => "Cyril Ogana",
"email" => "cogana@gmail.com"
)
),
"SUBJECT" =>"MY MAIL",
"MSG_HTML" => "Test Notifier 1:)",
"ATTACHMENTS" => array(
"imageAttachment" => "c:/User/Image1.jpg"
)
);
//load our message to the notifier
$notifierObj->setMessage($message);
//send all messages
$notifierObj->sendMessagesAll(array());
2 使用AfricasTalking发送短信
2.1 编辑你的PHP脚本
2.2.1 配置你的AfricasTalking配置数组
这些设置可以从数据库中提取或硬编码。
$configuration = array(
"SMS_CLIENT" => "AfricasTalking",
"USERNAME" => "SMSUSER",
"PASSWORD" => "smsApiKeyHere",
"APIKEY" => "",
"IS_API" => true,
"IS_BEHIND_PROXY" => false,
"PROXY_AUTH" => -1,
"PROXY_TYPE" => -1,
"PROXY_SERVER" => "",
"PROXY_LOGIN" => "",
"MAX_CHARS" => 140,
"SMS_FROM_NAME" => "SMSUSER"
);
2.2.2 构建你的通知器类并发送消息
请注意,配置和消息构建是不同的。认证配置、发送和接收通信的详细信息由通知器接口抽象化
//declare namespace usage
use cymapgt\core\utility\notifier\NotifierSmsAfricasTalkingService;
/*create notifier object for africas talking. If you are behind a proxy, the
*second parameter should be true, and your configuration array should contain
*the proxy server settings
*/
$notifierObj = new NotifierSmsAfricasTalkingService($configuration, false);
//our message is in the form of an array
$message = array (
"RECIPIENTS" => array(
"+254723712233",
"+254720123456",
"+254721000999"
),
"MESSAGE" =>"MY TEST SMS :)"
);
//load our message to the notifier
$notifierObj->setMessage($message);
//send all the SMS
$notifierObj->sendMessagesAll(array());
测试
该软件包提供PHPUnit测试
贡献
- 通过电子邮件 @rhossis 或通过Skype联系
- 您将作为贡献者添加为作者
许可证
BSD-3条款