From 177d1c939f615aff6c2187f85c586df0b204ee9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E9=87=91=E7=A3=8A?= <751475802@qq.com>
Date: Thu, 4 May 2023 13:41:50 +0800
Subject: [PATCH] 1
---
application/api/controller/Article.php | 3 +
application/api/controller/Auto.php | 16 ++
application/api/controller/Base.php | 2 +
application/api/controller/Production.php | 70 +++++--
application/api/controller/User.php | 3 +-
application/api/job/gpt.php | 11 +
application/common.php | 76 +++++++
vendor/aliemail/email.php | 237 ++++++++++++++++++++++
8 files changed, 398 insertions(+), 20 deletions(-)
create mode 100644 vendor/aliemail/email.php
diff --git a/application/api/controller/Article.php b/application/api/controller/Article.php
index e8a940d..de1ba3b 100644
--- a/application/api/controller/Article.php
+++ b/application/api/controller/Article.php
@@ -2159,6 +2159,9 @@ class Article extends Base
// }
+
+
+
/**
* 获取文章通讯作者信息
*/
diff --git a/application/api/controller/Auto.php b/application/api/controller/Auto.php
index ed04fa8..96f1d7e 100644
--- a/application/api/controller/Auto.php
+++ b/application/api/controller/Auto.php
@@ -357,6 +357,22 @@ class Auto extends Base
return jsonSuccess($re);
}
+
+ /**
+ * 推送邮件到作者当文章推送到官网时
+ */
+ public function pushEmailToAuthor(){
+ $data = $this->request->post();
+ $rule = new Validate([
+ ''=>'require'
+ ]);
+ if(!$rule->check($data)){
+ return jsonError($rule->getError());
+ }
+
+
+ }
+
/**
* 获取动态gpt内容
*/
diff --git a/application/api/controller/Base.php b/application/api/controller/Base.php
index 75bda79..69efa01 100644
--- a/application/api/controller/Base.php
+++ b/application/api/controller/Base.php
@@ -62,6 +62,7 @@ class Base extends Controller
protected $production_article_refer_obj = '';
protected $production_article_author_to_organ_obj = '';
protected $production_article_frag_obj = '';
+ protected $production_article_main_obj = '';
protected $apply_reviewer_obj = '';
@@ -124,6 +125,7 @@ class Base extends Controller
$this->production_article_refer_obj = Db::name('production_article_refer');
$this->production_article_author_to_organ_obj = Db::name('production_article_author_to_organ');
$this->production_article_frag_obj = Db::name('production_article_frag');
+ $this->production_article_main_obj = Db::name('production_article_main');
$this->apply_reviewer_obj = Db::name("apply_reviewer");
}
diff --git a/application/api/controller/Production.php b/application/api/controller/Production.php
index c535591..c9c500b 100644
--- a/application/api/controller/Production.php
+++ b/application/api/controller/Production.php
@@ -86,12 +86,24 @@ class Production extends Base
}
$frag['main'][] = $v;
}
+ if(!isset($frag['main'])){
+ return jsonError("manuscript file error!");
+ }
$insert['main'] = isset($frag['main']) ? json_encode($frag['main']) : '';
$insert['article_id'] = $data['article_id'];
$insert['journal_id'] = $article_info['journal_id'];
$insert['ctime'] = time();
- $this->production_article_obj->insert($insert);
+ $p_article_id = $this->production_article_obj->insertGetId($insert);
+
+
+ //将主体内容写入数据库
+ foreach($frag['main'] as $v){
+ $ca['p_article_id'] = $p_article_id;
+ $ca['content'] = $v;
+ $ca['ctime'] = time();
+ $this->production_article_main_obj->insert($ca);
+ }
return jsonSuccess([]);
}
@@ -419,24 +431,6 @@ class Production extends Base
}
}
- /**
- * 校对主入口
- */
- public function proto(){
- $data = $this->request->post();
-
- }
-
-
- public function eeeccc()
- {
- // $str = "Critical Care Medicine 2022;50 (6):955-63";
- // dump($this->bekjournal($str));
- $str = "Pandey S, Kumar P, Niranjan A, Verma H, Kumar M. Targeting biosignatures of hyperglycemia and oxidative stress in diabetes comorbid depressive rats: effectiveness of hydroethanolic extract of the whole plant of Ludwigia octovalvis. Tradit Med Res 2023;8 (2):9.";
- $res = explode('.', $str);
- echo $this->prgeAuthor($res[0]);
- }
-
public function getPdfByHtml(){
$data = $this->request->post();
@@ -1010,6 +1004,42 @@ class Production extends Base
}
}
+ /**
+ * gpt校对main内容
+ */
+ public function freshMain(){
+ $data = $this->request->post();
+ $rule = new Validate([
+ 'p_article_id'=>'require'
+ ]);
+ if(!$rule->check($data)){
+ return jsonError($rule->getError());
+ }
+ $list = $this->production_article_main_obj->where('p_article_id',$data['p_article_id'])->where('state',0)->select();
+ foreach($list as $v){
+ if($v['content']==''||strlen($v['content'])<60){
+ $this->production_article_main_obj->where('p_main_id',$v['p_main_id'])->update(['content_g'=>$v['content']]);
+ }else{
+ Queue::push('app\api\job\gpt@fresh', $v, 'gpt');
+ }
+ }
+
+ return jsonSuccess([]);
+ }
+
+
+
+ public function testref(){
+ // $mes['role'] = "user";
+ // $mes['content'] = "你好啊";
+ // $ckey = md5(rand(1000,9999).time().rand(10000,99999));
+ // GptChar([$mes],$ckey);
+ // echo $ckey;
+ dump(pushGpt("The role of inflammation in MPNs has been increasingly reported in the literature, overproduction of inflammatory cytokines is a clinical feature of patients with MPNs [17-23]. The core proteins screened for inflammation-related RELA, TNF and IL6. IL6 is an important cytosolic inflammatory factor in vivo and the most commonly overexpressed inflammatory factor in myeloid malignancies[24], which promotes STAT3 phosphorylation[25]. Activated IL6/STAT3 signaling can further mediate the production of TNFα, IL1β and other inflammatory factors, continuously enhancing the inflammatory response. TNF mediates the clonal advantage of mutant cells in MPNs[20], and inhibition of TNFR showed a therapeutic effect in mice with MPNs [26]. The above data suggest a central role of inflammation-related factors in MPNs. It suggests that DHI may play a role in treating myeloproliferative neoplasms through multiple targets."));
+ // $production_obj = $this->production_article_main_obj->where('p_main_id',4)->find();
+ // freshContent($production_obj);
+ }
+
/**
* 更新引用条目
*/
@@ -1040,6 +1070,8 @@ class Production extends Base
return jsonSuccess([]);
}
+
+
/**
* 合并到上个文献中
*/
diff --git a/application/api/controller/User.php b/application/api/controller/User.php
index b899169..62c583a 100644
--- a/application/api/controller/User.php
+++ b/application/api/controller/User.php
@@ -873,9 +873,10 @@ class User extends Base
}
$ids = $this->journal_obj->where('editor_id',$data['editor_id'])->column('journal_id');
$list = $this->apply_board_obj
- ->field("t_journal.title,t_apply_board.*,t_user.account,t_user.email,t_user.realname")
+ ->field("t_journal.title,t_apply_board.*,t_user.account,t_user.email,t_user.realname,t_user_reviewer_info.technical")
->join("t_journal",'t_journal.journal_id = t_apply_board.journal_id','left')
->join("t_user","t_user.user_id = t_apply_board.user_id",'left')
+ ->join("t_user_reviewer_info","t_user_reviewer_info.reviewer_id = t_user.user_id","left")
->where('t_apply_board.journal_id','in',$ids)->where('t_apply_board.state',0)->select();
$re['applys'] = $list;
return jsonSuccess($re);
diff --git a/application/api/job/gpt.php b/application/api/job/gpt.php
index 6f871ed..cdeb968 100644
--- a/application/api/job/gpt.php
+++ b/application/api/job/gpt.php
@@ -13,6 +13,12 @@ class gpt {
$job->delete();
}
+ // public function fresh(Job $job, $data){
+ // $this->fre($data);
+ // $job->delete();
+
+ // }
+
/**
* 发送邮件的逻辑
@@ -22,4 +28,9 @@ class gpt {
GptChar($data['message'],$data['ckey']);
}
+
+ // public function fre($data){
+ // freshContent($data);
+ // }
+
}
diff --git a/application/common.php b/application/common.php
index 9f9e837..e146d7d 100644
--- a/application/common.php
+++ b/application/common.php
@@ -322,6 +322,51 @@ function GptChar($message,$ckey)
}
+
+function freshContent($production_obj){
+ $production_article_main_obj = Db::name('production_article_main');
+ $gpt_res =object_to_array(json_decode(pushGpt("请帮我按照学术期刊的校对规则 将以下这段文字进行校对 目标是校对格式 不要改动文本内容 除非确认有拼写或语法错误 ,并且不要去掉这四个标签 直接改在原文:".$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 pushGpt($content){
+ // die;
+ $url = 'https://api.openai.com/v1/edits';
+ $api_key = Env::get("gpt.api_key");
+ $mes['content'] = $content;
+ $data = array(
+ 'model' => 'text-davinci-edit-001',
+ 'input' => $content,
+ 'instruction'=>"改正拼写错误;改正时态错误;改正书写格式错误;"
+ );
+
+ $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
@@ -536,6 +581,37 @@ function getReviewerCvs($reviewer_id){
return $cvs;
}
+function aliemail($email,$title,$content){
+ // file_put_contents('/usr/a.txt', $email,FILE_APPEND);
+ vendor('aliemail.email');
+ $mailto=$email;
+ $mailsubject=$title;
+ //组合邮件公共样式
+ $pre = Env::get('emailtemplete.pre');
+ $net = Env::get('emailtemplete.net');
+ $net1 = str_replace("{{email}}",$email,$net);
+ $mailbody=$pre.$content.$net1;
+ $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;
+}
/**
* 增加usermsg
diff --git a/vendor/aliemail/email.php b/vendor/aliemail/email.php
new file mode 100644
index 0000000..48c612e
--- /dev/null
+++ b/vendor/aliemail/email.php
@@ -0,0 +1,237 @@
+ debug = FALSE;
+ $this->smtp_port = $smtp_port;
+ $this->relay_host = $relay_host;
+ $this->time_out = 30; //is used in fsockopen()
+ $this->auth = $auth;//auth
+ $this->user = $user;
+ $this->pass = $pass;
+ $this->host_name = "localhost"; //is used in HELO command
+ $this->log_file = "";
+ $this->sock = FALSE;
+ }
+
+ /* Main Function */
+ function sendmail($to, $from, $subject, $body, $mailtype, $cc, $bcc, $additional_headers, $fromUser, $replyToAddress)
+ {
+ $mail_from = $this->get_address($this->strip_comment($from));
+ $body = preg_replace("/(^|(\r\n))(\.)/", "\1.\3", $body);
+ $header = "MIME-Version:1.0\r\n";
+ if($mailtype=="HTML"){
+ $header .= "Content-Type:text/html; charset=utf-8\r\n";
+ }
+ $header .= "To: ".$to."\r\n";
+ if ($cc != "") {
+ $header .= "Cc: ".$cc."\r\n";
+ }
+ $header .= "From: $fromUser<".$from.">\r\n";
+ $header .= "Subject: ".$subject."\r\n";
+ $header .= "Reply-To: ".$replyToAddress."\r\n";
+ $header .= $additional_headers;
+ $header .= "Date: ".date("r")."\r\n";
+ $header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
+ list($msec, $sec) = explode(" ", microtime());
+ $header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
+ //若需要开启邮件跟踪服务,请使用以下代码设置跟踪链接头。前置条件和约束见文档"如何开启数据跟踪功能?"
+ //$header .= "Content-Transfer-Encoding: quoted-printable\r\n";
+ //$header .= "X-AliDM-Trace: ". base64_encode(json_encode(['TagName'=>'用户创建的Tag','OpenTrace'=>"1"]))."\r\n";
+ $TO = explode(",", $this->strip_comment($to));
+ if ($cc != "") {
+ $TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
+ }
+ if ($bcc != "") {
+ $TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
+ }
+ $sent = TRUE;
+ foreach ($TO as $rcpt_to) {
+ $rcpt_to = $this->get_address($rcpt_to);
+ if (!$this->smtp_sockopen($rcpt_to)) {
+ $this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
+ $sent = FALSE;
+ continue;
+ }
+ if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
+ $this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
+ } else {
+ $this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
+ $sent = FALSE;
+ }
+ fclose($this->sock);
+ $this->log_write("Disconnected from remote host\n");
+ }
+ return $sent;
+ }
+ /* Private Functions */
+ function smtp_send($helo, $from, $to, $header, $body = "")
+ {
+ if (!$this->smtp_putcmd("HELO", $helo)) {
+ return $this->smtp_error("sending HELO command");
+ }
+ //auth
+ if($this->auth){
+ if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
+ return $this->smtp_error("sending HELO command");
+ }
+ if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
+ return $this->smtp_error("sending HELO command");
+ }
+ }
+ if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {
+ return $this->smtp_error("sending MAIL FROM command");
+ }
+ if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {
+ return $this->smtp_error("sending RCPT TO command");
+ }
+ if (!$this->smtp_putcmd("DATA")) {
+ return $this->smtp_error("sending DATA command");
+ }
+ if (!$this->smtp_message($header, $body)) {
+ return $this->smtp_error("sending message");
+ }
+ if (!$this->smtp_eom()) {
+ return $this->smtp_error("sending . [EOM]");
+ }
+ if (!$this->smtp_putcmd("QUIT")) {
+ return $this->smtp_error("sending QUIT command");
+ }
+ return TRUE;
+ }
+ function smtp_sockopen($address)
+ {
+ if ($this->relay_host == "") {
+ return $this->smtp_sockopen_mx($address);
+ } else {
+ return $this->smtp_sockopen_relay();
+ }
+ }
+ function smtp_sockopen_relay()
+ {
+ $this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
+ $this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
+ if (!($this->sock && $this->smtp_ok())) {
+ $this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
+ $this->log_write("Error: ".$errstr." (".$errno.")\n");
+ return FALSE;
+ }
+ $this->log_write("Connected to relay host ".$this->relay_host."\n");
+ return TRUE;
+ }
+ function smtp_sockopen_mx($address)
+ {
+ $domain = preg_replace("/^.+@([^@]+)$/", "\1", $address);
+ if (!@getmxrr($domain, $MXHOSTS)) {
+ $this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
+ return FALSE;
+ }
+ foreach ($MXHOSTS as $host) {
+ $this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
+ $this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
+ if (!($this->sock && $this->smtp_ok())) {
+ $this->log_write("Warning: Cannot connect to mx host ".$host."\n");
+ $this->log_write("Error: ".$errstr." (".$errno.")\n");
+ continue;
+ }
+ $this->log_write("Connected to mx host ".$host."\n");
+ return TRUE;
+ }
+ $this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
+ return FALSE;
+ }
+ function smtp_message($header, $body)
+ {
+ fputs($this->sock, $header."\r\n".$body);
+ $this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
+ return TRUE;
+ }
+ function smtp_eom()
+ {
+ fputs($this->sock, "\r\n.\r\n");
+ $this->smtp_debug(". [EOM]\n");
+ return $this->smtp_ok();
+ }
+ function smtp_ok()
+ {
+ $response = str_replace("\r\n", "", fgets($this->sock, 512));
+ $this->smtp_debug($response."\n");
+ if (!preg_match("/^[23]/", $response)) {
+ fputs($this->sock, "QUIT\r\n");
+ fgets($this->sock, 512);
+ $this->log_write("Error: Remote host returned \"".$response."\"\n");
+ return FALSE;
+ }
+ return TRUE;
+ }
+ function smtp_putcmd($cmd, $arg = "")
+ {
+ if ($arg != "") {
+ if($cmd=="") $cmd = $arg;
+ else $cmd = $cmd." ".$arg;
+ }
+ fputs($this->sock, $cmd."\r\n");
+ $this->smtp_debug("> ".$cmd."\n");
+ return $this->smtp_ok();
+ }
+ function smtp_error($string)
+ {
+ $this->log_write("Error: Error occurred while ".$string.".\n");
+ return FALSE;
+ }
+ function log_write($message)
+ {
+ $this->smtp_debug($message);
+ if ($this->log_file == "") {
+ return TRUE;
+ }
+ $message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
+ if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
+ $this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
+ return FALSE;
+ }
+ flock($fp, LOCK_EX);
+ fputs($fp, $message);
+ fclose($fp);
+ return TRUE;
+ }
+ function strip_comment($address)
+ {
+ $comment = "/\([^()]*\)/";
+ while (preg_match($comment, $address)) {
+ $address = preg_replace($comment, "", $address);
+ }
+ return $address;
+ }
+ function get_address($address)
+ {
+ $address = preg_replace("/([ \t\r\n])+/", "", $address);
+ $address = preg_replace("/^.*<(.+)>.*$/", "\1", $address);
+ return $address;
+ }
+ function smtp_debug($message)
+ {
+ if ($this->debug) {
+ echo $message;
+ }
+ }
+ }
+ ?>
\ No newline at end of file