Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e7b4abcd
authored
Aug 29, 2024
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完成文章富文本图片替换
parent
87c90f89
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
13 deletions
.env
app/Http/Services/DealImageService.php
app/Http/routes.php
.env
View file @
e7b4abcd
...
@@ -150,3 +150,5 @@ FOOTSTONE_URL=http://footstone.liexindev.net
...
@@ -150,3 +150,5 @@ FOOTSTONE_URL=http://footstone.liexindev.net
TAG_URL=http://192.168.1.18:32581
TAG_URL=http://192.168.1.18:32581
SKIP_SEND_EMAIL=true
SKIP_SEND_EMAIL=true
FILE_SERVER_URL=http://file.liexindev.net
app/Http/Services/DealImageService.php
View file @
e7b4abcd
...
@@ -17,31 +17,123 @@ class DealImageService
...
@@ -17,31 +17,123 @@ class DealImageService
preg_match_all
(
$pattern
,
$text
,
$matches
);
preg_match_all
(
$pattern
,
$text
,
$matches
);
$imageUrls
=
$matches
[
1
];
$imageUrls
=
$matches
[
1
];
dump
(
$imageUrls
);
// 输出所有提取出的 'img.ichunt.com' 图片链接
return
$imageUrls
;
}
}
//先去处理芯媒体的图片链接
//先去处理芯媒体的图片链接
public
static
function
dealNewsImage
()
public
static
function
dealNewsImage
()
{
{
$newsList
=
DB
::
connection
(
'liexin'
)
->
table
(
'article
_addon'
)
->
limit
(
1
0
)
->
get
();
$newsList
=
DB
::
connection
(
'liexin'
)
->
table
(
'article
'
)
->
where
(
'deal_status'
,
'!='
,
1
)
->
orderBy
(
'art_id'
,
'desc'
)
->
limit
(
10
0
)
->
get
();
foreach
(
$newsList
as
$news
)
{
foreach
(
$newsList
as
$news
)
{
self
::
getAllImage
(
$news
[
'body'
]);
$addon
=
DB
::
connection
(
'liexin'
)
->
table
(
'article_addon'
)
->
where
(
'art_id'
,
$news
[
'art_id'
])
->
first
();
if
(
empty
(
$addon
))
{
continue
;
}
$news
=
array_merge
(
$news
,
$addon
);
if
(
!
DB
::
connection
(
'liexin'
)
->
table
(
'article'
)
->
where
(
'art_id'
,
$news
[
'art_id'
])
->
exists
())
{
dump
(
"不存在的文章"
);
continue
;
}
$imageUrls
=
self
::
getAllImage
(
$news
[
'body'
]);
if
(
empty
(
$imageUrls
))
{
continue
;
}
//dump($imageUrls); // 输出所有提取出的 'img.ichunt.com' 图片链接
$imageMap
=
self
::
downloadAndUploadToPicServer
(
$imageUrls
);
//进行全局替换
foreach
(
$imageMap
as
$originImage
=>
$newImage
)
{
$news
[
'body'
]
=
str_replace
(
$originImage
,
$newImage
,
$news
[
'body'
]);
}
DB
::
connection
(
'liexin'
)
->
table
(
'article_addon'
)
->
where
(
'art_id'
,
$news
[
'art_id'
])
->
update
([
'body'
=>
$news
[
'body'
],
]);
DB
::
connection
(
'liexin'
)
->
table
(
'article'
)
->
where
(
'art_id'
,
$news
[
'art_id'
])
->
update
([
'deal_status'
=>
1
,
]);
dump
(
$news
[
'art_id'
]);
}
}
}
}
//处理cms的图片链接
public
function
dealCmsImage
()
{
}
//处理sku详细描述
public
function
dealSkuDetail
()
{
//先找出所有爱智的sku,按搜索的来
}
//根据url下载图片并且上传到图片服务
//根据url下载图片并且上传到图片服务
public
static
function
downloadAndUploadToPicServer
(
$url
)
public
static
function
downloadAndUploadToPicServer
(
$url
List
)
{
{
$path
=
storage_path
(
'/dealImage/'
)
.
md5
(
$url
);
$imageMap
=
[];
$client
=
new
\GuzzleHttp\Client
();
$path
=
''
;
$response
=
$client
->
get
(
$url
);
foreach
(
$urlList
as
$url
)
{
$contents
=
$response
->
getBody
()
->
getContents
();
if
(
str_contains
(
$url
,
'comhttp'
))
{
file_put_contents
(
$path
,
$contents
);
continue
;
}
try
{
$info
=
pathinfo
(
$url
);
$path
=
storage_path
(
'logs/'
)
.
md5
(
$url
)
.
'.'
.
$info
[
'extension'
];;
$client
=
new
\GuzzleHttp\Client
();
$response
=
$client
->
get
(
$url
);
$contents
=
$response
->
getBody
()
->
getContents
();
file_put_contents
(
$path
,
$contents
);
//然后上传到图片服务器
$response
=
$client
->
request
(
'POST'
,
env
(
'FILE_SERVER_URL'
)
.
'/uploadFile?sys_type=5&create_uid=1000'
,
[
'multipart'
=>
[
[
'name'
=>
'file'
,
'contents'
=>
fopen
(
$url
,
'r'
)
]
]
]);
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'
];
$imageMap
[
$url
]
=
$ossFileUrl
;
}
else
{
dump
(
'上传服务接口返回错误 : '
.
json_encode
(
$res
));
continue
;
}
}
else
{
dump
(
'上传网络错误,返回不一致的响应 : '
.
json_encode
(
$res
));
continue
;
}
}
catch
(
\Exception
$exception
)
{
dump
(
"发生错误 : "
.
$exception
->
getMessage
());
}
finally
{
if
(
file_exists
(
$path
))
{
//最后删除本地的文件
unlink
(
$path
);
}
}
}
return
$imageMap
;
//最后删除本地的文件
unlink
(
$path
);
}
}
}
}
app/Http/routes.php
View file @
e7b4abcd
...
@@ -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\D
ata
Service
::
dealNewsImage
();
\App\Http\Services\D
ealImage
Service
::
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);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment