init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)
这个提交包含在:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Common\Business;
|
||||
//[1.8.50]
|
||||
/**
|
||||
* 向第三方发送POST请求
|
||||
* Class ThirdSendRequest
|
||||
* [
|
||||
* 向第三方发送POST请求 curlPost
|
||||
* 向第三方发送POST请求获取cookie值 curlPostGetCookie
|
||||
* ]
|
||||
* @package Common\Business
|
||||
*/
|
||||
class ThirdSendRequest
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 向第三方发送POST请求
|
||||
* @param $url
|
||||
* @param $content
|
||||
* @param array $headers
|
||||
* @param string $cookie
|
||||
* @return bool|string
|
||||
*/
|
||||
public function curlPost($url, $content, $headers = [], $cookie = '')
|
||||
{
|
||||
$ch = curl_init();
|
||||
if (substr($url, 0, 5) == 'https') {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
if (!empty($headers)) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
|
||||
if (!empty($cookie)) {
|
||||
curl_setopt($ch, CURLOPT_COOKIE, $cookie);//以变量形式发送cookie
|
||||
}
|
||||
$result = curl_exec($ch);
|
||||
$error = curl_error($ch);
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 向第三方发送POST请求获取cookie值
|
||||
* @param $url
|
||||
* @param $content
|
||||
* @param array $headers
|
||||
* @return bool|string
|
||||
*/
|
||||
public function curlPostGetCookie($url, $content, $headers = [])
|
||||
{
|
||||
$ch = curl_init();
|
||||
if (substr($url, 0, 5) == 'https') {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
|
||||
}
|
||||
curl_setopt($ch,CURLOPT_HEADER,true); //返回带有响应的HTTP标头
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
if (!empty($headers)) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
|
||||
$result = curl_exec($ch);
|
||||
$error = curl_error($ch);
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户