Files
tougao/application/common.php
wangjinlei e70f430485 email test
2025-07-14 14:17:33 +08:00

1266 lines
40 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use think\Db;
use think\Env;
use think\Cache;
use PhpOffice\PhpWord\IOFactory;
//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 readExcel($file){
// 读取Excel文件
$objPHPExcel = PHPExcel_IOFactory::load($file);
// 获取表格中的数据
$sheet = $objPHPExcel->getSheet(0); // 获取第一个工作表
$highestRow = $sheet->getHighestRow(); // 取得总行数
$highestColumn = $sheet->getHighestColumn(); // 取得总列数
$dataset = [];
for ($row = 1; $row <= $highestRow; $row++) {
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
array_push($dataset, $rowData[0]);
}
return $dataset;
}
/**
* @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');
$net = str_replace("{{email}}", $memail, $net);
// $mail->msgHTML($pre.$content.$net);
$mail->msgHTML($content);
//Replace the plain text body with one created manually
$mail->AltBody = '';
if (is_array($attachmentFile)) {
for ($i = 0; $i < count($attachmentFile); $i++) {
if ($attachmentFile[$i] != '') {
$mail->addAttachment($attachmentFile[$i], substr($attachmentFile[$i], strrpos($attachmentFile[$i], DS) + 1)); //这里可以是多维数组,然后循环附件的文件和名称
}
}
} 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;
}
function get_str()
{
$length = 32;
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$len = strlen($str) - 1;
$randstr = '';
for ($i = 0; $i < $length; $i++) {
$num = mt_rand(0, $len);
$randstr .= $str[$num];
}
return md5($randstr . time());
}
function getArticleMains($article_id){
$article_mains_obj = Db::name("article_main");
$mains = $article_mains_obj->where("article_id",$article_id)->whereIn("state",[0,2])->order("sort asc")->select();
if(!$mains){
return null;
}
foreach ($mains as $k=>$main) {
if($main['is_h1']==1){
$mains[$k]['content'] = "<b><i>".$main['content']."</i></b>";
}
if($main['is_h2']==1||$main['is_h3']==1){
$mains[$k]['content'] = "<b>".$main['content']."</b>";
}
$mains[$k]['checks'] = Db::name("article_main_check")->where("am_id",$main['am_id'])->where("state",0)->select();
if($main['type']==0){
continue;
}elseif($main['type']==1){
$c_d = Db::name("article_main_image")->where("ami_id",$main['ami_id'])->find();
$mains[$k]['image'] = $c_d;
}else{
$c_d_t = Db::name("article_main_table")->where("amt_id",$main['amt_id'])->find();
$mains[$k]['table'] = $c_d_t;
}
}
return $mains;
}
function getRandPassword()
{
$length = 8;
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$len = strlen($str) - 1;
$randstr = '';
for ($i = 0; $i < $length; $i++) {
$num = mt_rand(0, $len);
$randstr .= $str[$num];
}
return $randstr;
}
function proofState($article_id)
{
$p_article_obj = Db::name('production_article');
$p_article_obj->where('article_id', $article_id)->where('state', '<>', 1)->where('proof_etime', '<', time())->where('proof_state', 1)->update(['proof_state' => 2]);
}
function readWordImg($article_id,$file){
$phpWord = IOFactory::load($file);
// 获取文档中的所有图像
$images = [];
foreach ($phpWord->getSections() as $section) {
foreach ($section->getElements() as $element) {
var_dump(get_class($element)); // 输出每个元素的类名
// 如果是列表项元素,检查其中是否包含图片
if ($element instanceof \PhpOffice\PhpWord\Element\ListItemRun) {
foreach ($element->getElements() as $itemElement) {
if (method_exists($itemElement, 'getImage')) {
$image = $itemElement->getImage();
if ($image) {
$imageContent = $image->getImageString();
$imageName = 'image_' . uniqid() . '.' . $image->getExtension();
file_put_contents(ROOT_PATH.'/public/articleImage/'.$article_id."/" . $imageName, $imageContent);
$images[] = $imageName;
}
}
}
} elseif ($element instanceof \PhpOffice\PhpWord\Element\Table) {
// 检查表格中是否包含图片
foreach ($element->getRows() as $row) {
foreach ($row->getCells() as $cell) {
foreach ($cell->getElements() as $cellElement) {
if (method_exists($cellElement, 'getImage')) {
$image = $cellElement->getImage();
if ($image) {
$imageContent = $image->getImageString();
$imageName = 'image_' . uniqid() . '.' . $image->getExtension();
file_put_contents(ROOT_PATH.'/public/articleImage/'.$article_id."/" . $imageName, $imageContent);
$images[] = $imageName;
}
}
}
}
}
}
// 检查是否是图片元素
elseif (method_exists($element, 'getImage')) {
$image = $element->getImage();
if ($image) {
$imageContent = $image->getImageString();
$imageName = 'image_' . uniqid() . '.' . $image->getExtension();
file_put_contents(ROOT_PATH.'/public/articleImage/'.$article_id."/" . $imageName, $imageContent);
$images[] = $imageName;
}
}
}
}
return $images;
}
/**
* 生成文章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;
case 'PERSP':
$frag = 'PERSPECTIVE';
break;
default:
$frag = 'OTHERS';
break;
}
return $frag;
}
function search_array_val($arr, $val)
{
foreach ($arr as $k => $v) {
if ($v == $val) {
return $k;
}
}
}
function sendMyEmail($email,$title,$content){
$mail = new PHPMailer(true);
try {
// 服务器设置
$mail->isSMTP();
$mail->Host = 'smtp.tmrjournals.com.cn'; // SMTP 服务器
$mail->SMTPAuth = true;
$mail->Username = 'wangjinlei@tmrjournals.com.cn'; // SMTP 用户名
$mail->Password = '123456qwe';
// $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable STARTTLS encryption
// $mail->Port = 587; // TCP port for STARTTLS
// $mail->SMTPDebug = 2; // Enable debugging for detailed output
// $mail->SMTPSecure = ''; // 不使用 SSL 或 TLS
// $mail->Port = 25;
$mail->SMTPSecure = false; // 禁用TLS/SSL加密
$mail->SMTPAutoTLS = false; // 禁用自动TLS加密
$mail->Port = 25; // 非加密的SMTP通常使用端口25
// 收件人设置
$mail->setFrom('wangjinlei@tmrjournals.com.cn', 'tmr');
$mail->addAddress($email, $email); // 添加一个收件人
$mail->addReplyTo('wangjinlei@tmrjournals.com.cn', 'repack');
// 附件(可选)
// $mail->addAttachment('/var/tmp/file.tar.gz');
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg');
// 内容
$mail->isHTML(true); // 设置邮件格式为 HTML
$mail->Subject = $title;
$pre = Env::get('emailtemplete.pre');
$net = Env::get('emailtemplete.net');
$net = str_replace("{{email}}", 'wangjinlei@tmrjournals.com.cn', $net);
$bo = $pre.$content.$net;
$mail->Body = $bo;
$mail->AltBody = $content;
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
function GptChar($message,$ckey)
{
$url = 'https://api.openai.com/v1/chat/completions';
// OpenAI API key
$api_key = Env::get("gpt.api_key");
// Request data
$data = array(
'model' => 'gpt-3.5-turbo',
'messages' => $message,
'temperature' => 0.2,
'max_tokens' => 2048,
'n' => 1,
'stop' => '',
'stream' => true // Use streaming mode
);
// Create request headers
$headers = array(
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
);
// Create context for request
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => json_encode($data),
'ignore_errors' => true
)
));
// Open connection to API endpoint
$fp = fopen($url, 'r', false, $context);
$cache_id = '';
// Read response data
if ($fp) {
while (!feof($fp)) {
$chunk = fgets($fp);
echo $chunk;
$cache = object_to_array(json_decode(substr($chunk,6)));
if(isset($cache['choices'][0]['delta']['content'])){
$cc = Cache::get($ckey)?Cache::get($ckey):'';
Cache::set($ckey,$cc.$cache['choices'][0]['delta']['content'],3600);
}
if(isset($cache['id'])&&$cache['id']!=''){
$cache_id = $cache['id'];
}
// ob_flush();
// flush();
}
fclose($fp);
}
if($cache_id!=''){
Cache::set($ckey."_id",$cache_id);
}
Cache::set($ckey,(Cache::get($ckey)?Cache::get($ckey):'')."[{enddata}]",3600);
}
function freshContent($production_obj){
$production_article_main_obj = Db::name('production_article_main');
$gpt_res =object_to_array(json_decode(pushGpt("请帮我按照学术期刊的校对规则 将以下这段文字进行校对 目标是校对格式 不要改动文本内容 除非确认有拼写或语法错误 ,并且不要去掉<i></i><b></b>这四个标签 直接改在原文:".$production_obj['content']))) ;
$production_article_main_obj->where('p_main_id',$production_obj['p_main_id'])->update(['content_g'=>$gpt_res['choices'][0]['message']['content']]);
$production_article_main_obj->close();
}
function my_array_merge($articles1,$articles2){
$ids = [];
foreach ($articles1 as $v){
$ids[] = $v["article_id"];
}
foreach ($articles2 as $v){
if(!in_array($v["article_id"],$ids)){
$articles1[] = $v;
}
}
return $articles1;
}
function zw_array(array $arr){
sort($arr);
$count = count($arr);
$middle = floor(($count-1)/2);
if($count % 2==0){
$median = ($arr[$middle]+$arr[$middle+1]) / 2;
}else{
$median = $arr[$middle];
}
return $median;
}
function pushGpt($content){
// die;
$url = 'https://api.openai.com/v1/chat/completions';
$api_key = Env::get("gpt.api_key");
// Request data
$mes['role'] = "user";
$mes['content'] = $content;
$data = array(
'model' => 'gpt-3.5-turbo',
'messages' => [$mes],
'temperature' => 0.2,
'max_tokens' => 2048,
'n' => 1,
'stop' => ''
);
$headers = array(
'Content-Type: application/json',
'Authorization: Bearer '.$api_key
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if(curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
/**
* 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); //获取页面各种信息
$err = curl_error($oCurl);
curl_close($oCurl);
if (intval($aStatus["http_code"]) == 200) {
return $sContent;
} else {
return $err;
// return false;
}
}
function formateVol($v){
$flag = "";
if(isset($v['year'])) {
if(is_array($v['year'])){
$flag .= $v['year'][0].", ".$v['year'][1]." ";
}else{
$flag .= $v['year']." ";
}
}
if(isset($v['volume'])) {
$flag .= $v['volume']." ";
}
if(isset($v['first_page'])) {
$flag .= $v['first_page']." ";
}
if(isset($v['item_number'])&&!isset($v['first_page'])) {
$flag .= $v['item_number']." ";
}
if(isset($v['issue'])) {
$flag .= $v['issue']." ";
}
return trim($flag);
}
function formateAuthor($list){
$flag = '';
if($list==null){
return $flag;
}
if(isset($list['given_name'])||isset($list['surname'])){
$flag = $list['given_name']." ".$list['surname'];
}
else if (count($list)<=3){
foreach ($list as $v){
$flag .= $v['given_name']." ".$v['surname'].", ";
}
$flag = trim(trim($flag),",");
}else{
for ($i=0;$i<3;$i++){
$flag .= $list[$i]['given_name']." ".$list[$i]['surname'].", ";
}
$flag .= "et al";
}
return $flag;
}
function xml_to_array($xml)
{
$reg = "/<(\\w+)[^>]*?>([\\x00-\\xFF]*?)<\\/\\1>/";
if(preg_match_all($reg, $xml, $matches))
{
$count = count($matches[0]);
$arr = array();
for($i = 0; $i < $count; $i++)
{
$key = $matches[1][$i];
$val = xml_to_array( $matches[2][$i] ); // 递归
if(array_key_exists($key, $arr))
{
if(is_array($arr[$key]))
{
if(!array_key_exists(0,$arr[$key]))
{
$arr[$key] = array($arr[$key]);
}
}else{
$arr[$key] = array($arr[$key]);
}
$arr[$key][] = $val;
}else{
$arr[$key] = $val;
}
}
return $arr;
}else{
return $xml;
}
}
function myGetParam($url,$params)
{
$query_string = http_build_query($params);
$full_url = $url . '?' . $query_string;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $full_url); // 设置请求URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 设置返回数据而不是直接输出
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 禁用SSL验证
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $response;
}
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->getConnection()->close();
}
function my_doiToFrag1($data)
{
$p_refer_obj = Db::name('production_article_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";
$url = "https://citation.crosscite.org/format?doi=$doi&style=cancer-translational-medicine&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);
$f = $c_frag . " Available at: " . PHP_EOL . "http://doi.org/" . $data['refer_doi'];
$cs = 1;
}
$p_refer_obj->where('p_refer_id', $data['p_refer_id'])->update(['refer_frag' => $f, "cs" => $cs]);
$p_refer_obj->getConnection()->close();
}
/**
* 增加用户积分log信息
*/
function addUserScoreLog($user_id, $score, $content, $ctime, $act = '+')
{
$score_obj = Db::name('user_score_log');
$insert['user_id'] = $user_id;
$insert['content'] = trim($content);
$insert['score'] = $score;
$insert['act'] = $act;
$insert['ctime'] = $ctime;
$score_obj->insert($insert);
}
function getPaystationToken()
{
$client_id = $_ENV['CLIENT_ID'];
$client_secret = $_ENV['CLIENT_SECRET'];
$access_token_url = $_ENV['API_URL'] . '/oauth/token';
$guzzle = new Client(['base_uri' => $access_token_url]);
try {
$raw_response = $guzzle->post('', [
'headers' => ['Content-type' => 'application/json'],
'body' => json_encode([
'client_id' => $client_id,
'client_secret' => $client_secret,
'grant_type' => 'client_credentials',
'scope' => 'write'
]),
]);
$response = $raw_response->getBody()->getContents();
if ($response) {
$response_decoded = json_decode($response);
if ($response_decoded && isset($response_decoded->access_token)) {
return $response_decoded->access_token;
}
return null;
}
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
//@todo: Replace with your own error handling
return null;
}
return null;
}
function my_doiToFrag2($data)
{
$p_refer_obj = Db::name('production_article_refer');
if ($data['refer_doi'] == ''||$data['state']==1) {
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";
// $url = "https://citation.crosscite.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";
$url = "https://citation.doi.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";
$res = myGet($url);
$frag = trim(substr($res, strpos($res, '.') + 1));
$update = [];
if ($frag == "") {
$update['refer_frag'] = $data['refer_content'];
$update['refer_type'] = "other";
} else {
// preg_match("/[0-9]{4}/",$frag,$math);
// $year = $math[0];
// $qbj=trim(substr($frag,0,stripos($frag,$year))) ;
if (mb_substr_count($frag, '.') != 3) {
$f = $frag . " Available at: " . PHP_EOL . "https://doi.org/" . $data['refer_doi'];
$update['refer_type'] = "other";
$update['refer_frag'] = $f;
$update['cs'] = 1;
} else {
$res = explode('.', $frag);
$update['author'] = prgeAuthor($res[0]);
$update['title'] = trim($res[1]);
$bj = bekjournal($res[2]);
$joura = formateJournal(trim($bj[0]));
$update['joura'] = $joura;
$is_js = 0;
if ($joura == trim($bj[0])) {
}
$update['refer_type'] = "journal";
$update['is_ja'] = $joura == trim($bj[0]) ? 0 : 1;
$update['dateno'] = str_replace(' ', '', str_replace('-', '', trim($bj[1])));
$update['doilink'] = strpos($data['refer_doi'],"http")===false?"https://doi.org/" . $data['refer_doi']:$data['refer_doi'];
$update['cs'] = 1;
}
}
$p_refer_obj->where('p_refer_id', $data['p_refer_id'])->update($update);
$p_refer_obj->getConnection()->close();
return $res;
}
function bekjournal($str)
{
preg_match("/[0-9]{4}/", $str, $math);
$year = $math[0];
$frag[0] = trim(substr($str, 0, stripos($str, $year)));
$frag[1] = substr($str, stripos($str, $year));
return $frag;
}
function formateJournal($fullname)
{
$obj = Db::name('journal_abbr');
$r = $obj->where('full_name', $fullname)->find();
if ($r) {
return $r['little_name'];
} else {
return $fullname;
}
}
function prgeAuthor($author)
{
$a = explode(',', $author);
if (count($a) < 7) {
return $author . '.';
} else {
return trim($a[0]) . ', ' . trim($a[1]) . ', ' . trim($a[2]) . ', et al.';
}
}
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();
// }
}
function getMajorStr($major_id)
{
$major_obj = Db::name('major');
$frag = '';
$major_info = $major_obj->where('major_id', $major_id)->find();
if ($major_info == null) {
return '';
}
if ($major_info['major_level'] == 1) {
return 'Medicine';
} else {
$frag = getMajorStr($major_info['pid']) . ' > ' . $major_info['major_title'];
}
return $frag;
}
function getMajorShu($major)
{
$major_obj = Db::name('major');
if ($major == 0) {
return;
}
$res = $major_obj->where('major_id', $major)->find();
if ($res['pid'] == 1) {
return $res['major_id'];
}
$p = getMajorShu($res['pid']);
return $p . ',' . $res['major_id'];
}
function changeArticleMajor($article_id,$majors){
$ms = explode(",",$majors);
$major_to_article_obj = Db::name("major_to_article");
foreach ($ms as $v){
$check = $major_to_article_obj->where("article_id",$article_id)->where("major_id",$v)->where("state",0)->find();
if(!$check){
$insert['article_id'] = $article_id;
$insert['major_id'] = $v;
$insert['ctime'] = time();
$major_to_article_obj->insert($insert);
}
}
$has = $major_to_article_obj->where("article_id",$article_id)->where("state",0)->select();
foreach ($has as $v){
if(!in_array($v['major_id'],$ms)){
$major_to_article_obj->where("mta_id",$v['mta_id'])->update(['state'=>1]);
}
}
}
function getReviewerCvs($reviewer_id){
$cvs = Db::name('user_cv')->where('user_id',$reviewer_id)->where('state',0)->select();
return $cvs;
}
function aliemail($email,$title,$content,$has_hb=1){
vendor('aliemail.email');
$mailto=$email;
$mailsubject=$title;
//组合邮件公共样式
$pre = Env::get('emailtemplete.pre');
$net = Env::get('emailtemplete.net');
$net1 = str_replace("{{email}}",$email,$net);
$mailbody=$has_hb==1?$pre.$content.$net1:$content;
$smtpserver = "smtpdm-ap-southeast-1.aliyun.com";
$smtpserverport = 80;
$smtpusermail = "propa@hellotmr.top";
// 发件人的账号,填写控制台配置的发信地址,比如xxx@xxx.com
$smtpuser = "propa@hellotmr.top";
// 访问SMTP服务时需要提供的密码(在控制台选择发信地址进行设置)
$smtppass = "Wu751019Pnx";
$mailsubject = "=?UTF-8?B?" . base64_encode($mailsubject) . "?=";
$mailtype = "HTML";
//可选,设置回信地址
$smtpreplyto = "tmr@tmrjournals.com";
$smtp = new \smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass);
$smtp->debug = false;
$cc ="";
$bcc = "";
$additional_headers = "";
//设置发件人名称,名称用户可以自定义填写。
$sender = $title;
$res = $smtp->sendmail($mailto,$smtpusermail, $mailsubject, $mailbody, $mailtype, $cc, $bcc, $additional_headers, $sender, $smtpreplyto);
return $res;
}
function paystationLookup($transactionId){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.paystation.co.nz/v1/transactions/'.$transactionId,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer '.createPayStationToken()
)
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
function createPayStationToken(){
$bodyParams = [
'client_id' => Env::get("paystation.client_id"),
'client_secret' => Env::get("paystation.client_secret"),
'grant_type' => 'client_credentials',
'scope' => "read write"
];
$accessTokenUrl = Env::get("paystation.api_url") . '/oauth/token';
$curlHandle = curl_init($accessTokenUrl);
$options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => [
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"accept: *",
"accept-encoding: gzip, deflate",
'Host: api.paystation.co.nz',
],
CURLOPT_POSTFIELDS => http_build_query($bodyParams)
];
curl_setopt_array($curlHandle, $options);
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
$curlResponse = curl_exec($curlHandle);
$error = curl_error($curlHandle);
curl_close($curlHandle);
if ($error) {
echo "cURL error: " . $error;
} else {
$response = json_decode($curlResponse);
if (array_key_exists('access_token', $response)) {
return $response->access_token;
}
if (array_key_exists('error', $response)) {
echo $response->error_description;
}
}
}
/**资金汇率
* @return void
*/
function prin($usd){
$res = myGet("https://v6.exchangerate-api.com/v6/575c78ea6173243d6c366814/latest/USD");
$re = object_to_array(json_decode($res));
return $usd*$re["conversion_rates"]['NZD'];
}
function postPayStationQuery($endpoint, $token, $body){
$curlHandle = curl_init(Env::get("paystation.api_url") . '/' . $endpoint);
$options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_HTTPHEADER => [
"cache-control: no-cache",
"content-type: application/json",
"accept: *",
"accept-encoding: gzip, deflate",
"Authorization: Bearer " . $token
],
CURLOPT_POSTFIELDS => $body
];
curl_setopt_array($curlHandle, $options);
$response = curl_exec($curlHandle);
$error = curl_error($curlHandle);
curl_close($curlHandle);
if ($error) {
echo "cURL error: " . $error;
} else {
return $response ?: null;
}
return null;
}
/**
* 增加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_SSL_VERIFYPEER, false);
// 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;
}
/**
* @title 文章类型接口
* @description 文章接口
*/
function getArticleType(){
$aArticleType = [
'base' => [
['name' => 'ARTICLE','value' => 'A'],
['name' => 'REVIEW','value' => 'B'],
['name' => 'CASE REPORT','value' => 'C'],
['name' => 'RESEARCH PROPOSAL','value' => 'P'],
['name' => 'NEWS','value' => 'N'],
['name' => 'COMMENT','value' => 'T'],
['name' => 'CORRECTION','value' => 'CT'],
['name' => 'HYPOTHESIS','value' => 'HT'],
['name' => 'PREFACE','value' => 'PF'],
['name' => 'EDITORIAL','value' => 'ET'],
['name' => 'REPORT','value' => 'RP'],
['name' => 'LETTER','value' => 'LR'],
['name' => 'EMPIRICAL FORMULA','value' => 'EF'],
['name' => 'EXPERT CONSENSUS','value' => 'EC'],
['name' => 'LETTER TO EDITOR','value' => 'LTE'],
['name' => 'QUESTIONNAIRE INVESTIGATION','value' => 'QI'],
['name' => 'CASE SERIES','value' => 'CS'],
['name' => 'RETRACTION','value' => 'RT'],
['name' => 'MINI REVIEW','value' => 'MR'],
// ['name' => 'PERSPECTIVE','value' => 'PERSP'],
['name' => 'OTHERS','value' => 'O']
],
'supplement' => [
['name' => 'EVIDENCE-BASED MEDICINE','value' => 'EM'],
['name' => 'PROTOCOL','value' => 'PT'],
]
];
return $aArticleType;
}
/**
* @title 医疗类型接口
* @description 文章接口
*/
function getMedicalType(){
$aMedicalType = [
['label' => 'None','value' => ''],
['label' => 'ARTICLE','value' => 'Article'],
['label' => 'REVIEW','value' => 'Review'],
['label' => 'CASE REPORT','value' => 'Case report'],
['label' => 'RESEARCH PROPOSAL','value' => 'Research proposal'],
['label' => 'NEWS','value' => 'News'],
['label' => 'COMMENT','value' => 'Comment'],
['label' => 'CORRECTION','value' => 'Correction'],
['label' => 'HYPOTHESIS','value' => 'Hypothesis'],
['label' => 'PREFACE','value' => 'Preface'],
['label' => 'EDITORIAL','value' => 'Editorial'],
['label' => 'REPORT','value' => 'Report'],
['label' => 'LETTER','value' => 'Letter'],
['label' => 'EMPIRICAL FORMULA','value' => 'Empirical formula'],
['label' => 'EVIDENCE-BASED MEDICINE','value' => 'Evidence-based medicine'],
['label' => 'EXPERT CONSENSUS','value' => 'Expert consensus'],
['label' => 'LETTER TO EDITOR','value' => 'Letter to editor'],
['label' => 'QUESTIONNAIRE INVESTIGATION','value' => 'Questionnaire investigation'],
['label' => 'PROTOCOL','value' => 'Protocol'],
['label' => 'CASE SERIES','value' => 'Case Series'],
['label' => 'RETRACTION','value' => 'Retraction'],
['label' => 'MINI REVIEW','value' => 'Mini Review'],
['label' => 'PERSPECTIVE','value' => 'Perspective'],
['label' => '内经难经','value' => '内经难经'],
['label' => '伤寒金匮','value' => '伤寒金匮'],
['label' => '神农本草经','value' => '神农本草经'],
['label' => '温病研究','value' => '温病研究'],
['label' => '唐宋方药','value' => '唐宋方药'],
['label' => '金元各家','value' => '金元各家'],
['label' => '明清经典','value' => '明清经典'],
['label' => '中西汇通','value' => '中西汇通'],
['label' => '太湖选粹','value' => '太湖选粹'],
['label' => '针灸推拿','value' => '针灸推拿'],
['label' => '名医名方','value' => '名医名方'],
['label' => '新冠肺炎','value' => '新冠肺炎'],
['label' => '书评','value' => '书评']
];
return $aMedicalType;
}