Commit cd0534ed by 杨树贤

修改上传地址

parent 69c4b659
...@@ -18,12 +18,16 @@ class DealImageService ...@@ -18,12 +18,16 @@ class DealImageService
preg_match_all($pattern, $text, $matches); preg_match_all($pattern, $text, $matches);
$imageUrls = $matches[1]; $imageUrls = $matches[1];
$pattern = '/<img [^>]*src\s*=\s*["\']?([^"\'>]*file\.liexindev\.net[^"\'>]*)/i';
preg_match_all($pattern, $text, $matches);
$imageUrls = array_merge($imageUrls, $matches[1]);
return $imageUrls; return $imageUrls;
} }
public static function checkImage($link) public static function checkImage($link)
{ {
if (strpos($link, 'img.ichunt.com') !== false || strpos($link, 'file.ichunt.com') !== false || strpos($link, 'file.liexindev.com') !== false) { if (strpos($link, 'img.ichunt.com') !== false || strpos($link, 'file.ichunt.net') !== false || strpos($link, 'file.liexindev.net') !== false) {
return $link; return $link;
} else { } else {
return ''; return '';
...@@ -201,14 +205,14 @@ class DealImageService ...@@ -201,14 +205,14 @@ class DealImageService
} }
try { try {
$info = pathinfo($url); $info = pathinfo($url);
$path = storage_path('logs/') . md5($url) . '.' . $info['extension'];; $path = storage_path('logs/') . md5($url);
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
$response = $client->get($url); $response = $client->get($url);
$contents = $response->getBody()->getContents(); $contents = $response->getBody()->getContents();
file_put_contents($path, $contents); file_put_contents($path, $contents);
//然后上传到图片服务器 //然后上传到图片服务器
$response = $client->request('POST', env('IMAGE_SERVER_URL') . '/uploadFile?sys_type=5&create_uid=1000', [ $response = $client->request('POST', env('IMAGE_SERVER_URL') . '/uploadImage?sys_type=5&create_uid=1000', [
'multipart' => [ 'multipart' => [
[ [
'name' => 'file', 'name' => 'file',
...@@ -216,17 +220,15 @@ class DealImageService ...@@ -216,17 +220,15 @@ class DealImageService
] ]
] ]
]); ]);
if ($response->getStatusCode() != 200) { if ($response->getStatusCode() != 200) {
dump('上传网络错误'); dump('上传网络错误');
continue; continue;
} }
$res = json_decode($response->getBody()->getContents(), true); $res = json_decode($response->getBody()->getContents(), true);
if (isset($res['code'])) { if (isset($res['code'])) {
if ($res['code'] == 0) { if ($res['code'] == 0) {
$ossFileUrl = $res['data']['oss_file_url']; $ossFileUrl = $res['data']['oss_image_url'];
$imageMap[$url] = $ossFileUrl; $imageMap[$url] = $ossFileUrl;
} else { } else {
dump('上传服务接口返回错误 : ' . json_encode($res)); dump('上传服务接口返回错误 : ' . json_encode($res));
......
...@@ -84,7 +84,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -84,7 +84,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
\App\Http\Services\DealImageService::dealCmsImage(); \App\Http\Services\DealImageService::dealNewsImage();
//\App\Http\Services\SupplierAddressService::initUnitedAddress(); //\App\Http\Services\SupplierAddressService::initUnitedAddress();
//\App\Http\Services\DataService::checkSupplierBandAccount(); //\App\Http\Services\DataService::checkSupplierBandAccount();
//(new CompanyService())->checkSupplierCompanyAndAddress(11042); //(new CompanyService())->checkSupplierCompanyAndAddress(11042);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment