提交 1ee30960 编写于 作者: R root

fecshop

上级 09ee7f1e
......@@ -15,7 +15,29 @@ return [
'successAutoLogin' => true,
# 注册登录成功后,跳转的url
'loginSuccessRedirectUrlKey' => 'customer/account',
'registerPageCaptcha' => true,
'registerPageCaptcha' => true,
'email' => [
'enable' => true,
'block' => 'fecshop\app\appfront\modules\Customer\block\mailer\account\register\EmailBody',
'viewPath' => 'mailer/customer/account/register',
'mailerConfig' => [
'appfront_register' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.sendgrid.net',
'username' => 'support@onfancymail.com',
'password' => 'check301',
'port' => '587',
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8',
],
],
],
]
],
'login' => [
# 在登录页面 customer/account/login 页面登录成功后跳转的urlkey,
......@@ -24,6 +46,13 @@ return [
'otherPageSuccessRedirectUrlKey' => false ,
'loginPageCaptcha' => true, // 登录验证码是否开启
'email' => [
'enable' => true,
'block' => 'fecshop\app\appfront\modules\Customer\block\mailer\account\login\EmailBody',
'viewPath' => 'mailer/customer/account/login',
# 如果不定义 mailerConfig,则会使用email service里面的默认配置
]
],
],
],
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\modules\Customer\block\mailer\account\login;
use Yii;
use fec\helpers\CModule;
use fec\helpers\CRequest;
use yii\base\InvalidValueException;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class EmailBody {
public function getLastData(){
return [];
}
}
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\modules\Customer\block\mailer\account\register;
use Yii;
use fec\helpers\CModule;
use fec\helpers\CRequest;
use yii\base\InvalidValueException;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class EmailBody {
public function getLastData(){
return [];
}
}
\ No newline at end of file
......@@ -32,6 +32,15 @@ class AccountController extends AppfrontController
}
public function actionLogin()
{
/**
$toEmail = 'zqy234@126.com';
// \fecshop\app\appfront\modules\Mailer\Email::sendLoginEmail($toEmail);
\fecshop\app\appfront\modules\Mailer\Email::sendRegisterEmail($toEmail);
exit;
*/
$param = Yii::$app->request->post('editForm');
$this->getBlock()->login($param);
$data = $this->getBlock()->getLastData();
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\modules\Mailer;
use Yii;
use fec\helpers\CConfig;
use fec\controllers\FecController;
use yii\base\InvalidValueException;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Email
{
public static function getSubjectAndBody($block,$viewPath,$langCode=''){
if(!$langCode){
$langCode = Yii::$service->store->currentLangCode;
}
if(!$langCode){
Yii::$service->helper->errors->add('langCode is empty');
return ;
}
$bodyViewFile = $viewPath.'/body_'.$langCode.'.php';
$bodyConfigKey = [
'class' => $block,
'view' => $bodyViewFile,
];
$subjectViewFile = $viewPath.'/subject_'.$langCode.'.php';
$subjectConfigKey = [
'view' => $subjectViewFile,
];
$emailSubject = Yii::$service->page->widget->render($subjectConfigKey);
$emailBody = Yii::$service->page->widget->render($bodyConfigKey);
return [$emailSubject,$emailBody];
}
/**
* @property $toEmail | String send to email address.
*
*/
public static function sendRegisterEmail($toEmail){
$registerParam = Yii::$app->getModule('customer')->params['register'];
if(isset($registerParam['email']['enable']) && $registerParam['email']['enable']){
$mailerConfigParam = '';
if(isset($registerParam['email']['mailerConfig']) && $registerParam['email']['mailerConfig']){
$mailerConfigParam = $registerParam['email']['mailerConfig'];
}
if(isset($registerParam['email']['block']) && $registerParam['email']['block']){
$block = $registerParam['email']['block'];
}
if(isset($registerParam['email']['viewPath']) && $registerParam['email']['viewPath']){
$viewPath = $registerParam['email']['viewPath'];
}
if($block && $viewPath){
list($subject,$htmlBody) = \fecshop\app\appfront\modules\Mailer\Email::getSubjectAndBody($block,$viewPath);
Yii::$service->email->send($toEmail,$subject,$htmlBody,$mailerConfigParam);
}
}
}
public static function sendLoginEmail($toEmail){
$registerParam = Yii::$app->getModule('customer')->params['login'];
if(isset($registerParam['email']['enable']) && $registerParam['email']['enable']){
$mailerConfigParam = '';
if(isset($registerParam['email']['mailerConfig']) && $registerParam['email']['mailerConfig']){
$mailerConfigParam = $registerParam['email']['mailerConfig'];
}
if(isset($registerParam['email']['block']) && $registerParam['email']['block']){
$block = $registerParam['email']['block'];
}
if(isset($registerParam['email']['viewPath']) && $registerParam['email']['viewPath']){
$viewPath = $registerParam['email']['viewPath'];
}
if($block && $viewPath){
list($subject,$htmlBody) = \fecshop\app\appfront\modules\Mailer\Email::getSubjectAndBody($block,$viewPath);
Yii::$service->email->send($toEmail,$subject,$htmlBody,$mailerConfigParam);
}
}
}
}
<?php
/**
* FecShop file.
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
return [
'email' => [
'class' => 'fecshop\services\Email',
'mailerConfig' => [
# 默认通用配置
'default' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.sendgrid.net',
'username' => 'support@onfancymail.com',
'password' => 'check301',
'port' => '587',
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8',
],
],
/*
# 登录账号 - 发送邮件的配置
'login' => 'default',
# 注册账号 - 发送邮件的配置
'register' => 'default',
# 找回密码 - 发送邮件的配置
'forgetPass' => 'default',
# 订阅邮件操作成功后 - 发送邮件的配置
'subscribeEmailSuccess' => 'default',
# 客户订阅邮件成功后,定期发送邮件给客户, - 发送邮件的配置
'subscribeEmail' => 'default',
# 客户评论产品后, - 发送邮件的配置
'reviewProduct' => 'default',
# 客户评论审核成功后, - 发送邮件的配置
'reviewProductAuditSuccess' => 'default',
# 客户评论产品后, - 发送邮件的配置
'contacts' => 'default',
'createNewOrder'=> [ # 创建新订单,但是不一定支付成功
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.sendgrid.net',
'username' => 'support@onfancymail.com',
'password' => 'check301',
'port' => '587',
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8',
],
],
'paySuccessOrder'=> 'createNewOrder', # 支付成功发送的邮件配置,值为 createNewOrder 代表等于 createNewOrder的配置
'shippedOrder' => 'createNewOrder', # 订单发货后,发送的邮件配置,值为 createNewOrder 代表等于 createNewOrder的配置
*/
],
],
];
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use yii\base\BootstrapInterface;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Email extends Service
{
public $mailerConfig;
public $defaultForm;
protected $_mailer; # Array
protected $_mailer_from; #Array
protected $_from;
/**
* 得到MailConfig
*/
protected function getMailerConfig($key = 'default'){
if(isset($this->mailerConfig[$key]) && $this->mailerConfig[$key]){
if(is_array($this->mailerConfig[$key])){
return $this->mailerConfig[$key];
}else if(is_string($this->mailerConfig[$key])){
return $this->getMailerConfig($this->mailerConfig[$key]);
}
}
return '';
}
/**
* 默认的默认form。邮件from
*/
protected function defaultForm($mailerConfig){
if(isset($mailerConfig['transport']['username'])){
if(!empty($mailerConfig['transport']['username'])){
return $mailerConfig['transport']['username'];
}
}
return ;
}
/**
* @property $mailerConfig | Array or String mailer组件的配置,下面是例子,
您可以使用在email service里面默认的配置,也可以动态配置他,下面是参数的例子:
注意:如果自定义传递邮箱配置,不同的配置,要使用不同的configKey
[
'configKey' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.sendgrid.net',
'username' => 'support@onfancymail.com',
'password' => 'check301',
'port' => '587',
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8',
],
],
]
* @return yii的mail组件、
*
*/
protected function actionMailer($mailerConfigParam = ''){
if(!$mailerConfigParam){
$key = 'default';
}else if(is_array($mailerConfigParam)){
$key_arr = array_keys($mailerConfigParam);
$key = $key_arr[0];
}else if(is_string($mailerConfigParam)){
$key = $mailerConfigParam;
}else{
return;
}
if(!$key){
return;
}
//exit;
if(!$this->_mailer[$key]){
$component_name = 'mailer_'.$key;
if(!$mailerConfigParam){
$mailerConfig = $this->getMailerConfig();
if(!is_array($mailerConfig) || empty($mailerConfig)){
return;
}
Yii::$app->set($component_name,$mailerConfig);
}else if(is_array($mailerConfigParam)){
$mailerConfig = $mailerConfigParam[$key];
if(!is_array($mailerConfig) || empty($mailerConfig)){
return;
}
$component_name .= 'custom_';
Yii::$app->set($component_name,$mailerConfig);
}else if(is_string($mailerConfigParam)){
$mailerConfig = $this->getMailerConfig($mailerConfigParam);
if(!is_array($mailerConfig) || empty($mailerConfig)){
return;
}
Yii::$app->set($component_name,$mailerConfig);
}
$this->_mailer_from[$key] = $this->defaultForm($mailerConfig);
$this->_mailer[$key] = Yii::$app->get($component_name);
}
$this->_from = $this->_mailer_from[$key];
//var_dump($this->_mailer[$key]);exit;
return $this->_mailer[$key];
}
/**
*
*/
protected function actionSend($to,$subject,$htmlBody,$mailerConfigParam=''){
/*
$this->mailer()->compose()
->setFrom('support@onfancymail.com')
->setTo('2851823529@qq.com')
->setSubject('111111Message subject222')
->setHtmlBody('<b>HTML content333333333df</b>')
->send();
*/
if(!$subject){
Yii::$service->helper->errors->add('email title is empty');
return;
}
if(!$htmlBody){
Yii::$service->helper->errors->add('email body is empty');
return;
}
$mailer = $this->mailer($mailerConfigParam);
if(!$mailer){
//error
Yii::$service->helper->errors->add('compose is empty, you must check you email config');
return;
}
if(!$this->_from){
//error
Yii::$service->helper->errors->add('email send from is empty');
return;
}else{
$from = $this->_from;
}
echo $from;
echo '<br/><br/>';
echo $to;echo '<br/><br/>';
echo $subject;echo '<br/><br/>';
echo $htmlBody;echo '<br/><br/>';
var_dump($mailer);
$mailer->compose()
->setFrom($from)
->setTo($to)
->setSubject($subject)
->setHtmlBody($htmlBody)
->send();
}
}
\ No newline at end of file
......@@ -25,22 +25,23 @@ class Widget extends Service
public $defaultObMethod = 'getLastData';
public $widgetConfig;
/*
@property configKey String or Array
Array example:
[
# class 选填
'class' => 'fec\block\TestMenu',
# view 为 必填 , view可以用两种方式
# view 1 使用绝对地址的方式
'view' => '@fec/views/testmenu/index.php',
OR
# view 2 使用相对地址,通过当前模板进行查找
'view' => 'cms/home/index.php',
'widgetConfig' =>[
'menu' =>[
# 必填
'class' => 'fec\block\TestMenu',
'view' => '@fec/views/testmenu/index.php',
OR
'view' => 'cms/home/index.php',
# 下面为选填
'method'=> 'getLastData',
'terry1'=> 'My1',
'terry2'=> 'My2',
],
]
# 下面为选填
'method'=> 'getLastData',
'terry1'=> 'My1',
'terry2'=> 'My2',
]
*/
protected function actionRender($configKey,$parentThis=''){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册