389 lines
11 KiB
PHP
389 lines
11 KiB
PHP
<?php
|
||
|
||
use PHPMailer\PHPMailer\PHPMailer;
|
||
use think\Db;
|
||
use think\Env;
|
||
|
||
//use TCPDF;
|
||
// +----------------------------------------------------------------------
|
||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||
// +----------------------------------------------------------------------
|
||
// | Author: 流年 <liu21st@gmail.com>
|
||
// +----------------------------------------------------------------------
|
||
// 应用公共文件
|
||
function authcode($str) {
|
||
$key = substr(md5('ThinkPHP.CN'), 5, 8);
|
||
$str1 = substr(md5($str), 8, 10);
|
||
return md5($key . $str1);
|
||
}
|
||
|
||
/**
|
||
* @function sendEmail
|
||
* @intro 发送邮件(带附件)
|
||
* @param $email 接收邮箱
|
||
* @param $title 邮件标题
|
||
* @param $from_name 发件人
|
||
* @param $content 邮件内容
|
||
* @param $memail 邮件内容
|
||
* @param $mpassword 邮件内容
|
||
* @param $attachmentFile 附件 (string | array)
|
||
* @return array
|
||
*/
|
||
function sendEmail($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') {
|
||
date_default_timezone_set('PRC');
|
||
//Create a new PHPMailer instance
|
||
$mail = new PHPMailer;
|
||
//Tell PHPMailer to use SMTP
|
||
$mail->isSMTP();
|
||
//Enable SMTP debugging
|
||
// 0 = off (for production use)
|
||
// 1 = client messages
|
||
// 2 = client and server messages
|
||
$mail->SMTPDebug = 0;
|
||
//Ask for HTML-friendly debug output
|
||
$mail->Debugoutput = 'html';
|
||
//charset
|
||
$mail->CharSet = 'UTF-8';
|
||
//Set the hostname of the mail server
|
||
$mail->Host = "smtp.qiye.aliyun.com"; //请填写你的邮箱服务器
|
||
//Set the SMTP port number - likely to be 25, 465 or 587
|
||
$mail->Port = 25; //端口号
|
||
//Whether to use SMTP authentication
|
||
$mail->SMTPAuth = true;
|
||
//Username to use for SMTP authentication
|
||
$mail->Username = $memail == '' ? "tmrweb@tmrjournals.com" : $memail; //发件邮箱用户名
|
||
//Password to use for SMTP authentication
|
||
$mail->Password = $mpassword == '' ? "Wu999999tmrwe" : $mpassword; //发件邮箱密码
|
||
//Set who the message is to be sent from
|
||
$mail->setFrom($memail == '' ? "tmrweb@tmrjournals.com" : $memail, $from_name);
|
||
//Set an alternative reply-to address(用户直接回复邮件的地址)
|
||
$mail->addReplyTo($memail == '' ? "tmrweb@tmrjournals.com" : $memail, $from_name);
|
||
//Set who the message is to be sent to
|
||
$mail->addAddress($email);
|
||
//Set the subject line
|
||
$mail->Subject = $title;
|
||
//Read an HTML message body from an external file, convert referenced images to embedded,
|
||
//convert HTML into a basic plain-text alternative body
|
||
|
||
//组合邮件模板的头尾
|
||
$pre = Env::get('emailtemplete.pre');
|
||
$net = Env::get('emailtemplete.net');
|
||
|
||
$mail->msgHTML($pre.$content.$net);
|
||
//Replace the plain text body with one created manually
|
||
$mail->AltBody = '';
|
||
// if (is_array($attachmentFile)) {
|
||
// for ($i = 0; $i < count($attachmentFile); $i++) {
|
||
// $mail->addAttachment($attachmentFile[$i], 'thanks' . $i.'.jpg'); //这里可以是多维数组,然后循环附件的文件和名称
|
||
// }
|
||
// } else {
|
||
if ($attachmentFile != '') {
|
||
//Attach an image file
|
||
$mail->addAttachment($attachmentFile, substr($attachmentFile,strrpos($attachmentFile,DS)+1));
|
||
}
|
||
// }
|
||
//send the message, check for errors
|
||
if (!$mail->send()) {
|
||
$status = 0;
|
||
$data = "邮件发送失败" . $mail->ErrorInfo;
|
||
;
|
||
} else {
|
||
$status = 1;
|
||
$data = "邮件发送成功";
|
||
}
|
||
return ['status' => $status, 'data' => $data]; //返回值(可选)
|
||
}
|
||
|
||
function object_to_array($obj) {
|
||
$obj = (array) $obj;
|
||
foreach ($obj as $k => $v) {
|
||
if (gettype($v) == 'resource') {
|
||
return;
|
||
}
|
||
if (gettype($v) == 'object' || gettype($v) == 'array') {
|
||
$obj[$k] = (array) object_to_array($v);
|
||
}
|
||
}
|
||
return $obj;
|
||
}
|
||
|
||
/**
|
||
* 生成文章sn号
|
||
* @return type
|
||
*/
|
||
function getArticleSN($abbr, $type) {
|
||
$str = $abbr;
|
||
$str .= date('Y', time()) . $type . date('md', time());
|
||
$where['accept_sn'] = ['like', "$str%"];
|
||
$nowres = Db::name('article')->where($where)->select();
|
||
$last_num = 1;
|
||
if ($nowres) {
|
||
foreach ($nowres as $v) {
|
||
$now_num = intval(substr($v['accept_sn'], -3));
|
||
$last_num = $now_num > $last_num ? $now_num : $last_num;
|
||
}
|
||
$last_num += 1;
|
||
}
|
||
$last_str = sprintf("%03d", $last_num);
|
||
$str .= $last_str;
|
||
return $str;
|
||
}
|
||
|
||
function translateType($type) {
|
||
$frag = '';
|
||
switch ($type) {
|
||
case "A":
|
||
$frag = 'ARTICLE';
|
||
break;
|
||
case 'B':
|
||
$frag = 'REVIEW';
|
||
break;
|
||
case 'C':
|
||
$frag = 'CASE REPORT';
|
||
break;
|
||
case 'P':
|
||
$frag = 'RESEARCH PROPOSAL';
|
||
break;
|
||
case 'N':
|
||
$frag = 'NEWS';
|
||
break;
|
||
case 'T':
|
||
$frag = 'COMMENT';
|
||
break;
|
||
case 'CT':
|
||
$frag = 'CORRECTION';
|
||
break;
|
||
case 'HT':
|
||
$frag = 'HYPOTHESIS';
|
||
break;
|
||
case 'PF':
|
||
$frag = 'PREFACE';
|
||
break;
|
||
case 'ET':
|
||
$frag = 'EDITORIAL';
|
||
break;
|
||
case 'RP':
|
||
$frag = 'REPORT';
|
||
break;
|
||
case 'LR':
|
||
$frag = 'LETTER';
|
||
break;
|
||
case 'EF':
|
||
$frag = 'EMPIRICAL FORMULA';
|
||
break;
|
||
case 'EM':
|
||
$frag = 'EVIDENCE-BASED MEDICINE';
|
||
break;
|
||
case 'EC':
|
||
$frag = 'EXPERT CONSENSUS';
|
||
break;
|
||
case 'LTE':
|
||
$frag = 'LETTER TO EDITOR';
|
||
break;
|
||
case 'QI':
|
||
$frag = 'QUESTIONNAIRE INVESTIGATION';
|
||
break;
|
||
case 'PT':
|
||
$frag = 'PROTOCOL';
|
||
break;
|
||
case 'CS':
|
||
$frag = 'CASE SERIES';
|
||
break;
|
||
case 'RT':
|
||
$frag = 'RETRACTION';
|
||
break;
|
||
case 'MR':
|
||
$frag = 'MINI REVIEW';
|
||
break;
|
||
default:
|
||
$frag = 'OTHERS';
|
||
break;
|
||
}
|
||
return $frag;
|
||
}
|
||
|
||
function search_array_val($arr,$val){
|
||
foreach($arr as $k => $v){
|
||
if($v == $val){
|
||
return $k;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* GET 请求
|
||
* @param string $url
|
||
*/
|
||
function myGet($url){
|
||
$oCurl = curl_init();
|
||
if(stripos($url,"https://")!==FALSE){
|
||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
|
||
}
|
||
curl_setopt($oCurl, CURLOPT_URL, $url);//目标URL
|
||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );//设定是否显示头信息,1为显示
|
||
curl_setopt($oCurl, CURLOPT_BINARYTRANSFER, true) ;//在启用CURLOPT_RETURNTRANSFER时候将获取数据返回
|
||
$sContent = curl_exec($oCurl);
|
||
$aStatus = curl_getinfo($oCurl);//获取页面各种信息
|
||
curl_close($oCurl);
|
||
if(intval($aStatus["http_code"])==200){
|
||
return $sContent;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function my_doiToFrag($data){
|
||
$ts_refer_obj = Db::name('ts_refer');
|
||
if($data['refer_doi']==''){
|
||
return 0;
|
||
}
|
||
$doi = str_replace('/','%2F',$data['refer_doi']);
|
||
$url = "https://citation.crosscite.org/format?doi=$doi&style=american-veterinary-medical-association&lang=en-US";
|
||
$res = myGet($url);
|
||
$frag = trim(substr($res,strpos($res,'.')+1));
|
||
$f = '';
|
||
$cs = 0;
|
||
if($frag==""){
|
||
$f = $data['refer_content'];
|
||
}else{
|
||
$c_frag = rtrim($frag,'.');
|
||
$f = substr_replace($c_frag,PHP_EOL,strripos($c_frag,"http"),0);
|
||
$cs = 1;
|
||
}
|
||
$ts_refer_obj->where('ts_refer_id',$data['ts_refer_id'])->update(['refer_frag'=>$f,"cs"=>$cs]);
|
||
$ts_refer_obj->close();
|
||
}
|
||
|
||
|
||
function my_tg_pushmail($data){
|
||
$res = sendEmail($data['email'],$data['title'],$data['title'],$data['content'],$data['tmail'],$data['tpassword'],$data['attachmentFile']);
|
||
if(isset($res['status'])){
|
||
$log_obj = Db::name('email_log');
|
||
$insert['article_id'] = $data['article_id'];
|
||
$insert['email'] = $data['email'];
|
||
$insert['content'] = $data['content'];
|
||
$insert['is_success'] = $res['status'];
|
||
$insert['attachment'] = $data['attachmentFile']!=''?substr($data['attachmentFile'],strrpos($data['attachmentFile'],'enclosure/')+10):'';
|
||
$insert['ctime'] = time();
|
||
$log_obj->insert($insert);
|
||
$log_obj->close();
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 增加usermsg
|
||
*/
|
||
function add_usermsg($userid, $content, $url) {
|
||
$msg_obj = Db::name('user_msg');
|
||
$msg_info = $msg_obj->where('user_id', $userid)
|
||
->where('url', $url)
|
||
->where('state', 0)
|
||
->find();
|
||
if ($msg_info) {
|
||
return true;
|
||
}
|
||
$msgdata['user_id'] = $userid;
|
||
$msgdata['content'] = $content;
|
||
$msgdata['url'] = $url;
|
||
$msgdata['ctime'] = time();
|
||
return $msg_obj->insert($msgdata);
|
||
}
|
||
|
||
function jsonSuccess($data) {
|
||
return json(['code' => 0, 'msg' => 'success', 'data' => $data]);
|
||
}
|
||
|
||
function jsonError($msg) {
|
||
return json(['code' => 1, 'msg' => $msg]);
|
||
}
|
||
|
||
function choiseJabbr($article_id, $jabbr) {
|
||
if ($article_id < 1799 && $jabbr == "Cancer Adv") {
|
||
return "TMR Cancer";
|
||
}
|
||
if ($article_id < 910 && $jabbr == "Microenviron Microecol Res") {
|
||
return "Tumor Microenviron Res";
|
||
}
|
||
if ($article_id < 1799 && $jabbr == "Med Theor Hypothesis") {
|
||
return "TMR Theory Hypoth";
|
||
}
|
||
return $jabbr;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
function myPost($url, $param = array()) {
|
||
|
||
if (!is_array($param)) {
|
||
|
||
throw new Exception("参数必须为array");
|
||
}
|
||
|
||
$httph = curl_init($url);
|
||
|
||
// curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0);
|
||
// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1);
|
||
|
||
curl_setopt($httph, CURLOPT_RETURNTRANSFER, 1);
|
||
|
||
curl_setopt($httph, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
|
||
|
||
curl_setopt($httph, CURLOPT_POST, 1); //设置为POST方式
|
||
|
||
curl_setopt($httph, CURLOPT_POSTFIELDS, $param);
|
||
|
||
// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0);
|
||
// curl_setopt($httph, CURLOPT_HEADER,1);
|
||
|
||
$rst = curl_exec($httph);
|
||
|
||
curl_close($httph);
|
||
|
||
return $rst;
|
||
}
|
||
|
||
function myPost1($url, $param = array()) {
|
||
|
||
if (!is_array($param)) {
|
||
|
||
throw new Exception("参数必须为array");
|
||
}
|
||
$data = json_encode($param);
|
||
|
||
$httph = curl_init($url);
|
||
curl_setopt($httph, CURLOPT_HTTPHEADER, array(
|
||
'Content-Type: application/json',
|
||
));
|
||
|
||
// curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0);
|
||
// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1);
|
||
|
||
curl_setopt($httph, CURLOPT_RETURNTRANSFER, 1);
|
||
|
||
curl_setopt($httph, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
|
||
|
||
curl_setopt($httph, CURLOPT_POST, 1); //设置为POST方式
|
||
|
||
curl_setopt($httph, CURLOPT_POSTFIELDS, $data);
|
||
|
||
// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0);
|
||
// curl_setopt($httph, CURLOPT_HEADER,1);
|
||
|
||
$rst = curl_exec($httph);
|
||
|
||
curl_close($httph);
|
||
|
||
return $rst;
|
||
}
|