作者 邓超

添加订阅

... ... @@ -930,6 +930,16 @@ class Home extends Base {
}
/**
* 解析订阅数据
* @author:dc
* @time 2024/8/7 14:12
*/
public function desubscribe(){
$key = app()->request('key','');
app()->_json(MailFun::deSubscribeUrl($key));
}
}
... ...
... ... @@ -239,6 +239,16 @@ class MailFun {
$mail->Subject = $data['subject'];
$mail->isHTML(true); //Set email format to HTML
// todo:: 订阅功能只可用作单发,不可群发。否则无法验证订阅人
if(count($mail->getToAddresses()) == 1){
$data['body'] = str_replace(
['{#subscribe_uuid#}','%7B%23subscribe_uuid%23%7D'], // 订阅用的key 获取用户信息所用
self::enSubscribeUrl($mail->Username,$mail->getToAddresses()[0][0]??'',$mail->Subject),
$data['body']
);
}
$mail->Body = $data['body'];// html格式的内容
// 发送
... ... @@ -344,4 +354,57 @@ class MailFun {
}
/**
* 生成订阅按钮
* @param string $from_email 发件人
* @param string $to_email 收件人
* @return string
* @author:dc
* @time 2024/8/7 10:56
*/
public static function enSubscribeUrl(string $from_email,string $to_email,string $subject=''){
$params = [
'from' => $from_email,
'to' => $to_email,
'subject' => $subject,
];
$params = json_encode($params);
return md5($from_email.'-'.$to_email.'-aicc')."+".trim(base64_encode($params),'=');
}
/**
* 解析url中的数据
* @param string $url
* @author:dc
* @time 2024/8/7 11:49
*/
public static function deSubscribeUrl(string $url){
list($sign,$params) = explode('+',$url);
if(!$sign || strlen($sign)!=32 || !$params){
return [];
}
$params = base64_decode($params.'==');
$params = @json_decode($params,true);
if(!$params){
return [];
}
if($sign != md5($params['from'].'-'.$params['to'].'-aicc')){
return [];
}
return $params;
}
}
... ...
... ... @@ -59,9 +59,10 @@ return [
'job/detail' => [\Controller\Job::class, 'jobDetail'],
// 上传图片
'upload/image' => [\Controller\Upload::class, 'image']
'upload/image' => [\Controller\Upload::class, 'image'],
// 解析 订阅url参数 数据
'desubscribe' => [\Controller\Home::class, 'desubscribe']
];
... ...