Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
1ee30960
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1ee30960
编写于
10月 08, 2016
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fecshop
上级
09ee7f1e
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
453 addition
and
15 deletion
+453
-15
app/appfront/config/modules/Customer.php
app/appfront/config/modules/Customer.php
+30
-1
app/appfront/modules/Customer/block/mailer/account/login/EmailBody.php
...modules/Customer/block/mailer/account/login/EmailBody.php
+25
-0
app/appfront/modules/Customer/block/mailer/account/register/EmailBody.php
...ules/Customer/block/mailer/account/register/EmailBody.php
+25
-0
app/appfront/modules/Customer/controllers/AccountController.php
...pfront/modules/Customer/controllers/AccountController.php
+9
-0
app/appfront/modules/Mailer/Email.php
app/appfront/modules/Mailer/Email.php
+97
-0
app/appfront/theme/base/front/mailer/customer/account/login/body_de.php
...heme/base/front/mailer/customer/account/login/body_de.php
+0
-0
app/appfront/theme/base/front/mailer/customer/account/login/body_en.php
...heme/base/front/mailer/customer/account/login/body_en.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/login/body_es.php
...heme/base/front/mailer/customer/account/login/body_es.php
+0
-0
app/appfront/theme/base/front/mailer/customer/account/login/body_fr.php
...heme/base/front/mailer/customer/account/login/body_fr.php
+0
-0
app/appfront/theme/base/front/mailer/customer/account/login/body_zh.php
...heme/base/front/mailer/customer/account/login/body_zh.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/login/subject_de.php
...e/base/front/mailer/customer/account/login/subject_de.php
+0
-0
app/appfront/theme/base/front/mailer/customer/account/login/subject_en.php
...e/base/front/mailer/customer/account/login/subject_en.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/login/subject_es.php
...e/base/front/mailer/customer/account/login/subject_es.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/login/subject_fr.php
...e/base/front/mailer/customer/account/login/subject_fr.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/login/subject_zh.php
...e/base/front/mailer/customer/account/login/subject_zh.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/register/body_en.php
...e/base/front/mailer/customer/account/register/body_en.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/register/body_es.php
...e/base/front/mailer/customer/account/register/body_es.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/register/body_zh.php
...e/base/front/mailer/customer/account/register/body_zh.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/register/subject_en.php
...ase/front/mailer/customer/account/register/subject_en.php
+1
-0
app/appfront/theme/base/front/mailer/customer/account/register/subject_zh.php
...ase/front/mailer/customer/account/register/subject_zh.php
+1
-0
config/services/Email.php
config/services/Email.php
+67
-0
services/Email.php
services/Email.php
+174
-0
services/page/Widget.php
services/page/Widget.php
+15
-14
未找到文件。
app/appfront/config/modules/Customer.php
浏览文件 @
1ee30960
...
...
@@ -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里面的默认配置
]
],
],
],
...
...
app/appfront/modules/Customer/block/mailer/account/login/EmailBody.php
0 → 100644
浏览文件 @
1ee30960
<?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
app/appfront/modules/Customer/block/mailer/account/register/EmailBody.php
0 → 100644
浏览文件 @
1ee30960
<?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
app/appfront/modules/Customer/controllers/AccountController.php
浏览文件 @
1ee30960
...
...
@@ -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
();
...
...
app/appfront/modules/Mailer/Email.php
0 → 100644
浏览文件 @
1ee30960
<?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
);
}
}
}
}
app/appfront/theme/base/front/mailer/customer/account/login/body_de.php
0 → 100644
浏览文件 @
1ee30960
app/appfront/theme/base/front/mailer/customer/account/login/body_en.php
0 → 100644
浏览文件 @
1ee30960
login
body
en
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/login/body_es.php
0 → 100644
浏览文件 @
1ee30960
app/appfront/theme/base/front/mailer/customer/account/login/body_fr.php
0 → 100644
浏览文件 @
1ee30960
app/appfront/theme/base/front/mailer/customer/account/login/body_zh.php
0 → 100644
浏览文件 @
1ee30960
login
body
zh
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/login/subject_de.php
0 → 100644
浏览文件 @
1ee30960
app/appfront/theme/base/front/mailer/customer/account/login/subject_en.php
0 → 100644
浏览文件 @
1ee30960
login
subject
en
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/login/subject_es.php
0 → 100644
浏览文件 @
1ee30960
login
subject
es
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/login/subject_fr.php
0 → 100644
浏览文件 @
1ee30960
login
subject
fr
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/login/subject_zh.php
0 → 100644
浏览文件 @
1ee30960
login
subject
zh
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/register/body_en.php
0 → 100644
浏览文件 @
1ee30960
register
body
en
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/register/body_es.php
0 → 100644
浏览文件 @
1ee30960
register
body
es
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/register/body_zh.php
0 → 100644
浏览文件 @
1ee30960
register
body
zh
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/register/subject_en.php
0 → 100644
浏览文件 @
1ee30960
register
subject
en
\ No newline at end of file
app/appfront/theme/base/front/mailer/customer/account/register/subject_zh.php
0 → 100644
浏览文件 @
1ee30960
register
subject
zh
\ No newline at end of file
config/services/Email.php
0 → 100644
浏览文件 @
1ee30960
<?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
services/Email.php
浏览文件 @
1ee30960
<?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
services/page/Widget.php
浏览文件 @
1ee30960
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录