|
@@ -143,11 +143,11 @@ class WeixinService extends Service
|
|
}
|
|
}
|
|
|
|
|
|
public function getWxFile($data){
|
|
public function getWxFile($data){
|
|
-// list($status, $msg) = $this->rule($data);
|
|
|
|
-// if(! $status) {
|
|
|
|
-// file_put_contents('record_ip.txt',date("Y-m-d H:i:s",time()).json_encode($data) . PHP_EOL."来源IP".$msg.PHP_EOL,8);
|
|
|
|
-// return [false, 'IP未入白名单'];
|
|
|
|
-// }
|
|
|
|
|
|
+ list($status, $msg) = $this->rule($data);
|
|
|
|
+ if(! $status) {
|
|
|
|
+ file_put_contents('record_ip.txt',date("Y-m-d H:i:s",time()).json_encode($data) . PHP_EOL."来源IP".$msg.PHP_EOL,8);
|
|
|
|
+ return [false, 'IP未入白名单'];
|
|
|
|
+ }
|
|
|
|
|
|
if(empty($data['wx_url'])) return [false, "URL不存在"];
|
|
if(empty($data['wx_url'])) return [false, "URL不存在"];
|
|
|
|
|
|
@@ -155,7 +155,7 @@ class WeixinService extends Service
|
|
list($status,$msg) = $this->get_helper_for_img($data['wx_url'],$header);
|
|
list($status,$msg) = $this->get_helper_for_img($data['wx_url'],$header);
|
|
if(! $status) return [false, $msg];
|
|
if(! $status) return [false, $msg];
|
|
|
|
|
|
- dd($msg);
|
|
|
|
|
|
+ return [true, $msg];
|
|
}
|
|
}
|
|
|
|
|
|
public function rule($data){
|
|
public function rule($data){
|
|
@@ -220,16 +220,16 @@ class WeixinService extends Service
|
|
return [false, $message];
|
|
return [false, $message];
|
|
}
|
|
}
|
|
|
|
|
|
- $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
|
|
|
- $header = substr($r, 0, $headerSize);
|
|
|
|
- $body = substr($r, $headerSize);
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
+
|
|
curl_close($ch);
|
|
curl_close($ch);
|
|
|
|
|
|
- $img = "";
|
|
|
|
|
|
+ // 检查是否为图片
|
|
|
|
+ if (! $this->isImage($r)) return [false, "资源不是图片"];
|
|
|
|
+
|
|
if ($httpCode == 200) {
|
|
if ($httpCode == 200) {
|
|
// 检查是否为图片
|
|
// 检查是否为图片
|
|
- list($status, $msg) = $this->getTemporaryUrl($body, $url);
|
|
|
|
|
|
+ list($status, $msg) = $this->getTemporaryUrl($r, $url);
|
|
if(! $status) return [false, $msg];
|
|
if(! $status) return [false, $msg];
|
|
$img = $msg;
|
|
$img = $msg;
|
|
} else {
|
|
} else {
|
|
@@ -248,25 +248,26 @@ class WeixinService extends Service
|
|
public function getTemporaryUrl($body,$url)
|
|
public function getTemporaryUrl($body,$url)
|
|
{
|
|
{
|
|
// 定义本地文件路径
|
|
// 定义本地文件路径
|
|
- $name = md5($url) . '.jpeg';
|
|
|
|
|
|
+ $name = md5($url) . '.jpg';
|
|
$localFilePath = storage_path(self::wx_img . $name);
|
|
$localFilePath = storage_path(self::wx_img . $name);
|
|
|
|
|
|
- if(! file_exists($localFilePath)){
|
|
|
|
- $directoryPath = dirname($localFilePath);
|
|
|
|
|
|
+ // 写入文件前先检查文件是否存在
|
|
|
|
+ if (! file_exists($localFilePath)) {
|
|
|
|
+
|
|
// 检查目录是否存在,如果不存在则创建
|
|
// 检查目录是否存在,如果不存在则创建
|
|
- if (! is_dir($directoryPath)) {
|
|
|
|
|
|
+ $directoryPath = dirname($localFilePath);
|
|
|
|
+ if (!is_dir($directoryPath)) {
|
|
// 设置目录权限,可以根据需要更改
|
|
// 设置目录权限,可以根据需要更改
|
|
$mode = 0777;
|
|
$mode = 0777;
|
|
// 使用递归选项创建目录
|
|
// 使用递归选项创建目录
|
|
- if (! mkdir($directoryPath, $mode, true)) return [false, '目录创建失败'];
|
|
|
|
|
|
+ if (!mkdir($directoryPath, $mode, true)) {
|
|
|
|
+ return [false, '目录创建失败'];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
file_put_contents($localFilePath, $body);
|
|
file_put_contents($localFilePath, $body);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- if(! file_exists($localFilePath)) file_put_contents($localFilePath, $body);
|
|
|
|
-
|
|
|
|
return [true, $name];
|
|
return [true, $name];
|
|
}
|
|
}
|
|
}
|
|
}
|