AyrShareController.php 4.0 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',['*']);
        $ayrShareHelper = new AyrShareHelper();
        foreach ($lists['list'] as  $k=>$v){
            $lists['list'][$k]['ayr'] = $ayrShareHelper->get_profiles_users($v['profile_key']);
        }
        $this->response('列表',Code::SUCCESS,$lists);
    }

    /**
     * @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);
    }

    /**
     * @name   :(获取当前用户的配置文件)get_profiles
     * @author :lyh
     * @method :post
     * @time   :2023/5/6 16:39
     */
    public function get_profiles(AyrShareLogic $ayrShareLogic){
        $this->request->validate([
            'id'=>['required']
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $info = $ayrShareLogic->ayr_share_info();
        //发送请求注册社交用户
        $ayrShareHelper = new AyrShareHelper();
        $data = [
            'title'=>$info['title'],
            'refId'=>$info['ref_id'],
            'profileKeys'=>$info['profile_keys']
        ];
        $res = $ayrShareHelper->post_generate_jwt($data);
        if($res['status'] == 'fail'){
            $this->response($res['message'],Code::USER_ERROR);
        }
        $this->response('success',Code::SUCCESS,$res);
    }
}