作者 lyh

gx

@@ -126,15 +126,13 @@ zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K @@ -126,15 +126,13 @@ zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K
126 * @time :2023/5/8 9:47 126 * @time :2023/5/8 9:47
127 * https://app.ayrshare.com/api/media/upload 127 * https://app.ayrshare.com/api/media/upload
128 */ 128 */
129 - public function post_media_upload($data){ 129 + public function post_media_upload($data,$api_key){
130 $param = [ 130 $param = [
131 'file'=>$data['file'],//base64编码 131 'file'=>$data['file'],//base64编码
132 - 'fileName'=>$data['file_name'],//生成图片名称  
133 - 'description'=>$data['description'],//描述  
134 ]; 132 ];
135 - $this->headers['Authorization'] = $this->headers['Authorization'].$data['profile_key']; 133 + $this->headers['Authorization'] = $this->headers['Authorization'].$api_key;
136 $url = $this->path.'/api/media/upload'; 134 $url = $this->path.'/api/media/upload';
137 - return $this->http_click('posts',$url,$param,$this->headers); 135 + return $this->http_click('post',$url,$param,$this->headers);
138 } 136 }
139 137
140 /** 138 /**
@@ -5,8 +5,12 @@ namespace App\Http\Controllers\Bside\AyrShare; @@ -5,8 +5,12 @@ namespace App\Http\Controllers\Bside\AyrShare;
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Helper\AyrShare as AyrShareHelper; 6 use App\Helper\AyrShare as AyrShareHelper;
7 use App\Http\Controllers\Bside\BaseController; 7 use App\Http\Controllers\Bside\BaseController;
  8 +use App\Http\Controllers\Bside\FileController;
  9 +use App\Http\Controllers\file\ImageController;
8 use App\Http\Logic\Bside\AyrShare\AyrReleaseLogic; 10 use App\Http\Logic\Bside\AyrShare\AyrReleaseLogic;
9 use App\Http\Logic\Bside\AyrShare\AyrShareLogic; 11 use App\Http\Logic\Bside\AyrShare\AyrShareLogic;
  12 +use App\Models\File\Image;
  13 +use App\Models\File\Image as ImageModel;
10 14
11 /** 15 /**
12 * @name:社交发布 16 * @name:社交发布
@@ -14,12 +18,23 @@ use App\Http\Logic\Bside\AyrShare\AyrShareLogic; @@ -14,12 +18,23 @@ use App\Http\Logic\Bside\AyrShare\AyrShareLogic;
14 class AyrReleaseController extends BaseController 18 class AyrReleaseController extends BaseController
15 { 19 {
16 /** 20 /**
  21 + * @name :(获取发送数据详情)info
  22 + * @author :lyh
  23 + * @method :post
  24 + * @time :2023/5/10 14:57
  25 + */
  26 + public function info(AyrReleaseLogic $ayrReleaseLogic){
  27 + $info = $ayrReleaseLogic->release_info();
  28 + $this->response('success',Code::SUCCESS,$info);
  29 + }
  30 +
  31 + /**
17 * @name :(获取当前用户已绑定的社交链接)info 32 * @name :(获取当前用户已绑定的社交链接)info
18 * @author :lyh 33 * @author :lyh
19 * @method :post 34 * @method :post
20 * @time :2023/5/9 16:00 35 * @time :2023/5/9 16:00
21 */ 36 */
22 - public function info(AyrShareLogic $ayrShareLogic){ 37 + public function share_info(AyrShareLogic $ayrShareLogic){
23 $info = $ayrShareLogic->ayr_share_info(); 38 $info = $ayrShareLogic->ayr_share_info();
24 $this->response('success',Code::SUCCESS,$info); 39 $this->response('success',Code::SUCCESS,$info);
25 } 40 }
@@ -29,7 +44,7 @@ class AyrReleaseController extends BaseController @@ -29,7 +44,7 @@ class AyrReleaseController extends BaseController
29 * @method :post 44 * @method :post
30 * @time :2023/5/9 9:36 45 * @time :2023/5/9 9:36
31 */ 46 */
32 - public function send_post(AyrReleaseLogic $ayrReleaseLogic,AyrShareLogic $ayrShareLogic){ 47 + public function send_post(AyrReleaseLogic $ayrReleaseLogic,AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
33 // DB::beginTransaction(); 48 // DB::beginTransaction();
34 // try { 49 // try {
35 //获取发送账号详情 50 //获取发送账号详情
@@ -39,10 +54,8 @@ class AyrReleaseController extends BaseController @@ -39,10 +54,8 @@ class AyrReleaseController extends BaseController
39 'files'=>$this->param['file'], 54 'files'=>$this->param['file'],
40 ]; 55 ];
41 //参数处理 56 //参数处理
42 - $image_data = $this->image_file_param($data); 57 + $image_data = $ayrReleaseLogic->image_file_param($data);
43 $this->param['mediaUrls'] = array_merge($image_data['images_link'],$image_data['files_link']); 58 $this->param['mediaUrls'] = array_merge($image_data['images_link'],$image_data['files_link']);
44 - var_dump($this->param);  
45 - die();  
46 //统一生成链接 59 //统一生成链接
47 $param = [ 60 $param = [
48 'post'=>$this->param['content'], 61 'post'=>$this->param['content'],
@@ -50,8 +63,7 @@ class AyrReleaseController extends BaseController @@ -50,8 +63,7 @@ class AyrReleaseController extends BaseController
50 'mediaUrls'=>$this->param['mediaUrls'],//参数处理 63 'mediaUrls'=>$this->param['mediaUrls'],//参数处理
51 ]; 64 ];
52 //发送请求注册社交用户 65 //发送请求注册社交用户
53 - $ayrShareHelper = new AyrShareHelper();  
54 - $res = $ayrShareHelper->post_send_msg($param,$share_info['profile_key']); 66 + $res = $ayrShare->post_send_msg($param,$share_info['profile_key']);
55 $this->response('success',Code::SUCCESS,$res); 67 $this->response('success',Code::SUCCESS,$res);
56 //保存数据库 68 //保存数据库
57 $ayrReleaseLogic->release_add(); 69 $ayrReleaseLogic->release_add();
@@ -63,46 +75,50 @@ class AyrReleaseController extends BaseController @@ -63,46 +75,50 @@ class AyrReleaseController extends BaseController
63 } 75 }
64 76
65 /** 77 /**
66 - * @name :(上传第三方参数参数)get_param 78 + * @name :(图片上传到第三方平台)send_media
67 * @author :lyh 79 * @author :lyh
68 * @method :post 80 * @method :post
69 - * @time :2023/5/10 10:27 81 + * @time :2023/5/10 14:07
70 */ 82 */
71 - public function image_file_param($data) {  
72 - if (empty($data) || !is_array($data)) {  
73 - return empty($data) ? is_array($data) ? [] : '' : $data; 83 + public function send_media(AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
  84 + $image_info = $ayrShareLogic->save_img_info($this->param['hash']);
  85 + if(empty($image_info['ayr_id'])){
  86 + //获取发送账号详情
  87 + $share_info = $ayrShareLogic->ayr_share_info();
  88 + //获取当前图片数据是否已上传到第三方
  89 + $arr = (new ImageController())->index($this->param['hash']);
  90 + //向第三方存储图片
  91 + $param = [
  92 + 'file'=>($arr->original),//base64编码
  93 + ];
  94 + $param_data = $ayrShare->post_media_upload($param,$share_info['profile_key']);
  95 + //更新图片库
  96 + $ayrShareLogic->save_img($param_data);
74 } 97 }
75 - foreach ($data as $k => $v) {  
76 - if (is_array($v)) {  
77 - $data[$k] = $this->_extents($v);  
78 - } else {  
79 - if (is_null($v)) {  
80 - $data[$k] = '';  
81 - continue;  
82 - }  
83 - //获取操作人  
84 - switch ((string) $k) {  
85 - case 'image':  
86 - $data['image_link'] = url('/b/image/' . $v . '/2');  
87 - break;  
88 - case 'images':  
89 - $v = explode(',',$v);  
90 - foreach ($v as $k1=>$v1){  
91 - $data['images_link'][$k1] = url('/b/image/' . $v1 . '/2');  
92 - }  
93 - break;  
94 - case 'file':  
95 - $data['file_link'] = url('/b/file_hash/' . $v .'/mp4');  
96 - break;  
97 - case 'files':  
98 - $v = explode(',',$v);  
99 - foreach ($v as $k1=>$v1){  
100 - $data['files_link'][$k1] = url('/b/file_hash/' . $v1 . '/mp4');  
101 - }  
102 - break;  
103 - }  
104 - } 98 + $this->response('success');
  99 + }
  100 +
  101 + /**
  102 + * @name :(文件上传到第三方平台)send_media
  103 + * @author :lyh
  104 + * @method :post
  105 + * @time :2023/5/10 14:07
  106 + */
  107 + public function send_media_file(AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
  108 + $image_info = $ayrShareLogic->save_file_info($this->param['hash']);
  109 + if(empty($image_info['ayr_id'])){
  110 + //获取发送账号详情
  111 + $share_info = $ayrShareLogic->ayr_share_info();
  112 + //获取当前图片数据是否已上传到第三方
  113 + $arr = (new FileController())->index($this->param['hash']);
  114 + //向第三方存储图片
  115 + $param = [
  116 + 'file'=>($arr->original),//base64编码
  117 + ];
  118 + $param_data = $ayrShare->post_media_upload($param,$share_info['profile_key']);
  119 + //更新图片库
  120 + $ayrShareLogic->save_file($param_data);
105 } 121 }
106 - return $data; 122 + $this->response('success');
107 } 123 }
108 } 124 }
@@ -33,7 +33,7 @@ class FileController @@ -33,7 +33,7 @@ class FileController
33 { 33 {
34 $this->request = request(); 34 $this->request = request();
35 $this->config = config('filesystems.disks.upload'); 35 $this->config = config('filesystems.disks.upload');
36 - $this->uploads = config('uploads.default_file'); 36 + $this->uploads = config('upload.default_file');
37 $this->path = $this->config['root'].$this->uploads['path'].'/'; 37 $this->path = $this->config['root'].$this->uploads['path'].'/';
38 } 38 }
39 39
@@ -44,13 +44,15 @@ class FileController @@ -44,13 +44,15 @@ class FileController
44 * @method :post 44 * @method :post
45 * @time :2023/5/9 9:15 45 * @time :2023/5/9 9:15
46 */ 46 */
47 - public function index($hash = '',$type = 1){ 47 + public function index($hash = '', $type = 1)
  48 + {
  49 + // 检查是否有修改日期或ETag头部
48 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) { 50 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
49 header("HTTP/1.1 304 Not Modified"); 51 header("HTTP/1.1 304 Not Modified");
50 exit; 52 exit;
51 } 53 }
52 $file_model = new File(); 54 $file_model = new File();
53 - $info = $file_model->read(['hash'=>$hash]); 55 + $info = $file_model->read(['hash' => $hash]);
54 if ($info === false) { 56 if ($info === false) {
55 $this->response('指定文件不存在!', Code::USER_ERROR); 57 $this->response('指定文件不存在!', Code::USER_ERROR);
56 } 58 }
@@ -58,10 +60,54 @@ class FileController @@ -58,10 +60,54 @@ class FileController
58 if (!is_file($path)) { 60 if (!is_file($path)) {
59 $this->response('指定文件已被系统删除!', Code::USER_ERROR); 61 $this->response('指定文件已被系统删除!', Code::USER_ERROR);
60 } 62 }
  63 + $size = $info['size'];
  64 + // 设置Content-Type头部
  65 + $header['Content-Type'] = 'video/' . $info['type'];
  66 + // 设置Accept-Ranges头部
  67 + $header['Accept-Ranges'] = 'bytes';
  68 + // 检查是否有范围请求
  69 + if (isset($_SERVER['HTTP_RANGE'])) {
  70 + $range = $_SERVER['HTTP_RANGE'];
  71 + $ranges = explode('-', substr($range, 6));
  72 + $start = intval($ranges[0]);
  73 + $end = $size - 1;
  74 + if (!empty($ranges[1])) {
  75 + $end = intval($ranges[1]);
  76 + }
  77 + $length = $end - $start + 1;
  78 + // 设置部分响应头部
  79 + $header['Content-Length'] = $length;
  80 + $header['Content-Range'] = 'bytes ' . $start . '-' . $end . '/' . $size;
  81 + // 发送206 Partial Content状态码
  82 + header('HTTP/1.1 206 Partial Content');
  83 + header('Status: 206 Partial Content');
  84 + header('Accept-Ranges: bytes');
  85 + header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size);
  86 +
  87 + // 读取部分内容并发送响应
  88 + $file = fopen($path, 'rb');
  89 + fseek($file, $start);
  90 + $buffer = 1024 * 8; // 设置缓冲区大小
  91 + while (!feof($file) && ($p = ftell($file)) <= $end) {
  92 + if ($p + $buffer > $end) {
  93 + // 最后一块缓冲区
  94 + $buffer = $end - $p + 1;
  95 + }
  96 + echo fread($file, $buffer);
  97 + flush(); // 将输出刷新到浏览器
  98 + }
  99 + fclose($file);
  100 + exit;
  101 + }
  102 + // 无范围请求,发送完整文件
  103 + $header['Content-Length'] = $size;
61 $content = file_get_contents($path); 104 $content = file_get_contents($path);
62 - $header['Content-Length'] = $info['size'];  
63 - $header['Content-Type'] = 'video/'.$info['type'];  
64 - return response($content, 200, $header); 105 + // 发送完整响应
  106 + foreach ($header as $name => $value) {
  107 + header("$name: $value");
  108 + }
  109 + echo $content;
  110 + exit;
65 } 111 }
66 /** 112 /**
67 * 图片上传 113 * 图片上传
@@ -73,6 +119,7 @@ class FileController @@ -73,6 +119,7 @@ class FileController
73 'file.required'=>'必须填写', 119 'file.required'=>'必须填写',
74 ]); 120 ]);
75 $files = $this->request->file('file'); 121 $files = $this->request->file('file');
  122 +
76 if (empty($files)) { 123 if (empty($files)) {
77 $this->response('没有上传的文件!', 400); 124 $this->response('没有上传的文件!', 400);
78 } 125 }
@@ -4,6 +4,8 @@ namespace App\Http\Logic\Bside\AyrShare; @@ -4,6 +4,8 @@ namespace App\Http\Logic\Bside\AyrShare;
4 4
5 use App\Http\Logic\Bside\BaseLogic; 5 use App\Http\Logic\Bside\BaseLogic;
6 use App\Models\AyrShare\AyrRelease; 6 use App\Models\AyrShare\AyrRelease;
  7 +use App\Models\File\File;
  8 +use App\Models\File\Image;
7 9
8 class AyrReleaseLogic extends BaseLogic 10 class AyrReleaseLogic extends BaseLogic
9 { 11 {
@@ -17,7 +19,7 @@ class AyrReleaseLogic extends BaseLogic @@ -17,7 +19,7 @@ class AyrReleaseLogic extends BaseLogic
17 } 19 }
18 20
19 /** 21 /**
20 - * @name :()release_info 22 + * @name :(获取详情)release_info
21 * @author :lyh 23 * @author :lyh
22 * @method :post 24 * @method :post
23 * @time :2023/5/9 16:27 25 * @time :2023/5/9 16:27
@@ -42,20 +44,32 @@ class AyrReleaseLogic extends BaseLogic @@ -42,20 +44,32 @@ class AyrReleaseLogic extends BaseLogic
42 } 44 }
43 return $this->success(); 45 return $this->success();
44 } 46 }
45 -  
46 /** 47 /**
47 - * @name :(上传第三方平台)0ayr_release_add 48 + * @name :(上传第三方图片参数处理)get_param
48 * @author :lyh 49 * @author :lyh
49 * @method :post 50 * @method :post
50 - * @time :2023/5/9 10:02 51 + * @time :2023/5/10 10:27
51 */ 52 */
52 - public function ayr_release_add($param){  
53 - $param = [  
54 - 'post'=>$this->param['content'],  
55 - 'platforms'=>$this->param['platforms'],  
56 - 'mediaUrls'=>$this->param['mediaUrls'],  
57 - ];  
58 - return $this->success($param); 53 + public function image_file_param($data) {
  54 + $arr = [];
  55 + foreach ($data as $k => $v){
  56 + if($k == 'images'){
  57 + $images = explode(',',$v);
  58 + $imageModel = new Image();
  59 + $list = $imageModel->list(['hash'=>['in',$images]],'id');
  60 + foreach ($list as $v1){
  61 + $arr[] = $v1['ayr_url'];
  62 + }
  63 + }else{
  64 + $files = explode(',',$v);
  65 + $filesModel = new File();
  66 + $list = $filesModel->list(['hash'=>['in',$files]],'id');
  67 + foreach ($list as $v2){
  68 + $arr[] = $v2['ayr_url'];
  69 + }
  70 + }
  71 + }
  72 + return $this->success($arr);
59 } 73 }
60 74
61 /** 75 /**
@@ -2,10 +2,10 @@ @@ -2,10 +2,10 @@
2 2
3 namespace App\Http\Logic\Bside\AyrShare; 3 namespace App\Http\Logic\Bside\AyrShare;
4 4
5 -use App\Helper\AyrShare as AyrShareHelper;  
6 -use App\Http\Controllers\file\ImageController;  
7 use App\Http\Logic\Bside\BaseLogic; 5 use App\Http\Logic\Bside\BaseLogic;
8 use App\Models\AyrShare\AyrShare; 6 use App\Models\AyrShare\AyrShare;
  7 +use App\Models\File\File as FileModel;
  8 +use App\Models\File\Image as ImageModel;
9 9
10 class AyrShareLogic extends BaseLogic 10 class AyrShareLogic extends BaseLogic
11 { 11 {
@@ -82,26 +82,76 @@ class AyrShareLogic extends BaseLogic @@ -82,26 +82,76 @@ class AyrShareLogic extends BaseLogic
82 } 82 }
83 return $this->success(); 83 return $this->success();
84 } 84 }
  85 + /**
  86 + * @name :(更新图片库)save_info_info
  87 + * @author :lyh
  88 + * @method :post
  89 + * @time :2023/5/10 15:01
  90 + */
  91 + public function save_img_info($hash){
  92 + $imageModel = new ImageModel();
  93 + $info = $imageModel->read(['hash'=>$hash]);
  94 + if($info === false){
  95 + $this->fail('error');
  96 + }
  97 + return $this->success();
  98 + }
85 99
86 /** 100 /**
87 - * @name :(向第三方平台发布帖子)api_public_msg 101 + * @name :(更新图片库)save_info_info
88 * @author :lyh 102 * @author :lyh
89 * @method :post 103 * @method :post
90 - * @time :2023/5/8 9:11 104 + * @time :2023/5/10 15:01
91 */ 105 */
92 - public function send_public_post($param){  
93 - //获取图片  
94 - $image_c = new ImageController();  
95 - $image_info = $image_c->index($param['hash']);  
96 - $param = [  
97 - 'post'=>$param['text'],  
98 - 'mediaUrls'=>$image_info,  
99 - 'platforms'=>$this->param['platforms'], 106 + public function save_file_info($hash){
  107 + $fileModel = new FileModel();
  108 + $info = $fileModel->read(['hash'=>$hash]);
  109 + if($info === false){
  110 + $this->fail('error');
  111 + }
  112 + return $this->success();
  113 + }
  114 +
  115 + /**
  116 + * @name :(更新图片库)save_img
  117 + * @author :lyh
  118 + * @method :post
  119 + * @time :2023/5/10 15:01
  120 + */
  121 + public function save_img($param_data){
  122 + //根据文件hash存入数据库
  123 + $ayr_data = [
  124 + 'ayr_id'=>$param_data['id'],
  125 + 'ayr_url'=>$param_data['url'],
  126 + 'ayr_url_link'=>$param_data['url_1080']
  127 + ];
  128 + $imageModel = new ImageModel();
  129 + $rs = $imageModel->edit($ayr_data,['hash'=>$this->param['hash']]);
  130 + if($rs === false){
  131 + $this->fail('更新失败');
  132 + }
  133 + return $this->success();
  134 + }
  135 +
  136 + /**
  137 + * @name :(更新文件库)save_img
  138 + * @author :lyh
  139 + * @method :post
  140 + * @time :2023/5/10 15:01
  141 + */
  142 + public function save_file($param_data){
  143 + //根据文件hash存入数据库
  144 + $ayr_data = [
  145 + 'ayr_id'=>$param_data['id'],
  146 + 'ayr_url'=>$param_data['url'],
  147 + 'ayr_url_link'=>$param_data['url_1080']
100 ]; 148 ];
101 - //发布帖子  
102 - $ayrShareHelper = new AyrShareHelper();  
103 - $res = $ayrShareHelper->post_send_msg($param);  
104 - $this->success($res); 149 + $imageModel = new FileModel();
  150 + $rs = $imageModel->edit($ayr_data,['hash'=>$this->param['hash']]);
  151 + if($rs === false){
  152 + $this->fail('更新失败');
  153 + }
  154 + return $this->success();
105 } 155 }
106 } 156 }
107 157
@@ -24,7 +24,7 @@ return [ @@ -24,7 +24,7 @@ return [
24 //默认视频 24 //默认视频
25 'default_file' =>[ 25 'default_file' =>[
26 'size' => [ 26 'size' => [
27 - 'max' => 1024*1024*200, // 2M 27 + 'max' => 1024*1024*20, // 2M
28 ], 28 ],
29 'path' => '/file' 29 'path' => '/file'
30 ], 30 ],
@@ -218,8 +218,10 @@ Route::middleware(['bloginauth'])->group(function () { @@ -218,8 +218,10 @@ Route::middleware(['bloginauth'])->group(function () {
218 Route::any('/bind', [\App\Http\Controllers\Bside\AyrShare\AyrShareController::class, 'bind_account'])->name('ayr_bind_account'); 218 Route::any('/bind', [\App\Http\Controllers\Bside\AyrShare\AyrShareController::class, 'bind_account'])->name('ayr_bind_account');
219 //社交绑定 219 //社交绑定
220 Route::prefix('release')->group(function () { 220 Route::prefix('release')->group(function () {
221 - Route::any('/', [\App\Http\Controllers\Bside\AyrShare\AyrReleaseController::class, 'info'])->name('ayr_release_info'); 221 + Route::any('/info', [\App\Http\Controllers\Bside\AyrShare\AyrReleaseController::class, 'info'])->name('ayr_release_info');
  222 + Route::any('/share_info', [\App\Http\Controllers\Bside\AyrShare\AyrReleaseController::class, 'share_info'])->name('ayr_release_share_info');
222 Route::any('/send', [\App\Http\Controllers\Bside\AyrShare\AyrReleaseController::class, 'send_post'])->name('ayr_release_send'); 223 Route::any('/send', [\App\Http\Controllers\Bside\AyrShare\AyrReleaseController::class, 'send_post'])->name('ayr_release_send');
  224 + Route::any('/send_media', [\App\Http\Controllers\Bside\AyrShare\AyrReleaseController::class, 'send_media'])->name('ayr_release_send_media');
223 }); 225 });
224 }); 226 });
225 227