AyrReleaseController.php
4.6 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
<?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\Controllers\Bside\FileController;
use App\Http\Controllers\file\ImageController;
use App\Http\Logic\Bside\AyrShare\AyrReleaseLogic;
use App\Http\Logic\Bside\AyrShare\AyrShareLogic;
use App\Models\File\Image;
use App\Models\File\Image as ImageModel;
/**
* @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 :(获取当前用户已绑定的社交链接)info
* @author :lyh
* @method :post
* @time :2023/5/9 16:00
*/
public function share_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,AyrShareHelper $ayrShare){
// DB::beginTransaction();
// try {
//获取发送账号详情
$share_info = $ayrShareLogic->ayr_share_info();
$data = [
'images'=>$this->param['image'],
'files'=>$this->param['file'],
];
//参数处理
$this->param['mediaUrls'] = $ayrReleaseLogic->image_file_param($data);;
//统一生成链接
$param = [
'post'=>$this->param['content'],
'platforms'=>$this->param['platforms'],
'mediaUrls'=>$this->param['mediaUrls'],//参数处理
'idempotencyKey'=>$this->param['idempotencyKey'],//时间(如是过去时间,立即发布)
];
//发送请求注册社交用户
$res = $ayrShare->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 :(图片上传到第三方平台)send_media
* @author :lyh
* @method :post
* @time :2023/5/10 14:07
*/
public function send_media(AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
$image_info = $ayrShareLogic->save_img_info($this->param['hash']);
if(empty($image_info['ayr_id'])){
//获取发送账号详情
$share_info = $ayrShareLogic->ayr_share_info();
//获取当前图片数据是否已上传到第三方
$arr = (new ImageController())->index($this->param['hash']);
//向第三方存储图片
$param = [
'file'=>($arr->original),//base64编码
];
$param_data = $ayrShare->post_media_upload($param,$share_info['profile_key']);
//更新图片库
$ayrShareLogic->save_img($param_data);
}
$this->response('success');
}
/**
* @name :(文件上传到第三方平台)send_media
* @author :lyh
* @method :post
* @time :2023/5/10 14:07
*/
public function send_media_file(AyrShareLogic $ayrShareLogic,AyrShareHelper $ayrShare){
$image_info = $ayrShareLogic->save_file_info($this->param['hash']);
if(empty($image_info['ayr_id'])){
//获取发送账号详情
$share_info = $ayrShareLogic->ayr_share_info();
//获取当前图片数据是否已上传到第三方
$arr = (new FileController())->index($this->param['hash']);
//向第三方存储图片
$param = [
'file'=>($arr->original),//base64编码
];
$param_data = $ayrShare->post_media_upload($param,$share_info['profile_key']);
//更新图片库
$ayrShareLogic->save_file($param_data);
}
$this->response('success');
}
}