[ 'email_subject' => 'Congratulations! Your article published in {#email_subject#} has recently been cited', // 'email_content' => ' // Dear {#author_name#},

// I hope this message finds you well! I would like to take this opportunity to extend my warmest congratulations to you. Your article, "{#article_name#}" has been cited in "{#journal_name#}"{#factor#}. This is an incredible achievement that truly reflects your outstanding contributions to the field.

// Once again, congratulations! I look forward to seeing more of your remarkable research in the future!

// Best regards,
// {#editorinchief#}
// {#journal_title#}
// Website:{#journal_usx#}
// X: @{#journal_sx#}Journals', 'email_content' => "Dear {#author_name#},

I hope this message finds you well!

I am writing to inform you that your article, titled “{#article_title#}” published in {#journal_title#} has recently been cited in th following recently work. For your reference, here are the details of the citation:

Citing Article: {#article_name#}
{#author#} Published in: {#journal_name#}
{#year#} {#doi_url#} We greatly appreciate your valuable contribution to {#journal_title#} and are delighted to see your work being recognized and cited. It's a pleasure to witness the ongoing influence of your research.

We believe that your expertise and insights could lead to many productive and impactful joint efforts in the future. Should you be interested in exploring opportunities for collaboration, please do not hesitate to reach out.

Thank you for your ongoing contributions to the academic community! Congratulations!

Best regards,
{#editorinchief#}
{#journal_title#}
Website:{#journal_usx#}
X: @{#journal_sx#}Journals" ] ]; protected $sDoiUrl = 'https://doi.org/'; public function __construct(\think\Request $request = null) { parent::__construct($request); } /** * 查询文章是否被引用 并发送邮件给通讯作者 * * @return void */ public function articleCite(){ $aParam = $this->request->post(); $sDate = empty($aParam['date']) ? date('Y-m-d', strtotime('-1 day')) : $aParam['date']; //接口请求地址 $sUrl = $this->sJournalUrl.'crontab/Cite/getList'; //请求接口获取数据 $aParam['date'] = $sDate; $aResult = object_to_array(json_decode(myPost($sUrl, $aParam))); $aContent = empty($aResult['data']) ? [] : $aResult['data']; if(empty($aContent)){ $this->showMessage($aResult['msg'] ?? '接口异常',2); exit; } //获取数据-文章引用数据 $aArticleCite = empty($aContent['article_cite']) ? [] : $aContent['article_cite']; if(empty($aArticleCite)){ $this->showMessage('未查询到引用文章数据:'.$sDate,2); exit; } $aCite = []; foreach ($aArticleCite as $key => $value) { $aCite[$value['article_id']][] = $value; } //获取数据-文章通讯作者数据 $aArticleAuthor = empty($aContent['article_author']) ? [] : $aContent['article_author']; if(empty($aArticleAuthor)){ $this->showMessage('未查询到引用文章通讯作者数据:'.$sDate,2); exit; } $aArticleId = array_unique(array_column($aArticleAuthor, 'article_id')); //获取数据-文章数据 $aArticle = empty($aContent['article']) ? [] : $aContent['article']; //期刊数据 $aJournal = empty($aContent['journal']) ? [] : $aContent['journal']; //查询邮件发送日志 $aArticleCiteId = array_column($aArticleCite, 'article_cite_id'); $aWhere = ['article_cite_id' => ['in',$aArticleCiteId],'is_success' => 1]; $aEmailLog = Db::name('email_article_cite')->field('article_cite_id,email')->where($aWhere)->select(); $aLog = []; if(!empty($aEmailLog)){ foreach ($aEmailLog as $key => $value) { $aLog[$value['email']][] = $value['article_cite_id']; } } //邮件发送 //获取邮件模版 $aEmailCite= $this->aEmailConfig['cite']; //邮件发送日志记录数组 $aEmailLog = []; $aSendEmail = [];//['2101' => ['mohammadalipour_z@yahoo.com']]; foreach ($aArticleAuthor as $key => $value) { //作者邮箱-发送信息 $email = empty($value['email']) ? '' : $value['email']; if(empty($email)){ continue; } //获取引用文章信息 $aArticleCite = empty($aCite[$value['article_id']]) ? [] : $aCite[$value['article_id']]; if(empty($aArticleCite)){ $this->showMessage('未查询到文章引用信息为空,文章ID:'.$value['article_id']."\n\n",2); continue; } //判断同一个邮箱是否重复发送 if(!empty($aSendEmail[$value['article_id']]) && in_array($email, $aSendEmail[$value['article_id']])){ continue; } //用户信息 $realname = empty($value['author_name']) ? $email : $value['author_name']; //邮件日志 $aEmailLogInfo = empty($aLog[$email]) ? [] : $aLog[$email]; foreach ($aArticleCite as $val) { if(in_array($val['article_cite_id'], $aEmailLogInfo)){ $this->showMessage('文章标题为:'.$val['article_name'].'邮箱账号为:'.$email."已发送过邮件\n\n",2); continue; } //期刊数据 $aJournalInfo = empty($aJournal[$val['journal_id']]) ? [] : $aJournal[$val['journal_id']]; if(empty($aJournalInfo)){ $this->showMessage('未查询到文章标题为:'.$val['article_name'].'期刊信息'."\n\n",2); continue; } //期刊标题 $from_name = empty($aJournalInfo['journal_title']) ? '' : $aJournalInfo['journal_title']; //邮件标题 $title = str_replace('{#email_subject#}', $from_name, $aEmailCite['email_subject']); //邮件内容 $aSearch = [ '{#author_name#}' => empty($realname) ? $email : $realname, '{#article_name#}' => empty($val['article_name']) ? '' : $val['article_name'],//文章标题 '{#journal_name#}' => empty($val['journal_name']) ? '' : $val['journal_name'],//期刊名 '{#factor#}' => empty($val['factor']) ? '' : ' (Impact Factor: '.$val['factor'].')',//影响因子 '{#editorinchief#}' => empty($aJournalInfo['editorinchief']) ? '' : $aJournalInfo['editorinchief'],//总编辑 '{#journal_title#}' => $from_name,//期刊名 '{#journal_usx#}' => empty($aJournalInfo['usx']) ? '' : $this->sJournalUsx.$aJournalInfo['usx'],//官网地址 '{#journal_sx#}' => empty($aJournalInfo['sx']) ? '' : $aJournalInfo['sx'],//期刊sx '{#author#}' => empty($val['author']) ? '' : 'Citing Author(s): '.$val['author'].'
'//引用作者 ]; $aVol = empty($val['vol']) ? [] : explode(' ',$val['vol']); $aSearch['{#year#}'] = empty($aVol[0]) ? '' : 'Year: '.$aVol[0].'
'; $aSearch['{#doi_url#}'] = empty($val['doi']) ? '' : 'DOI or Link to Citing Article: '.$this->sDoiUrl.$val['doi'].'

'; $aSearch['{#article_title#}'] = empty($aArticle[$val['article_id']]) ? '' : strip_tags($aArticle[$val['article_id']]); $content = str_replace(array_keys($aSearch), array_values($aSearch), $aEmailCite['email_content']); //判断标题和内容是否为空 if(empty($title) || empty($content)){ $this->showMessage('未查询到文章标题为:'.$val['article_name'].'标题为'.$title.'为空或邮件内容为'.$content."为空\n\n",2); continue; } $pre = Env::get('emailtemplete.pre'); $net = Env::get('emailtemplete.net'); $net1 = str_replace("{{email}}",trim($email),$net); $content=$pre.$content.$net1; //发送邮件 $memail = empty($aJournalInfo['email']) ? '' : $aJournalInfo['email']; $mpassword = empty($aJournalInfo['epassword']) ? '' : $aJournalInfo['epassword']; $aResult = sendEmail($email,$title,$from_name,$content,$memail,$mpassword); $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; $iIsSuccess = 2; $sMsg = empty($aResult['msg']) ? '未知' : $aResult['msg']; if($iStatus == 1){ $iIsSuccess = 1; $sMsg = '成功'; } $this->showMessage('给邮箱:'.$email.'发送邮件-'.$sMsg."\n\n",2); $aEmailLog[] = ['article_id' => $val['article_id'],'article_cite_id' => $val['article_cite_id'],'email' => $email,'content' => $content,'create_tiem' => time(),'is_success' => $iIsSuccess,'journal_id' => $val['journal_id'],'journal_issn' => $aJournalInfo['issn'],'msg' => $sMsg]; $aSendEmail[$value['article_id']][] = $email; } } //插入日志记录 if(!empty($aEmailLog)){ $result = Db::name('email_article_cite')->insertAll($aEmailLog); if($result === false){ $this->showMessage('邮件发送日志插入失败:'.json_encode($aEmailLog),2); exit; } } $this->showMessage('批量处理文章引用发送邮件通知通讯作者成功:'.$sDate."\n",1); } /** * * 格式化信息输出 * * @access public * @return void * @author huangpu * @date 2018.09.28 * @param $[message] [<显示信息>] * @param $[status] [<输出信息1成功,2失败>] */ private function showMessage($message, $status = 1) { if ($status == 1) { echo "[SUCCESS]"; } else { echo "[ERROR]"; } echo date("Y-m-d H:i:s") . " " . $message . "\n"; } }