1
This commit is contained in:
@@ -207,6 +207,44 @@ function search_array_val($arr,$val){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
$frag1 = $frag==""?"none":$frag;
|
||||
$ts_refer_obj->where('ts_refer_id',$data['ts_refer_id'])->update(['refer_frag'=>$frag1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加usermsg
|
||||
*/
|
||||
@@ -247,6 +285,10 @@ function choiseJabbr($article_id, $jabbr) {
|
||||
return $jabbr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function myPost($url, $param = array()) {
|
||||
|
||||
if (!is_array($param)) {
|
||||
@@ -276,3 +318,37 @@ function myPost($url, $param = array()) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user