AyrReleaseController.php
4.9 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?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\Http\Requests\Bside\AyrShare\AyrReleaseRequest;
/**
* @name:社交发布
* Facebook Pages and Groups: 10 images, including a carousel post.
* Instagram: 10 images.
* Google : 1 image.
* LinkedIn: 9 images.
* Pinterest: 1 image.
* Reddit: 1 image.
* Telegram: 1 image.
* Twitter:4 image
*/
class AyrReleaseController extends BaseController
{
/**
* @name :(获取发送数据详情)info
* @author :lyh
* @method :post
* @time :2023/5/10 14:57
*/
public function info(AyrReleaseLogic $ayrReleaseLogic){
$info = $ayrReleaseLogic->release_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :(获取当前用户已绑定的社交链接)
* @author :lyh
* @method :post
* @time :2023/5/9 16:00
*/
public function share_info(AyrShareLogic $ayrShareLogic){
$this->request->validate([
'share_id'=>['required']
],[
'share_id.required' => 'share_id不能为空'
]);
$info = $ayrShareLogic->ayr_share_info($this->param['share_id']);
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :(发布社交)send_post
* @author :lyh
* @method :post
* @time :2023/5/9 9:36
*/
public function send_post(AyrReleaseRequest $ayrReleaseRequest,AyrReleaseLogic $ayrReleaseLogic,
AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
$ayrReleaseRequest->validated();
//获取发送账号详情
$share_info = $ayrShareLogic->ayr_share_info($this->param['share_id']);
//验证发送平台
$ayrShareLogic->verify_param($share_info);
if(isset($this->param['video']) && !empty($this->param['video'])){
$data['files'] = $this->param['video'];
}
if(isset($this->param['images']) && !empty($this->param['images'])){
$data['images'] = $this->param['images'];
}
//参数处理
$this->param['mediaUrls'] = $ayrReleaseLogic->image_file_param($data);
//时间处理
$datetime = new \DateTime($this->param['schedule_date']);
$formattedTime = $datetime->format("Y-m-d\TH:i:s\Z");
//统一生成发布
$param = [
'post'=>$this->param['content'],
'platforms'=>$this->param['platforms'],
'mediaUrls'=>$this->param['mediaUrls'],//参数处理
'scheduleDate'=>$formattedTime,//时间(如是过去时间,立即发布)
];
//发送请求发布社交文章
$res = $ayrShare->post_send_msg($param,$share_info['profile_key']);
//保存数据库
$ayrReleaseLogic->release_add();
$this->response('success',Code::SUCCESS,json_decode($res));
}
/**
* @name :(图片上传到第三方平台)send_media
* @author :lyh
* @method :post
* @time :2023/5/10 14:07
*/
public function send_media(AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
$this->request->validate([
'share_id'=>['required'],
'hash'=>['required']
],[
'share_id.required' => 'SHARE_ID不能为空',
'hash.required' => 'HASH不能为空'
]);
//获取发送账号详情
$share_info = $ayrShareLogic->ayr_share_info();
//向第三方存储图片
$param = [
'file'=>$ayrShareLogic->base_img_content($this->param['hash']),//base64编码
];
$param_data = $ayrShare->post_media_upload($param,$share_info['profile_key']);
//更新图片库
$ayrShareLogic->save_img($param_data);
$this->response('success',Code::SUCCESS,$param_data);
}
/**
* @name :(文件上传到第三方平台)send_media
* @author :lyh
* @method :post
* @time :2023/5/10 14:07
*/
public function send_media_file(AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
$this->request->validate([
'share_id'=>['required'],
'hash'=>['required']
],[
'share_id.required' => 'SHARE_ID不能为空',
'hash.required' => 'HASH不能为空'
]);
//获取发送账号详情
$share_info = $ayrShareLogic->ayr_share_info();
//向第三方存储图片
$param = [
'file'=>$ayrShareLogic->base_img_content($this->param['hash']),//base64编码
];
$param_data = $ayrShare->post_media_upload($param,$share_info['profile_key']);
//更新图片库
$ayrShareLogic->save_file($param_data);
$this->response('success');
}
}