Commit cd0534ed by 杨树贤

修改上传地址

parent 69c4b659
......@@ -18,12 +18,16 @@ class DealImageService
preg_match_all($pattern, $text, $matches);
$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;
}
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;
} else {
return '';
......@@ -201,14 +205,14 @@ class DealImageService
}
try {
$info = pathinfo($url);
$path = storage_path('logs/') . md5($url) . '.' . $info['extension'];;
$path = storage_path('logs/') . md5($url);
$client = new \GuzzleHttp\Client();
$response = $client->get($url);
$contents = $response->getBody()->getContents();
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' => [
[
'name' => 'file',
......@@ -216,17 +220,15 @@ class DealImageService
]
]
]);
if ($response->getStatusCode() != 200) {
dump('上传网络错误');
continue;
}
$res = json_decode($response->getBody()->getContents(), true);
if (isset($res['code'])) {
if ($res['code'] == 0) {
$ossFileUrl = $res['data']['oss_file_url'];
$ossFileUrl = $res['data']['oss_image_url'];
$imageMap[$url] = $ossFileUrl;
} else {
dump('上传服务接口返回错误 : ' . json_encode($res));
......
......@@ -84,7 +84,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], 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\DataService::checkSupplierBandAccount();
//(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