AyrShareController.php 3.5 KB
<?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\Models\AyrShare\AyrShare as AyrShareModel;

/**
 * @name:社交绑定
 */
class AyrShareController extends BaseController
{
    /**
     * @name   :(社交列表)lists
     * @author :lyh
     * @method :post
     * @time   :2023/5/5 16:06
     */
    public function lists(AyrShareModel $ayrShareModel){
        $lists = $ayrShareModel->lists($this->map,$this->page,$this->row,'id',['*']);
        $this->response('列表',Code::SUCCESS,$lists);
    }

    /**
     * @name   :(定时更新)save_account
     * @author :lyh
     * @method :post
     * @time   :2023/5/9 14:39
     */
    public function save_account(AyrShareLogic $ayrShareLogic){
        $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']);
            $ayrShareLogic->ayr_share_edit(['bind_plat_from'=>$str]);
        }
        $this->response('success');
    }
    /**
     * @name   :(创建ayr_share账户)create_account
     * @author :lyh
     * @method :post
     * @time   :2023/5/5 16:44
     */
    public function create_account(AyrShareLogic $ayrShareLogic){
        $param = [
            'title'=>md5(uniqid().time()),
        ];
        //发送请求注册社交用户
        $ayrShareHelper = new AyrShareHelper();
        $res = $ayrShareHelper->post_create_profiles($param);
        if($res['status'] == 'fail'){
            $this->response('同步绑定失败');
        }
        //执行数据库操作
        $ayrShareLogic->ayr_share_add($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();
        $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);
    }

}