mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]修改微信模块双模块兼容
This commit is contained in:
parent
6e18f7ff67
commit
9a1c040c00
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
namespace app\wechat\service;
|
namespace app\wechat\service;
|
||||||
|
|
||||||
|
use service\FileService;
|
||||||
use service\WechatService;
|
use service\WechatService;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
|
|
||||||
@ -56,17 +57,20 @@ class MediaService
|
|||||||
* @return string
|
* @return string
|
||||||
* @throws \WeChat\Exceptions\InvalidResponseException
|
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||||
* @throws \WeChat\Exceptions\LocalCacheException
|
* @throws \WeChat\Exceptions\LocalCacheException
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
*/
|
*/
|
||||||
public static function uploadImage($local_url)
|
public static function uploadImage($local_url)
|
||||||
{
|
{
|
||||||
$media_url = Db::name('WechatNewsImage')->where(['md5' => md5($local_url)])->value('media_url');
|
$map = ['md5' => md5($local_url)];
|
||||||
if (!empty($media_url)) {
|
if (!($media_url = Db::name('WechatNewsImage')->where($map)->value('media_url'))) {
|
||||||
return $media_url;
|
return $media_url;
|
||||||
}
|
}
|
||||||
$result = WechatService::wechat()->upFile(base64_encode(file_get_contents($local_url)), $local_url);
|
$info = WechatService::media()->uploadImg(self::getServerPath($local_url));
|
||||||
$info = WechatService::media()->uploadImg($result['file']);
|
if (strtolower(sysconf('wechat_type')) === 'thr') {
|
||||||
WechatService::wechat()->rmFile($local_url);
|
WechatService::wechat()->rmFile($local_url);
|
||||||
$data = ['local_url' => $local_url, 'media_url' => $info['url'], 'md5' => md5($local_url)];
|
}
|
||||||
|
$data = ['local_url' => $local_url, 'media_url' => $info['url'], 'md5' => $map['md5']];
|
||||||
Db::name('WechatNewsImage')->insert($data);
|
Db::name('WechatNewsImage')->insert($data);
|
||||||
return $info['url'];
|
return $info['url'];
|
||||||
}
|
}
|
||||||
@ -88,13 +92,36 @@ class MediaService
|
|||||||
if (($media_id = Db::name('WechatNewsMedia')->where($map)->value('media_id'))) {
|
if (($media_id = Db::name('WechatNewsMedia')->where($map)->value('media_id'))) {
|
||||||
return $media_id;
|
return $media_id;
|
||||||
}
|
}
|
||||||
$result = WechatService::wechat()->upFile(base64_encode(file_get_contents($local_url)), $local_url);
|
$result = WechatService::media()->addMaterial(self::getServerPath($local_url), $type, $video_info);
|
||||||
$result = WechatService::media()->addMaterial($result['file'], $type, $video_info);
|
if (strtolower(sysconf('wechat_type')) === 'thr') {
|
||||||
WechatService::wechat()->rmFile($local_url);
|
WechatService::wechat()->rmFile($local_url);
|
||||||
|
}
|
||||||
$data = ['md5' => $map['md5'], 'type' => $type, 'appid' => $map['appid'], 'media_id' => $result['media_id'], 'local_url' => $local_url];
|
$data = ['md5' => $map['md5'], 'type' => $type, 'appid' => $map['appid'], 'media_id' => $result['media_id'], 'local_url' => $local_url];
|
||||||
isset($result['url']) && $data['media_url'] = $result['url'];
|
isset($result['url']) && $data['media_url'] = $result['url'];
|
||||||
Db::name('WechatNewsMedia')->insert($data);
|
Db::name('WechatNewsMedia')->insert($data);
|
||||||
return $data['media_id'];
|
return $data['media_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件位置处理
|
||||||
|
* @param string $local
|
||||||
|
* @return string
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
protected static function getServerPath($local)
|
||||||
|
{
|
||||||
|
switch (strtolower(sysconf('wechat_type'))) {
|
||||||
|
case 'api':
|
||||||
|
if (file_exists($local)) {
|
||||||
|
return $local;
|
||||||
|
}
|
||||||
|
return FileService::download($local)['file'];
|
||||||
|
case 'thr':
|
||||||
|
return WechatService::wechat()->upFile(base64_encode(file_get_contents($local)), $local)['file'];
|
||||||
|
default:
|
||||||
|
return $local;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user