AyrShareController.php
5.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
<?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\AyrShareLogic;
use App\Http\Requests\Bside\AyrShare\AyrShareRequest;
use App\Models\AyrShare\AyrShare as AyrShareModel;
/**
* @name:社交绑定
*/
class AyrShareController extends BaseController
{
//生成名称前缀
const TITLE = 'globalso';
/**
* @name :(社交列表)lists
* @author :lyh
* @method :post
* @time :2023/5/5 16:06
*/
public function lists(AyrShareModel $ayrShareModel,AyrShareLogic $ayrShareLogic){
//授权配置列表
$share_list = $ayrShareModel->platforms;
$lists = $ayrShareModel->lists($this->map,$this->page,$this->row,'id',['id','name','title','profile_key','bind_platforms','operator_id','created_at','updated_at']);
foreach ($lists['list'] as $k => $v){
if(!empty($v['profile_key'])){
$ayrShareHelper = new AyrShareHelper();
$share_info = $ayrShareHelper->get_profiles_users($v['profile_key']);
if(isset($share_info['activeSocialAccounts'])){
$str = json_encode($share_info['activeSocialAccounts']);
if($str != $v['bind_platforms']){
$ayrShareLogic->ayr_share_edit(['bind_platforms'=>$str],$v['id']);
}
}else{
$ayrShareLogic->ayr_share_edit(['bind_platforms'=>''],$v['id']);
}
}
}
$lists['share_list'] = $share_list;
$this->response('列表',Code::SUCCESS,$lists);
}
/**
* @name :(定时更新)save_account
* @author :lyh
* @method :post
* @time :2023/5/9 14:39
*/
public function save_account(AyrShareLogic $ayrShareLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$info = $ayrShareLogic->ayr_share_info();
$ayrShareHelper = new AyrShareHelper();
$share_info = $ayrShareHelper->get_profiles_users($info['profile_key']);
if(isset($share_info['activeSocialAccounts'])){
$str = json_encode($share_info['activeSocialAccounts']);
if($str != $info['bind_platforms']){
$ayrShareLogic->ayr_share_edit(['bind_platforms'=>$str],$this->param['id']);
$res = true;
}else{
$res = false;
}
}else{
$ayrShareLogic->ayr_share_edit(['bind_platforms'=>''],$this->param['id']);
$res = true;
}
$this->response('success',Code::SUCCESS,['is_true'=>$res]);
}
/**
* @name :(创建ayr_share账户)create_account
* @author :lyh
* @method :post
* @time :2023/5/5 16:44
*/
public function create_account(AyrShareRequest $ayrShareRequest,AyrShareLogic $ayrShareLogic){
$ayrShareRequest->validated();
$param = [
'title'=>self::TITLE . ':' . $this->user['project_id'] . '-' . $this->param['name'],
];
//发送请求注册社交用户
$ayrShareHelper = new AyrShareHelper();
$res = $ayrShareHelper->post_create_profiles($param);
if($res['status'] == 'fail'){
$this->response('同步绑定失败');
}
//执行数据库操作
$ayrShareLogic->ayr_share_save($res);
$this->response('success');
}
/**
* @name :(删除用户账号并同步ayr_share账号)edit_account
* @author :lyh
* @method :post
* @time :2023/5/6 10:11
*/
public function del_account(AyrShareLogic $ayrShareLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $ayrShareLogic->ayr_share_info();
if(!empty($info['title'])){
$data = [
// 'title'=>$info['title'],
'profileKey'=>$info['profile_key']
];
//发送请求删除社交用户
$ayrShareHelper = new AyrShareHelper();
$res = $ayrShareHelper->deleted_profiles($data);
if($res['status'] == 'fail'){
$this->response('同步删除失败');
}
}
$ayrShareLogic->ayr_share_del();
$this->response('success');
}
/**
* @name :(授权绑定第三方平台,生成jwt令牌)ayr_share_bind
* @author :lyh
* @method :post
* @time :2023/5/6 10:24
*/
public function bind_account(AyrShareLogic $ayrShareLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $ayrShareLogic->ayr_share_info();
//发送请求注册社交用户
$ayrShareHelper = new AyrShareHelper();
$data = [
'profileKey'=>$info['profile_key']
];
$res = $ayrShareHelper->post_generate_jwt($data);
if($res['status'] == 'fail'){
$this->response($res['message'],Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS,$res);
}
}