AyrReleaseController.php
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace App\Http\Controllers\Bside\AyrShare;
use App\Enums\Common\Code;
use App\Helper\AyrShare as AyrShareHelper;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\AyrShare\AyrReleaseLogic;
use App\Http\Logic\Bside\AyrShare\AyrShareLogic;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use Illuminate\Support\Facades\DB;
/**
* @name:社交发布
*/
class AyrReleaseController extends BaseController
{
/**
* @name :(获取当前用户已绑定的社交链接)info
* @author :lyh
* @method :post
* @time :2023/5/9 16:00
*/
public function info(AyrShareLogic $ayrShareLogic){
$info = $ayrShareLogic->ayr_share_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :(发布社交)send_post
* @author :lyh
* @method :post
* @time :2023/5/9 9:36
*/
public function send_post(AyrReleaseLogic $ayrReleaseLogic,AyrShareLogic $ayrShareLogic){
// DB::beginTransaction();
// try {
//获取发送账号详情
$share_info = $ayrShareLogic->ayr_share_info();
$data = [
'images'=>$this->param['image'],
'files'=>$this->param['file'],
];
//参数处理
$image_data = $this->image_file_param($data);
$this->param['mediaUrls'] = array_merge($image_data['images_link'],$image_data['files_link']);
//统一生成链接
$param = [
'post'=>$this->param['content'],
'platforms'=>$this->param['platforms'],
'mediaUrls'=>$this->param['mediaUrls'],//参数处理
];
//发送请求注册社交用户
$ayrShareHelper = new AyrShareHelper();
$res = $ayrShareHelper->post_send_msg($param,$share_info['profile_key']);
$this->response('success',Code::SUCCESS,$res);
//保存数据库
$ayrReleaseLogic->release_add();
// DB::commit();
// }catch (\Exception $e){
// DB::rollBack();
// $this->response('error',Code::USER_ERROR);
// }
}
/**
* @name :(上传第三方参数参数)get_param
* @author :lyh
* @method :post
* @time :2023/5/10 10:27
*/
public function image_file_param($data) {
if (empty($data) || !is_array($data)) {
return empty($data) ? is_array($data) ? [] : '' : $data;
}
foreach ($data as $k => $v) {
if (is_array($v)) {
$data[$k] = $this->_extents($v);
} else {
if (is_null($v)) {
$data[$k] = '';
continue;
}
//获取操作人
switch ((string) $k) {
case 'image':
$data['image_link'] = url('/b/image/' . $v . '/'.rand(100,999));
break;
case 'images':
$v = explode(',',$v);
foreach ($v as $k1=>$v1){
$data['images_link'][$k1] = url('/b/image/' . $v1 . '/'.rand(100,999));
}
break;
case 'file':
$data['file_link'] = url('/b/file_hash/' . $v .'/.mp4');
break;
case 'files':
$v = explode(',',$v);
foreach ($v as $k1=>$v1){
$data['files_link'][$k1] = url('/b/file_hash/' . $v1 . '/.mp4');
}
break;
}
}
}
return $data;
}
}