AyrShare.php
8.2 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
namespace App\Helper;
use GuzzleHttp\Client;
/**
* @name: ayr_share社交绑定
*/
class AyrShare
{
public $path = 'https://app.ayrshare.com';
//api_key
public $api_key = 'G8GQW3X-XBTMGXW-QPDDZ9A-WE1Z5SB';
//系统设置
public $config = [
'facebook'=>'#best https://www.facebook.com',
'google'=>'#best https://www.google.com',
'instagram'=>'#best https://www.instagram.com',
'linkedin'=>'#best https://www.linkedin.com',
'twitter'=>'#best https://www.twitter.com',
'telegram'=>'#best https://www.telegram.com',
'tiktok'=>'#bestvideo',
];
//profile_key
public $profile_key = '';
//设置请求头
public $headers = [
'Authorization' => 'Bearer ',
'Content-Type' => 'application/json',
];
//私钥
private $private_key = "-----BEGIN RSA PRIVATE KEY-----
MIICWgIBAAKBgGFatMeBeaw7QJrqmylMLZlwuuO0FA/EZg5/g7Rrqu+FgpwvFkJq
9twEZJY+aIdDH8/RVrCZQGR/xUxKw9v4ows+sLwi4g41m8KRKDXUcJwQvSlwsHAi
h9hPGZxDsRK0Nv4pZ7XqGgh0Wb0VypX/+Q1dhX9BnXQmvEKayk8GQWQxAgMBAAEC
gYAFqOJNnudV7fPpja4LjpQwEW+sATIRYJeWTC9587ByUE6xicM/hTxouhCm82Xc
Rzi4OjFR/vbRYOQ1dTtBtIi18fdRrseQNyR/N2NZjw1X8n5aZcw5NVaa3d3YTQNa
uzjnYF5eYSOD4pNKKIDc35VHdmvGCV/JXwQKMTgu1+4AAQJBAL5jjN3kvMKFF8vG
DyYR8k+wPG9iXAdR0HjVNB3OzxKVW0MTwM32pJBXCmF1MOziL8WC48VHQL48hVRa
52xRqAECQQCC53rrrOPhPCLIb6kBfgqnxCojqlUK9paFL7NYTPtLYcOajY6+NiKT
CG1gaOwZh4r34HF7I59l/Ds98Z4nQDwxAkAC4/oIiGeBQIoK8vfZ6R3XreJNAp5J
EinrG7mN1kz4iEH5c7xSpDL9agTjU+cpQYneIs2Yeit2d+7CSBsJXvgBAkBDFsfU
yYLxCJT7DN8dOK/VU6AVL1Luj3qNP+k2tB2GgNBzAWHK8ou9t2/3HU8DtofuikUe
yx8Cccca9B4OF8nBAkAgIUZKGmVNFcGnFFo55vSJInNXFo4HCJ2o4DunBORVtQ/j
zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K
-----END RSA PRIVATE KEY-----";
/**
* @name :(创建子账户配置文件)post_create_profiles
* @author :lyh
* @method :post
* @time :2023/5/5 15:16
*/
public function post_create_profiles($data){
$param = [
'title'=>$data['title'],
];
$url = $this->path.'/api/profiles/profile';
return $this->http_click('post',$url,$param);
}
/**
* @name :(删除子账户配置文件)deleted_profiles
* @author :lyh
* @method :post
* @time :2023/5/5 15:16
*/
public function deleted_profiles($data){
$param = [
'title'=>$data['title'],
// 'profileKey'=>$this->profile_key,
];
$url = $this->path.'/api/profiles/profile';
return $this->http_click('delete',$url,$param);
}
/**
* @name :(跳转第三方生成jwt令牌)post_generate_jwt
* @author :lyh
* @method :post
* @time :2023/5/5 18:07 https://app.ayrshare.com/api/profiles/generateJWT
*/
public function post_generate_jwt($data,$domain = 'globalso'){
$param = [
'domain'=>$domain,
'privateKey'=>$this->private_key,
'profileKey'=>$data['profileKey'],
// 'logout'=>true
];
$url = $this->path.'/api/profiles/generateJWT';
return $this->http_click('post',$url,$param);
}
/**
* @name :(获取指定api_key的配置文件)get_profiles_users
* @author :lyh
* @method :post
* @time :2023/5/6 16:44
*/
public function get_profiles_users($api_key){
$this->headers['Authorization'] = $this->headers['Authorization'].$api_key;
$url = $this->path.'/api/user';
return $this->http_click('get',$url,[],$this->headers);
}
/**
* @name :(发帖)post_send_msg
* @author :lyh
* @method :post
* @time :2023/5/8 9:22
* @param :platforms: "facebook", "fbg", "twitter",
* "linkedin", "instagram","youtube", "reddit" ,"telegram""
*/
public function post_send_msg($param,$api_key){
//平台参数处理
$this->headers['Accept-Encoding'] = 'gzip';
$this->headers['Authorization'] = $this->headers['Authorization'].$api_key;
$url = $this->path.'/api/post';
return $this->http_click('posts',$url,$param,$this->headers);
}
/**
* @name :(上传图片或视频到ayr_share)post_media_upload
* @author :lyh
* @method :post
* @time :2023/5/8 9:47
* https://app.ayrshare.com/api/media/upload
*/
public function post_media_upload($data,$api_key){
$param = [
'file'=>$data['file'],//base64编码
];
$this->headers['Authorization'] = $this->headers['Authorization'].$api_key;
$url = $this->path.'/api/media/upload';
return $this->http_click('post',$url,$param,$this->headers);
}
/**
* @name :获取过去30天发布的历史记录(1-30)
* @author :lyh
* @method :get
* @time :2023/5/5 10:00
*/
public function get_analytics_links($to_day){
$last_days = (string)$to_day;
$url = $this->path.'/analytics/links?lastDays='.$last_days;
return $this->http_click('get',$url);
}
/**
* @name :(通过 Ayrshare 获取给定帖子的实时分析,例如点赞、印象、转推等)post_analytics
* @author :lyh
* @method :post
* @time :2023/5/5 11:56
*/
public function post_analytics($id){
$param = [
'id'=>$id,
'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
];
$url = $this->path.'/api/analytics/post';
return $this->http_click('post', $url, $param);
}
/**
* @name :(获取特定用户个人资料)analytics_post
* @author :lyh
* @method :post
* @time :2023/5/5 10:43
*/
public function post_analytics_social(){
$post_data = [
'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
];
$url = $this->path.'/api/analytics/social';
return $this->http_click('post',$url,$post_data);
}
/**
* @name :(设置自动计划)post_schedule_set
* @author :lyh
* @method :post
* @time :2023/5/5 13:58
*/
public function post_schedule_set($data){
$param = [
'schedule'=>["13:05Z", "20:14Z"],
'title'=>$data['title'],
];
$url = $this->path.'/api/auto-schedule/set';
return $this->http_click('post',$url,$param);
}
/**
* @name :(删除自动计划)delete_schedule
* @author :lyh
* @method :post
* @time :2023/5/5 14:04
*/
public function delete_schedule($data){
$param = [
'title'=>$data['title'],
];
$url = $this->path.'/api/auto-schedule/delete';
return $this->http_click('delete',$url,$param);
}
/**
* @name :(列出自动计划)get_schedule_list
* @author :lyh
* @method :post
* @time :2023/5/5 14:08
*/
public function get_schedule_list(){
$url = $this->path.'/api/auto-schedule/list';
return $this->http_click('get',$url);
}
/**
* @name :(发布到用户个人资料)post_user
* @author :lyh
* @method :post
* @time :2023/5/5 15:00
*/
public function post_profiles($data){
$param = [
'post'=>$data['post'],
'platforms'=>$data['platforms'],
'profileKey'=>$this->profile_key,
'mediaUrls'=>$data['mediaUrls']
];
$url = $this->path.'/api/post';
return $this->http_click('post',$url,$param);
}
/**
* 发送http post,get,put,delete请求
* @param type $url
* @param type $post_data
*/
function http_click($method = 'post',$url, $param = [],$header = [])
{
if(!empty($param)){
$post_data['json'] = $param;
}
if(empty($header)){
$this->headers['Authorization'] = $this->headers['Authorization'].$this->api_key;
}
$post_data['headers'] = !empty($header) ? $header : $this->headers;
$client = new Client();
try {
$res = $client->request(strtoupper($method), $url, $post_data)->getBody()->getContents();
return (array)json_decode($res);
} catch (\Exception $e) {
return ["status"=>"fail","message"=>$e->getMessage()];
}
}
}