On this page
用户绑定上线
控制器层:application\api\v1\Chat.php
php
// 绑定上线
public function bind(Request $request){
//{type:"bind",client_id:"7f0000010b5700000001"}';
// 验证当前用户是否绑定手机号,状态等信息,验证数据合法性
(new ChatValidate)->goCheck('bind');
$userId = $request->userId;
$client_id = $request->client_id;
// 验证client_id合法性
if (!Gateway::isOnline($client_id)) return TApiException('clientId不合法');
// 验证当前客户端是否已经绑定
if (Gateway::getUidByClientId($client_id)) return TApiException('已被绑定');
// 直接绑定
Gateway::bindUid($request->client_id,$userId);
// 返回成功
return self::showResCode('绑定成功',['type'=>'bind','status'=>true]);
}
验证器层:application\common\validate\ChatValidate
php
protected $rule = [
...
'client_id'=>'require'
];
protected $scene = [
'bind'=>['type','client_id']
];
路由层:route\route.php
php
// socket 部分
Route::group('api/:v1/',function(){
...
// 绑定上线
Route::post('chat/bind','api/:v1.Chat/bind');
})->middleware(['ApiUserAuth','ApiUserBindPhone','ApiUserStatus']);