From 8bf6b7b6c775fe106c890ebc9d7b4237cde5ba6c Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Tue, 23 Jul 2024 15:40:55 +0800 Subject: [PATCH] 1 --- application/api/controller/Article.php | 52 ++--- application/common.php | 305 +++++++++++++++---------- 2 files changed, 206 insertions(+), 151 deletions(-) diff --git a/application/api/controller/Article.php b/application/api/controller/Article.php index 57f417d..e2b4cad 100644 --- a/application/api/controller/Article.php +++ b/application/api/controller/Article.php @@ -44,6 +44,17 @@ class Article extends Controller { $this->article_main_obj = Db::name('article_main'); } + + public function mmmttt(){ + $data = $this->request->post(); + $get_url = "https://doi.crossref.org/servlet/getForwardLinks"; + $get_data["usr"] = "books@tmrjournals.com/tmrp"; + $get_data["pwd"] = "849192806pnX"; + $get_data["doi"] = $data["doi"]; + $r = xml_to_array(myGet($get_url,$get_data)); + return jsonSuccess($r); + } + /** * @title 获取文章详情 * @description 获取文章详情 @@ -88,39 +99,11 @@ class Article extends Controller { } else { $cite = $article_info['abbr'] . '. ' . $article_info['title'] . '. ' . choiseJabbr($article_info['article_id'], $journal_info['jabbr']) . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $article_info['npp'] . '. doi:' . $article_info['doi']; } - -// //获取html -// if($article_info['file_html']==''){ -// $caches = $this->article_main_obj->where('article_id',$article_info['article_id'])->where('state',0)->select(); -// if($caches){ -// $article_info['file_html'] = $caches; -// } -// } - if (stripos($article_info['npp'], '-')) { $cc = explode('-', $article_info['npp']); $article_info['first_page'] = $cc[0]; $article_info['last_page'] = $cc[1]; } - - //添加orDoi - // if($article_info['journal_id']==1&&$article_info['article_id']<1540){ - // $article_info['ordoi'] = str_replace("10.53388", "10.12032", $article_info['doi']); - // }elseif($article_info['journal_id']==14&&$article_info['article_id']<1540){ - // $article_info['ordoi'] = str_replace("10.53388", "10.12032", $article_info['doi']); - // }elseif($article_info['journal_id']==17&&$article_info['article_id']>=735&&$article_info['article_id']<=1534){ - // $article_info['ordoi'] = str_replace("10.53388", "10.12032", $article_info['doi']); - // }elseif($article_info['journal_id']==8&&$article_info['article_id']>=591&&$article_info['article_id']<=1535){ - // $article_info['ordoi'] = str_replace("10.53388", "10.12032", $article_info['doi']); - // }elseif($article_info['journal_id']==13&&$article_info['article_id']>=256&&$article_info['article_id']<=1486){ - // $article_info['ordoi'] = str_replace("10.53388", "10.12032", $article_info['doi']); - // }elseif($article_info['journal_id']==4&&$article_info['article_id']>=872&&$article_info['article_id']<=1508){ - // $article_info['ordoi'] = str_replace("10.53388", "10.12032", $article_info['doi']); - // }elseif($article_info['journal_id']==24&&($article_info['journal_stage_id']==242||$article_info['journal_stage_id']==251)){ - // $article_info['ordoi'] = str_replace("10.53388", "10.12032", $article_info['doi']); - // }else{ - // $article_info['ordoi'] = ''; - // } if($article_info['journal_id']==1&&$article_info['article_id']<1540){ $article_info['ordoi'] = str_replace("10.53388", "10.12032", $article_info['doi']); }elseif($article_info['journal_id']==14&&$article_info['article_id']<1540){ @@ -138,15 +121,18 @@ class Article extends Controller { }else{ $article_info['ordoi'] = ''; } - - $article_info['publication'] = date('Y/m/d', strtotime($article_info['pub_date'])); - //修改keywords $article_info['keywords'] = str_replace(',', '    ', $article_info['keywords']); - //更改适应期刊改名后的期刊名称 $journal_info['title'] = choiseti1($article_info['article_id'],$journal_info['title']); + //获取文章引用信息 + $get_url = "https://doi.crossref.org/servlet/getForwardLinks"; + $get_data["usr"] = "books@tmrjournals.com/tmrp"; + $get_data["pwd"] = "849192806pnX"; + $get_data["doi"] = $article_info['doi']; + $r = xml_to_array(myGet($get_url,$get_data)); + $re['crossref_cite'] = isset($r['crossref_result']['query_result']["body"]['forward_link'])?$r['crossref_result']['query_result']["body"]['forward_link']:null; //返回数据 $re['articleInfo'] = $article_info; $re['journalInfo'] = $journal_info; @@ -167,8 +153,8 @@ class Article extends Controller { }else{ $stack = []; } - $re["track"] = $stack; + return jsonSuccess($re); } diff --git a/application/common.php b/application/common.php index 85ce859..5a36646 100644 --- a/application/common.php +++ b/application/common.php @@ -3,6 +3,7 @@ use PHPMailer\PHPMailer\PHPMailer; use think\Db; use think\Env; + //use TCPDF; // +---------------------------------------------------------------------- @@ -15,7 +16,8 @@ use think\Env; // | Author: 流年 // +---------------------------------------------------------------------- // 应用公共文件 -function authcode($str) { +function authcode($str) +{ $key = substr(md5('ThinkPHP.CN'), 5, 8); $str1 = substr(md5($str), 8, 10); return md5($key . $str1); @@ -27,7 +29,8 @@ function authcode($str) { * @param object $obj 对象 * @return array */ -function object_to_array($obj) { +function object_to_array($obj) +{ $obj = (array)$obj; foreach ($obj as $k => $v) { if (gettype($v) == 'resource') { @@ -40,63 +43,65 @@ function object_to_array($obj) { return $obj; } -function choiseJabbr($article_id,$jabbr){ - if($article_id<1799&&$jabbr=="Cancer Adv"){ +function choiseJabbr($article_id, $jabbr) +{ + if ($article_id < 1799 && $jabbr == "Cancer Adv") { return "TMR Cancer"; } - if($article_id<910&&$jabbr=="Microenviron Microecol Res"){ + if ($article_id < 910 && $jabbr == "Microenviron Microecol Res") { return "Tumor Microenviron Res"; } - if($article_id<1799&&$jabbr=="Med Theor Hypothesis"){ + if ($article_id < 1799 && $jabbr == "Med Theor Hypothesis") { return "TMR Theory Hypoth"; } - if($article_id<1821&&$jabbr=="Clin Res Commun"){ + if ($article_id < 1821 && $jabbr == "Clin Res Commun") { return "TMR Clin Res"; } - if($article_id<1665&&$jabbr=="Aging Commun"&&$article_id!=1612){ + if ($article_id < 1665 && $jabbr == "Aging Commun" && $article_id != 1612) { return "TMR Aging"; } - if($article_id<1869&&$jabbr=="Nurs Commun"){ + if ($article_id < 1869 && $jabbr == "Nurs Commun") { return "TMR Integr Nurs"; } - if($article_id<1981&&$jabbr=="Toxicol Adv"){ + if ($article_id < 1981 && $jabbr == "Toxicol Adv") { return "Asian Toxicol Res"; } - if($article_id>=1981&&$article_id<2358&&$jabbr=='Toxicol Adv'){ + if ($article_id >= 1981 && $article_id < 2358 && $jabbr == 'Toxicol Adv') { return "Toxicol Commun"; } - if($article_id<2190&&$jabbr=="Food Health"){ + if ($article_id < 2190 && $jabbr == "Food Health") { return "Food Ther Health Care"; } - if($article_id<2520&&$jabbr=="Chin Quintessence Res"){ + if ($article_id < 2520 && $jabbr == "Chin Quintessence Res") { return "经典中医研究"; } - if($article_id<2980&&$jabbr=="Integr Med Discov"){ + if ($article_id < 2980 && $jabbr == "Integr Med Discov") { return "TMR Integr Med"; } - if($article_id<3051&&$jabbr=="Pharmacol Discov"){ + if ($article_id < 3051 && $jabbr == "Pharmacol Discov") { return "TMR Pharmacol Res"; } - if($article_id<3200&&$jabbr=="Nat Ther Adv"){ + if ($article_id < 3200 && $jabbr == "Nat Ther Adv") { return "TMR Modern Herb Med"; } return $jabbr; } -function getArticleMains($article_id){ +function getArticleMains($article_id) +{ $article_main_obj = Db::name("article_main"); - $list = $article_main_obj->where('article_id',$article_id)->where('state',0)->where('is_add',0)->select(); + $list = $article_main_obj->where('article_id', $article_id)->where('state', 0)->where('is_add', 0)->select(); $frag = []; - foreach ($list as $v){ + foreach ($list as $v) { $frag[] = $v; $pre = $v['article_main_id']; - while ($pre!=0){ - $ca = $article_main_obj->where("pre_id",$pre)->where('state',0)->find(); - if($ca){ + while ($pre != 0) { + $ca = $article_main_obj->where("pre_id", $pre)->where('state', 0)->find(); + if ($ca) { $frag[] = $ca; $pre = $ca['article_main_id']; - }else{ + } else { $pre = 0; } } @@ -104,117 +109,122 @@ function getArticleMains($article_id){ return $frag; } -function getArticleRefers($article_id){ +function getArticleRefers($article_id) +{ $article_obj = Db::name("article"); - $article_info = $article_obj->where('article_id',$article_id)->find(); + $article_info = $article_obj->where('article_id', $article_id)->find(); $url = "http://api.tmrjournals.com/public/index.php/api/Web/getRefers"; $program['w_article_id'] = $article_info['article_id']; - $dois = explode("/",$article_info['doi']); + $dois = explode("/", $article_info['doi']); $program['doi'] = $dois[1]; - $res = object_to_array(json_decode(myPost($url,$program))); - $refers = isset($res['data']['refers'])?$res['data']['refers']:[]; + $res = object_to_array(json_decode(myPost($url, $program))); + $refers = isset($res['data']['refers']) ? $res['data']['refers'] : []; return $refers; } -function getArticleTracks($doi){ +function getArticleTracks($doi) +{ $url = "http://api.tmrjournals.com/public/index.php/api/Web/getStackByDoi"; $program["doi"] = $doi; - $res = object_to_array(json_decode(myPost($url,$program))); - if($res['code']==1){ + $res = object_to_array(json_decode(myPost($url, $program))); + if ($res['code'] == 1) { return []; - }else{ + } else { return $res['data']['msgs']; } } -function choiseJtitle($list){ - foreach ($list as $k => $v){ +function choiseJtitle($list) +{ + foreach ($list as $k => $v) { $list[$k]['journal_title'] = choiseti($v); } return $list; } -function choiseti($v){ - if($v['article_id']<1799&&$v['journal_title']=="Cancer Advances"){ +function choiseti($v) +{ + if ($v['article_id'] < 1799 && $v['journal_title'] == "Cancer Advances") { return "TMR Cancer"; } - if($v['article_id']<910&&$v['journal_title']=="Microenvironment & Microecology Research"){ + if ($v['article_id'] < 910 && $v['journal_title'] == "Microenvironment & Microecology Research") { return "Tumor Microenvironment Research"; } - if($v['article_id']<1799&&$v['journal_title']=="Medical Theory and Hypothesis"){ + if ($v['article_id'] < 1799 && $v['journal_title'] == "Medical Theory and Hypothesis") { return "TMR Theory and Hypothesis"; } - if($v['article_id']<1821&&$v['journal_title']=="Clinical Research Communications"){ + if ($v['article_id'] < 1821 && $v['journal_title'] == "Clinical Research Communications") { return "TMR Clinical Research"; } - if($v['article_id']<1665&&$v['journal_title']=="Aging Communications"&&$v['article_id']!=1612){ + if ($v['article_id'] < 1665 && $v['journal_title'] == "Aging Communications" && $v['article_id'] != 1612) { return "TMR Aging"; } - if($v['article_id']<1869&&$v['journal_title']=="Nursing Communications"){ + if ($v['article_id'] < 1869 && $v['journal_title'] == "Nursing Communications") { return "TMR Integrative Nursing"; } - if($v['article_id']<1981&&$v['journal_title']=="Toxicology Advances"){ + if ($v['article_id'] < 1981 && $v['journal_title'] == "Toxicology Advances") { return "Asian Toxicology Research"; } - if($v['article_id']>=1981&&$v['article_id']<2358&&$v['journal_title']=="Toxicology Advances"){ + if ($v['article_id'] >= 1981 && $v['article_id'] < 2358 && $v['journal_title'] == "Toxicology Advances") { return "Toxicology Communications"; } - if($v['article_id']<2190&&$v['journal_title']=="Food and Health"){ + if ($v['article_id'] < 2190 && $v['journal_title'] == "Food and Health") { return "Food Therapy and Health Care"; } - if($v['article_id']<2520&&$v['journal_title']=="Chin Quintessence Res"){ + if ($v['article_id'] < 2520 && $v['journal_title'] == "Chin Quintessence Res") { return "经典中医研究"; } - if($v['article_id']<2980&&$v['journal_title']=="Integrative Medicine Discovery"){ + if ($v['article_id'] < 2980 && $v['journal_title'] == "Integrative Medicine Discovery") { return "TMR Integrative Medicine"; } - if($v["article_id"]<3051&&$v['journal_title']=="Pharmacology Discovery"){ + if ($v["article_id"] < 3051 && $v['journal_title'] == "Pharmacology Discovery") { return "TMR Pharmacology Research"; } - if($v["article_id"]<3200&&$v['journal_title']=="Natural Therapy Advances"){ + if ($v["article_id"] < 3200 && $v['journal_title'] == "Natural Therapy Advances") { return "TMR Modern Herbal Medicine"; } return $v['journal_title']; } -function choiseti1($article_id,$journal_title){ - if($article_id<1799&&$journal_title=="Cancer Advances"){ +function choiseti1($article_id, $journal_title) +{ + if ($article_id < 1799 && $journal_title == "Cancer Advances") { return "TMR Cancer"; } - if($article_id<910&&$journal_title=="Microenvironment & Microecology Research"){ + if ($article_id < 910 && $journal_title == "Microenvironment & Microecology Research") { return "Tumor Microenvironment Research"; } - if($article_id<1799&&$journal_title=="Medical Theory and Hypothesis"){ + if ($article_id < 1799 && $journal_title == "Medical Theory and Hypothesis") { return "TMR Theory and Hypothesis"; } - if($article_id<1821&&$journal_title=="Clinical Research Communications"){ + if ($article_id < 1821 && $journal_title == "Clinical Research Communications") { return "TMR Clinical Research"; } - if($article_id<1665&&$journal_title=="Aging Communications"&&$article_id!=1612){ + if ($article_id < 1665 && $journal_title == "Aging Communications" && $article_id != 1612) { return "TMR Aging"; } - if($article_id<1869&&$journal_title=="Nursing Communications"){ + if ($article_id < 1869 && $journal_title == "Nursing Communications") { return "TMR Integrative Nursing"; } - if($article_id<1981&&$journal_title=="Toxicology Advances"){ + if ($article_id < 1981 && $journal_title == "Toxicology Advances") { return "Asian Toxicology Research"; } - if($article_id>=1981&&$article_id<2358&&$journal_title=="Toxicology Advances"){ + if ($article_id >= 1981 && $article_id < 2358 && $journal_title == "Toxicology Advances") { return "Toxicology Communications"; } - if($article_id<2190&&$journal_title=="Food and Health"){ + if ($article_id < 2190 && $journal_title == "Food and Health") { return "Food Therapy and Health Care"; } - if($article_id<2520&&$journal_title=="Chinese Quintessence Research"){ + if ($article_id < 2520 && $journal_title == "Chinese Quintessence Research") { return "Classical Chinese Medicine Research"; } - if($article_id<2980&&$journal_title=="Integrative Medicine Discovery"){ + if ($article_id < 2980 && $journal_title == "Integrative Medicine Discovery") { return "TMR Integrative Medicine"; } - if($article_id<3051&&$journal_title=="Pharmacology Discovery"){ + if ($article_id < 3051 && $journal_title == "Pharmacology Discovery") { return "TMR Pharmacology Research"; } - if($article_id<3200&&$journal_title=="Natural Therapy Advances"){ + if ($article_id < 3200 && $journal_title == "Natural Therapy Advances") { return "TMR Modern Herbal Medicine"; } return $journal_title; @@ -232,7 +242,8 @@ function choiseti1($article_id,$journal_title){ * @param $attachmentFile 附件 (string | array) * @return array */ -function sendEmail($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') { +function sendEmail($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') +{ date_default_timezone_set('PRC'); //Create a new PHPMailer instance $mail = new PHPMailer; @@ -283,8 +294,7 @@ function sendEmail($email = '', $title = '', $from_name = '', $content = '', $me //send the message, check for errors if (!$mail->send()) { $status = 0; - $data = "邮件发送失败" . $mail->ErrorInfo; - ; + $data = "邮件发送失败" . $mail->ErrorInfo;; } else { $status = 1; $data = "邮件发送成功"; @@ -292,8 +302,9 @@ function sendEmail($email = '', $title = '', $from_name = '', $content = '', $me return ['status' => $status, 'data' => $data]; //返回值(可选) } -function sendEmail_data($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') { - ini_set('memory_limit','3200M'); +function sendEmail_data($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') +{ + ini_set('memory_limit', '3200M'); date_default_timezone_set('PRC'); //Create a new PHPMailer instance $mail = new PHPMailer; @@ -336,16 +347,15 @@ function sendEmail_data($email = '', $title = '', $from_name = '', $content = '' // $mail->addAttachment($attachmentFile[$i], 'thanks.pdf' . $i); //这里可以是多维数组,然后循环附件的文件和名称 // } // } else { - if ($attachmentFile != '') { - //Attach an image file - $mail->addAttachment($attachmentFile, 'journal.zip'); - } + if ($attachmentFile != '') { + //Attach an image file + $mail->addAttachment($attachmentFile, 'journal.zip'); + } // } //send the message, check for errors if (!$mail->send()) { $status = 0; - $data = "邮件发送失败" . $mail->ErrorInfo; - ; + $data = "邮件发送失败" . $mail->ErrorInfo;; } else { $status = 1; $data = "邮件发送成功"; @@ -353,7 +363,8 @@ function sendEmail_data($email = '', $title = '', $from_name = '', $content = '' return ['status' => $status, 'data' => $data]; //返回值(可选) } -function sendEmail1($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') { +function sendEmail1($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') +{ date_default_timezone_set('PRC'); //Create a new PHPMailer instance $mail = new PHPMailer; @@ -413,35 +424,36 @@ function sendEmail1($email = '', $title = '', $from_name = '', $content = '', $m return ['status' => $status, 'data' => $data]; //返回值(可选) } -function aliemail($email,$title,$content){ +function aliemail($email, $title, $content) +{ // file_put_contents('/usr/a.txt', $email,FILE_APPEND); vendor('aliemail.email'); - $mailto=$email; - $mailsubject=$title; + $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"; + $net1 = str_replace("{{email}}", $email, $net); + $mailbody = $pre . $content . $net1; + $smtpserver = "smtpdm-ap-southeast-1.aliyun.com"; $smtpserverport = 80; - $smtpusermail = "propa@hellotmr.top"; + $smtpusermail = "propa@hellotmr.top"; // 发件人的账号,填写控制台配置的发信地址,比如xxx@xxx.com - $smtpuser = "propa@hellotmr.top"; + $smtpuser = "propa@hellotmr.top"; // 访问SMTP服务时需要提供的密码(在控制台选择发信地址进行设置) - $smtppass = "Wu751019Pnx"; - $mailsubject = "=?UTF-8?B?" . base64_encode($mailsubject) . "?="; - $mailtype = "HTML"; + $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 = ""; + $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); + $sender = $title; + $res = $smtp->sendmail($mailto, $smtpusermail, $mailsubject, $mailbody, $mailtype, $cc, $bcc, $additional_headers, $sender, $smtpreplyto); return $res; } @@ -449,9 +461,10 @@ function aliemail($email,$title,$content){ * 生成文章sn号 * @return type */ -function getArticleSN($abbr,$type) { +function getArticleSN($abbr, $type) +{ $str = $abbr; - $str .= date('Y', time()).$type.date('md', time()); + $str .= date('Y', time()) . $type . date('md', time()); $where['accept_sn'] = ['like', "$str%"]; $nowres = Db::name('article')->where($where)->select(); $last_num = 1; @@ -470,12 +483,13 @@ function getArticleSN($abbr,$type) { /** * 增加usermsg */ -function add_usermsg($userid, $content, $url) { +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(); + ->where('url', $url) + ->where('state', 0) + ->find(); if ($msg_info) { return true; } @@ -486,29 +500,32 @@ function add_usermsg($userid, $content, $url) { return $msg_obj->insert($msgdata); } -function jsonSuccess($data){ - return json(['code'=>0,'msg'=>'success','data'=>$data]); +function jsonSuccess($data) +{ + return json(['code' => 0, 'msg' => 'success', 'data' => $data]); } -function jsonError($msg){ - return json(['code'=>1,'msg'=>$msg]); +function jsonError($msg) +{ + return json(['code' => 1, 'msg' => $msg]); } -function myPost($url, $param=array()){ +function myPost($url, $param = array()) +{ - if(!is_array($param)){ + if (!is_array($param)) { throw new Exception("参数必须为array"); } - $httph =curl_init($url); + $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_RETURNTRANSFER, 1); curl_setopt($httph, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); @@ -520,47 +537,99 @@ function myPost($url, $param=array()){ // curl_setopt($httph, CURLOPT_HEADER,1); - $rst=curl_exec($httph); + $rst = curl_exec($httph); curl_close($httph); return $rst; - } - - function ORCIDPost($url, $param=array()){ +} - if(!is_array($param)){ + +function myGet($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 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 ORCIDPost($url, $param = array()) +{ + + if (!is_array($param)) { throw new Exception("参数必须为array"); } $headerArray = ['Content-Type: application/x-www-form-urlencoded']; - $httph =curl_init($url); + $httph = curl_init($url); curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, false); // curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1); - curl_setopt($httph,CURLOPT_RETURNTRANSFER,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_HTTPHEADER,$headerArray); + + curl_setopt($httph, CURLOPT_HTTPHEADER, $headerArray); // curl_setopt($httph, CURLOPT_RETURNTRANSFER,0); // curl_setopt($httph, CURLOPT_HEADER,1); - $rst=curl_exec($httph); - + $rst = curl_exec($httph); + curl_close($httph); return $rst; - } +}