This commit is contained in:
commie
2026-02-27 13:53:53 +08:00
parent c9c8a120ab
commit d75fea32f7
25 changed files with 847 additions and 359 deletions
+5 -5
View File
@@ -264,6 +264,7 @@ class CommonController extends BaseController{
* *
* @Apidoc\Method ("POST") * @Apidoc\Method ("POST")
* @Apidoc\Param("email", type="string",require=true, desc="邮箱") * @Apidoc\Param("email", type="string",require=true, desc="邮箱")
* @Apidoc\Param("mobile", type="string",require=true, desc="手机号")
* @Apidoc\Param("newpassword", type="string",require=true, desc="新密码") * @Apidoc\Param("newpassword", type="string",require=true, desc="新密码")
* @Apidoc\Param("code", type="string",require=true, desc="邮箱验证码,event=resetpwd") * @Apidoc\Param("code", type="string",require=true, desc="邮箱验证码,event=resetpwd")
*/ */
@@ -347,13 +348,12 @@ class CommonController extends BaseController{
captcha_verfiy('mobile','reset_trade_pwd',$user->mobile); captcha_verfiy('mobile','reset_trade_pwd',$user->mobile);
} }
}else{ }else{
if ($email && Validate::is($email, "email")) {
captcha_verfiy('email','reset_trade_pwd',$email);
$user = UserModel::getByEmail($email);
}
if ($mobile && Validate::regex($mobile, "^1\d{10}$")) { if ($mobile && Validate::regex($mobile, "^1\d{10}$")) {
captcha_verfiy('mobile','reset_trade_pwd',$mobile); captcha_verfiy('mobile','reset_trade_pwd',$mobile);
$user = UserModel::getByMobile($mobile); $user = UserModel::getByMobile($mobile);
}elseif ($email && Validate::is($email, "email")) {
captcha_verfiy('email','reset_trade_pwd',$email);
$user = UserModel::getByEmail($email);
} }
} }
if (!$user) { if (!$user) {
@@ -379,7 +379,7 @@ class CommonController extends BaseController{
* @Apidoc\Param("email", type="string",require=true, desc="邮箱,可选") * @Apidoc\Param("email", type="string",require=true, desc="邮箱,可选")
*/ */
public function captcha(Request $request){ public function captcha(Request $request){
$debug = true; $debug = false;
$request->input('type'); $request->input('type');
$type = $request->input('type'); $type = $request->input('type');
$event = $request->input('event'); $event = $request->input('event');
+2 -1
View File
@@ -27,7 +27,8 @@ class UserController extends BaseController{
public $noNeedLogin = []; public $noNeedLogin = [];
/** /**
* @Apidoc\Title("个人资料") * @Apidoc\Title("个人资料")
* @Apidoc\Method("GET") * @Apidoc\Method("GET","POST")
* @Apidoc\Tag("常用")
* @Apidoc\Desc("GET为获取用户信息,POST为修改数据") * @Apidoc\Desc("GET为获取用户信息,POST为修改数据")
* @Apidoc\Param("nickname", type="string",require=true, desc="昵称") * @Apidoc\Param("nickname", type="string",require=true, desc="昵称")
*/ */
+41 -8
View File
@@ -13,6 +13,7 @@ class OpenIm extends Command
{ {
protected static $defaultName = 'openim'; protected static $defaultName = 'openim';
protected static $defaultDescription = 'OpenIm'; protected static $defaultDescription = 'OpenIm';
public $sdk= null;
/** /**
* @return void * @return void
@@ -37,23 +38,18 @@ class OpenIm extends Command
if(method_exists($this, $action)){ if(method_exists($this, $action)){
return $this->$action($input, $output); return $this->$action($input, $output);
} }
$output->writeln($action.'不存在');
return self::FAILURE; return self::FAILURE;
} }
private function change_user(InputInterface $input, OutputInterface $output):int{ private function change_user(InputInterface $input, OutputInterface $output):int{
$im = new \support\OpenImSdk\Client([ $im = $this->getSdk();
'host' => 'http://127.0.0.1:10002', // OpenIM API地址
'secret' => 'n1e5a6s6m7', // OpenIM密钥
]);
$data = $im->user->updateUserInfo(idEncode('100006'),['userInfo'=>['userId'=>'wx100001']]); $data = $im->user->updateUserInfo(idEncode('100006'),['userInfo'=>['userId'=>'wx100001']]);
cp($data); cp($data);
return self::SUCCESS; return self::SUCCESS;
} }
private function sync_users(InputInterface $input, OutputInterface $output):int{ private function sync_users(InputInterface $input, OutputInterface $output):int{
$im = new \support\OpenImSdk\Client([ $im = $this->getSdk();
'host' => 'http://127.0.0.1:10002', // OpenIM API地址
'secret' => 'n1e5a6s6m7', // OpenIM密钥
]);
$data = $im->user->getAllUsersUid(1,1000); $data = $im->user->getAllUsersUid(1,1000);
cp($data); cp($data);
return self::SUCCESS; return self::SUCCESS;
@@ -82,4 +78,41 @@ class OpenIm extends Command
} }
return self::SUCCESS; return self::SUCCESS;
} }
function sync_cache(){
$res = \app\model\Openim\Group::field('group_id,creator_user_id')->select();
$group_create = [];
foreach($res as $v){
if(!isset($group_create[$v['creator_user_id']])){
$group_create[$v['creator_user_id']] = 0;
}
if($v['status'] != 2){
$group_create[$v['creator_user_id']]+=1;
}
cache('group_owner_'.$v['group_id'],$v['creator_user_id']);
$group_user_count = \app\model\Openim\GroupMember::field('group_id,count(*) as count')
->where('group_id',$v['group_id'])
->count('user_id');
cp('群组数量',$v['group_id'],'成员数量:',$group_user_count);
cache('group_'.$v['group_id'].'_user_count',$group_user_count);
}
//cp($group_create);
foreach($group_create as $userId =>$count){
cp('用户:',$userId,'创建群组数量:',$count);
cache('user_'.$userId.'_create_group_count',$count);
}
return 0;
}
function getSdk(){
if($this->sdk){
return $this->sdk;
}
$this->sdk = new \support\OpenImSdk\Client([
'host' => 'http://127.0.0.1:10002', // OpenIM API地址
'secret' => 'n1e5a6s6m7', // OpenIM密钥
]);
return $this->sdk;
}
} }
+181 -319
View File
@@ -5,19 +5,14 @@ use support\Response;
use think\facade\Db; use think\facade\Db;
use app\model\User as UserModel; use app\model\User as UserModel;
class HookController{ class HookController{
public $sdk = null;
function index(){ function index(){
return 'ok'; return 'ok';
} }
function __call($method, $args):Response function __call($method, $args):Response
{ {
//log_alert(Input()); //log_alert(Input());
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
//用户注册完成后 //用户注册完成后
function callbackAfterUserRegisterCommand(Request $request): Response function callbackAfterUserRegisterCommand(Request $request): Response
@@ -38,25 +33,16 @@ class HookController{
// 'createTime' => 0, // 'createTime' => 0,
// 'appMangerLevel' => 0, // 'appMangerLevel' => 0,
// 'globalRecvMsgOpt' => 0, // 'globalRecvMsgOpt' => 0,
$im->message->sendBusinessNotification('official_team',idEncode($v['userID']),[ $im->message->sendBusinessNotification('official_team',$v['userID'],[
'contentType' => 101, 'contentType' => 101,
'textElem' => [ 'textElem' => [
'content' => '欢迎使用'.Config('site.name') 'content' => '欢迎使用'.Config('site.name')
] ]
]); ]);
} }
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/** //在发送单聊消息前的回调
* 在发送单聊消息前的回调
* @return void
*/
public function callbackBeforeSendSingleMsgCommand(Request $request): Response public function callbackBeforeSendSingleMsgCommand(Request $request): Response
{ {
//log_alert(Input()); //log_alert(Input());
@@ -68,30 +54,16 @@ class HookController{
// if($status == 1 && $sessionType != 4){ // if($status == 1 && $sessionType != 4){
// //$max = 10000000000;//限制消息数量 // //$max = 10000000000;//限制消息数量
// $user_rights = get_user_rights($user_id); // $user_rights = get_user_rights($user_id);
// $max = $user_rights['max_send_msg_count']; // $max = $user_rights['right']['max_send_msg_count'];
// $sended_msg_count = cache('single_msg_count_'.$user_id)??0 + cache('group_msg_count_'.$user_id)??0; // $sended_msg_count = cache('single_msg_count_'.$user_id)??0 + cache('group_msg_count_'.$user_id)??0;
// if($sended_msg_count > $max){ // if($sended_msg_count > $max){
// return json([ // return $this->error(1002,'超出消息数量限制,请先开通或升级会员');
// "actionCode" => 0,
// "errCode" => 1002,
// "errMsg" => "超出消息数量限制,请先开通或升级会员",
// "errDlt" => "超出消息数量限制,请先开通或升级会员",
// "nextCode"=> 1
// ]);
// } // }
// } // }
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/**
* 发送单聊消息后的回调 //发送单聊消息后的回调
* @return void
*/
public function callbackAfterSendSingleMsgCommand(Request $request): Response public function callbackAfterSendSingleMsgCommand(Request $request): Response
{ {
@@ -109,76 +81,37 @@ class HookController{
} }
cache_add($key,1); cache_add($key,1);
} }
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/**
* 发送群聊消息前的回调 //发送群聊消息前的回调
* @return void
*/
public function callbackBeforeSendGroupleMsgCommand(Request $request): Response public function callbackBeforeSendGroupleMsgCommand(Request $request): Response
{ {
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/**
* 发送群聊消息后的回调 //发送群聊消息后的回调
* @return void
*/
public function callbackAfterSendGroupleMsgCommand(Request $request): Response public function callbackAfterSendGroupleMsgCommand(Request $request): Response
{ {
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/** //发送好友申请之前的回调
* 发送好友申请之前的回调
* @return void
*/
public function callbackBeforeAddFriendCommand(Request $request): Response{ public function callbackBeforeAddFriendCommand(Request $request): Response{
$from_user_id = Input('fromUserID'); // $from_user_id = Input('fromUserID');
$to_user_id = Input('toUserID'); // $to_user_id = Input('toUserID');
$handleResult = Input('handleResult'); // $handleResult = Input('handleResult');
$key = 'friend_count_'.$from_user_id; // $key = 'friend_count_'.$from_user_id;
$user_rights = get_user_rights($from_user_id); // $user_rights = get_user_rights($from_user_id);
$max = isset($user_rights['max_friend_count']) ? $user_rights['max_friend_count'] : -1; // $max = isset($user_rights['right']['max_friend_count']) ? $user_rights['right']['max_friend_count'] : -1;
if(cache($key) > $max){ // if(cache($key) > $max){
return json([
"actionCode" => 0, // return $this->error(1001,'超出好友数量限制,请先开通或升级会员');
"errCode" => 1001, // }
"errMsg" => "超出好友数量限制,请先开通或升级会员", return $this->success();
"errDlt" => "超出好友数量限制,请先开通或升级会员",
"nextCode" => 1
]);
}
return json([
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/** //发送好友申请之后的回调
* 发送好友申请之后的回调
* @return void
*/
public function callbackAfterAddFriendCommand(Request $request): Response public function callbackAfterAddFriendCommand(Request $request): Response
{ {
@@ -186,95 +119,46 @@ class HookController{
$to_user_id = Input('toUserID'); $to_user_id = Input('toUserID');
cache_add('friend_count_'.$to_user_id,1); cache_add('friend_count_'.$to_user_id,1);
cache_add('friend_count_'.$from_user_id,1); cache_add('friend_count_'.$from_user_id,1);
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/** //在添加好友对方同意之前的回调
* 在添加好友对方同意之前的回调
* @return void
*/
public function callbackBeforeAddFriendAgreeCommand(Request $request): Response public function callbackBeforeAddFriendAgreeCommand(Request $request): Response
{ {
$from_user_id = Input('fromUserID'); // $from_user_id = Input('fromUserID');
$to_user_id = Input('toUserID'); // $to_user_id = Input('toUserID');
$handleResult = Input('handleResult'); // $handleResult = Input('handleResult');
if($handleResult == 1){ // if($handleResult == 1){
$key = 'friend_count_'.$to_user_id; // $key = 'friend_count_'.$to_user_id;
$user_rights = get_user_rights($to_user_id); // $user_rights = get_user_rights($to_user_id);
$max = isset($user_rights['max_friend_count']) ? $user_rights['max_friend_count'] : -1; // $max = isset($user_rights['right']['max_friend_count']) ? $user_rights['right']['max_friend_count'] : -1;
if(cache($key) > $max){ // if(cache($key) > $max){
return json([ // return $this->error(1001,'超出好友数量限制,请先开通或升级会员');
"actionCode" => 0, // }
"errCode" => 1001, // }
"errMsg" => "超出好友数量限制,请先开通或升级会员", return $this->success();
"errDlt" => "超出好友数量限制,请先开通或升级会员",
"nextCode"=> 1
]);
}
}
return json([
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/**
* 在添加好友对方同意之的回调 //在添加好友对方同意之的回调
* @param Request $request
* @return void
*/
public function callbackAfterAddFriendAgreeCommand(Request $request):Response public function callbackAfterAddFriendAgreeCommand(Request $request):Response
{ {
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/** //用户在线状态回调
* 用户在线状态回调
* @return void
*/
public function callbackAfterUserOnlineCommand(Request $request): Response public function callbackAfterUserOnlineCommand(Request $request): Response
{ {
$user_id = Input('userID'); $user_id = Input('userID');
//Db::name('user')->where('id',$user_id)->update(['online'=>1]); return $this->success();
return json([
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/** //用户离线状态回调
* 用户离线状态回调
* @return void
*/
public function callbackAfterUserOfflineCommand(Request $request): Response{ public function callbackAfterUserOfflineCommand(Request $request): Response{
$user_id = Input('userID'); $user_id = Input('userID');
//Db::name('user')->where('id',$user_id)->update(['online'=>0]); //Db::name('user')->where('id',$user_id)->update(['online'=>0]);
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
//用户删除好友之后得回调 //用户删除好友之后得回调
function callbackAfterDeleteFriendCommand() : Response { public function callbackAfterDeleteFriendCommand(Request $request): Response {
$friendUserID = Input('friendUserID'); $friendUserID = Input('friendUserID');
$ownerUserID = Input('ownerUserID'); $ownerUserID = Input('ownerUserID');
$sdk = $this->getSdk(); $sdk = $this->getSdk();
@@ -287,212 +171,161 @@ class HookController{
$this->getSdk()->friend->deleteFriend($ownerUserID,$friendUserID); $this->getSdk()->friend->deleteFriend($ownerUserID,$friendUserID);
} }
} }
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/** //在创建群组之前的回调
* 在创建群组之前的回调 //执行顺序,callbackBeforeCreateGroupCommand -> callbackBeforeMembersJoinGroupCommand -> callbackAfterCreateGroupCommand
* @return void
*/
public function callbackbeforeCreateGroupCommand(Request $request): Response public function callbackbeforeCreateGroupCommand(Request $request): Response
{ {
$from_user_id = Input('fromUserID'); $groupID = Input('groupID');
$to_user_id = Input('toUserID'); $creatorUserID = Input('creatorUserID');
$handleResult = Input('handleResult'); $key = 'user_'.$creatorUserID.'_create_group_count';
if($handleResult == 1){ $user_rights = get_user_rights($creatorUserID);
$key = 'friend_count_'.$to_user_id; $max_group_create_count = isset($user_rights['right']['max_group_create_count']) ? $user_rights['right']['max_group_create_count'] : -1;
$user_rights = get_user_rights($to_user_id); if(cache($key) > $max_group_create_count){
$max = isset($user_rights['max_friend_count']) ? $user_rights['max_friend_count'] : -1; return $this->error(2001,'超出创建群组数量限制,请先开通或升级会员');
if(cache($key) > $max){
return json([
"actionCode" => 0,
"errCode" => 1001,
"errMsg" => "超出好友数量限制,请先开通或升级会员",
"errDlt" => "超出好友数量限制,请先开通或升级会员",
"nextCode"=> 1
]);
}
} }
return json([ $max_group_user = $user_rights['right']['max_group_user_count'];
"actionCode" => 0, if(count(Input('initMemberList')) > $max_group_user){
"errCode" => 0, return $this->error(2002,'超出群组成员数量限制,请先开通或升级会员');
"errMsg" => "", }
"errDlt" => "", return $this->success();
"nextCode"=> 0
]);
} }
/** //在创建群组之后的回调
* 在创建群组之后的回调
* @param Request $request
* @return void
*/
public function callbackafterCreateGroupCommand(Request $request):Response public function callbackafterCreateGroupCommand(Request $request):Response
{ {
return json([ $groupID = Input('groupID');
"actionCode" => 0, $creatorUserID = Input('creatorUserID');
"errCode" => 0, cache_add('user_'.$creatorUserID.'_create_group_count',1);
"errMsg" => "", //增加群组用户数量缓存
"errDlt" => "", cache_add('group_'.$groupID.'_user_count',count(Input('initMemberList')));
"nextCode"=> 0 return $this->success();
]);
} }
/** //转让群主之后的回调
* 转让群主之后的回调
* @param Request $request
* @return void
*/
public function callbackAfterTransferGroupOwnerCommand(Request $request):Response public function callbackAfterTransferGroupOwnerCommand(Request $request):Response
{ {
$oldOwnerUserID = Input('oldOwnerUserID'); $oldOwnerUserID = Input('oldOwnerUserID');
$newOwnerUserID = Input('newOwnerUserID'); $newOwnerUserID = Input('newOwnerUserID');
$groupID = Input('groupID');
cache_add('user_'.$oldOwnerUserID.'_create_group_count',-1); cache_add('user_'.$oldOwnerUserID.'_create_group_count',-1);
cache_add('user_'.$newOwnerUserID.'_create_group_count',1); cache_add('user_'.$newOwnerUserID.'_create_group_count',1);
return json([ cache_add('group_owner_'.$groupID,$newOwnerUserID);
"actionCode" => 0, return $this->success();
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
//解散群组后回调
/**
* 解散群组后回调
* @param Request $request
* @return void
*/
public function callbackAfterDisMissGroupCommand(Request $request):Response public function callbackAfterDisMissGroupCommand(Request $request):Response
{ {
$groupID = Input('groupID'); $groupID = Input('groupID');
$ownerID = Input('ownerID'); $ownerID = Input('ownerID');
return json([ //减少群主创建群组数量缓存
"actionCode" => 0, cache_add('user_'.$ownerID.'_create_group_count',-1);
"errCode" => 0, //删除群组用户数量缓存
"errMsg" => "", cache('group_'.$groupID.'_user_count',null);
"errDlt" => "", //删除群组群主缓存
"nextCode"=> 0 cache('group_owner_'.$groupID,null);
]); return $this->success();
} }
/** //用户退出群组的回调
* 用户退出群组的回调
* @param Request $request
* @return void
*/
public function callbackAfterQuitGroupCommand(Request $request):Response public function callbackAfterQuitGroupCommand(Request $request):Response
{ {
$groupID = Input('groupID'); $groupID = Input('groupID');
$userID = Input('userID'); $userID = Input('userID');
cache_add('user_'.$userID.'_join_group_count',-1); // //减少用户加入群组数量缓存
// cache_add('user_'.$userID.'_join_group_count',-1);
//减少群组用户数量缓存
cache_add('group_'.$groupID.'_user_count',-1); cache_add('group_'.$groupID.'_user_count',-1);
return json([ return $this->success();
"actionCode" => 0,
"errCode" => 0,
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/** //群成员进群之前的回调
* 群成员进群之前的回调
* @param Request $request
* @return void
*/
public function callbackBeforeMembersJoinGroupCommand(Request $request):Response public function callbackBeforeMembersJoinGroupCommand(Request $request):Response
{ {
$groupID = Input('groupID'); $groupID = Input('groupID');
$memberList = Input('memberList'); $memberList = Input('memberList');
return json([ $ownerID = $this->getGroupOwner($groupID);
"actionCode" => 0, //获取群组当前用户数量
"errCode" => 0, $group_user_count = cache('group_'.$groupID.'_user_count');
"errMsg" => "", if($group_user_count === null){
"errDlt" => "", $group_user_count = 0;
"nextCode"=> 0 }
]); //获取群组最大用户数量
$max_group_user = get_user_rights($ownerID)['right']['max_group_user_count'];
if((count($memberList) + $group_user_count) > $max_group_user){
return $this->error(2003,'超出群组成员数量限制,请先开通或升级会员');
}
return $this->success();
} }
/** //踢除群组成员的回调
* 踢除群组成员的回调
* @param Request $request
* @return void
*/
public function callbackAfterKickGroupCommand(Request $request):Response public function callbackAfterKickGroupCommand(Request $request):Response
{ {
$groupID = Input('groupID'); $groupID = Input('groupID');
$kickedUserIDs = Input('kickedUserIDs'); $kickedUserIDs = Input('kickedUserIDs');
return json([ //减少群组用户数量缓存
"actionCode" => 0, cache_add('group_'.$groupID.'_user_count',-count($kickedUserIDs));
"errCode" => 0, // foreach($kickedUserIDs as $kickedUserID){
"errMsg" => "", // //减少用户加入群组数量缓存
"errDlt" => "", // cache_add('user_'.$kickedUserID.'_join_group_count',-1);
"nextCode"=> 0 // }
]); return $this->success();
} }
/** //新成员加入群组之后的回调
* 新成员加入群组之后的回调
* @param Request $request
* @return void
*/
public function callbackAfterJoinGroupCommand(Request $request):Response public function callbackAfterJoinGroupCommand(Request $request):Response
{ {
$groupID = Input('groupID'); $groupID = Input('groupID');
$userID = Input('userID'); $userID = Input('userID');
cache_add('user_'.$userID.'_join_group_count',-1); // //增加用户加入群组数量缓存
cache_add('group_'.$groupID.'_user_count',-1); // cache_add('user_'.$userID.'_join_group_count',1);
return json([ //增加群组用户数量缓存
"actionCode" => 0, cache_add('group_'.$groupID.'_user_count',1);
"errCode" => 0, return $this->success();
"errMsg" => "",
"errDlt" => "",
"nextCode"=> 0
]);
} }
/** //邀请新成员加入群组之前的回调
* 邀请新成员加入群组之前的回调 //执行顺序,callbackBeforeInviteJoinGroupCommand -> callbackBeforeMembersJoinGroupCommand
* @param Request $request
* @return void
*/
public function callbackBeforeInviteJoinGroupCommand(Request $request):Response public function callbackBeforeInviteJoinGroupCommand(Request $request):Response
{ {
$groupID = Input('groupID'); $groupID = Input('groupID');
$invitedUserIDs = Input('invitedUserIDs'); $invitedUserIDs = Input('invitedUserIDs');
return json([ //获取群组当前用户数量
"actionCode" => 0, $group_user_count = cache('group_'.$groupID.'_user_count');
"errCode" => 0, if($group_user_count === null){
"errMsg" => "", $group_user_count = 0;
"errDlt" => "", }
"nextCode"=> 0 //获取群组最大用户数量
]); $max_group_user = get_user_rights($this->getGroupOwner($groupID))['right']['max_group_user_count'];
if((count($invitedUserIDs) + $group_user_count) > $max_group_user){
return $this->error(2003,'超出群组成员数量限制,请先开通或升级会员');
}
return $this->success();
} }
/** //申请加入群组之前的回调
* 申请加入群组之前的回调
* @param Request $request
* @return void
*/
public function callbackBeforeJoinGroupCommand(Request $request):Response public function callbackBeforeJoinGroupCommand(Request $request):Response
{ {
$groupID = Input('groupID'); $groupID = Input('groupID');
$applyID = Input('applyID'); $applyID = Input('applyID');
return json([ //获取群组当前用户数量
"actionCode" => 0, $group_user_count = cache('group_'.$groupID.'_user_count')?:0;
"errCode" => 0, //获取群组最大用户数量
"errMsg" => "", $max_group_user = get_user_rights($this->getGroupOwner($groupID))['right']['max_group_user_count'];
"errDlt" => "", if((1 + $group_user_count) > $max_group_user){
"nextCode"=> 0 return $this->error(2003,'群组已经满员');
]); }
// //获取用户加入群组数量限制
// $max_group_join_count = get_user_rights($applyID)['right']['max_group_join_count'];
// //获取用户加入群组数量
// $user_join_group_count = cache('user_'.$applyID.'_join_group_count')?:0;
// if((1 + $user_join_group_count) > $max_group_join_count){
// return $this->error(2004,'超出加入群组数量限制,请先开通或升级会员');
// }
return $this->success();
} }
@@ -501,14 +334,43 @@ class HookController{
function getGroupOwner($groupID=''){
$result = cache('group_owner_'.$groupID);
if($result){
return $result;
}
$groupsInfo = $this->getSdk()->group->getGroupsInfo([$groupID]);
foreach($groupsInfo['groupInfos'] as $groupInfo){
if($groupInfo['groupID'] == $groupID){
cache('group_owner_'.$groupID,$groupInfo['ownerUserID']);
return $groupInfo['ownerUserID'];
}
}
return '';
}
function result($code,$msg,$nextCode=0){
return json([
"actionCode" => 0,
"errCode" => $code,
"errMsg" => $msg,
"errDlt" => $msg,
"nextCode"=> $nextCode
]);
}
function success(){
return $this->result(0,"");
}
function error($errCode=0,$errMsg='',$nextCode=1){
return $this->result($errCode,$errMsg,$nextCode);
}
function getSdk(){ function getSdk(){
$IM = new \support\OpenImSdk\Client([ if($this->sdk){
return $this->sdk;
}
$this->sdk = new \support\OpenImSdk\Client([
'host' => 'http://127.0.0.1:10002', // OpenIM API地址 'host' => 'http://127.0.0.1:10002', // OpenIM API地址
'secret' => 'n1e5a6s6m7', // OpenIM密钥 'secret' => 'n1e5a6s6m7', // OpenIM密钥
]); ]);
return $IM; return $this->sdk;
} }
} }
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $owner_user_id
* @property string $block_user_id
* @property datetime $create_time
* @property int $add_source
* @property string $operator_user_id
* @property string $ex
*/
class Black extends \app\model\Base
{
protected $table = 'black';
protected $schema = [
'owner_user_id' => 'string',
'block_user_id' => 'string',
'create_time' => 'datetime',
'add_source' => 'int',
'operator_user_id' => 'string',
'ex' => 'string',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $key
* @property string $value
* @property string $description
* @property datetime $create_time
* @property datetime $update_time
*/
class Config extends \app\model\Base
{
protected $table = 'config';
protected $schema = [
'key' => 'string',
'value' => 'string',
'description' => 'string',
'create_time' => 'datetime',
'update_time' => 'datetime',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $owner_user_id
* @property string $conversation_id
* @property int $conversation_type
* @property string $user_id
* @property string $group_id
* @property int $recv_msg_opt
* @property bool $is_pinned
* @property bool $is_private_chat
* @property int $burn_duration
* @property int $group_at_type
* @property string $attached_info
* @property string $ex
* @property int $max_seq
* @property int $min_seq
* @property datetime $create_time
* @property bool $is_msg_destruct
* @property int $msg_destruct_time
* @property datetime $latest_msg_destruct_time
*/
class Conversation extends \app\model\Base
{
protected $table = 'conversation';
protected $schema = [
'owner_user_id' => 'string',
'conversation_id' => 'string',
'conversation_type' => 'int',
'user_id' => 'string',
'group_id' => 'string',
'recv_msg_opt' => 'int',
'is_pinned' => 'bool',
'is_private_chat' => 'bool',
'burn_duration' => 'int',
'group_at_type' => 'int',
'attached_info' => 'string',
'ex' => 'string',
'max_seq' => 'int',
'min_seq' => 'int',
'create_time' => 'datetime',
'is_msg_destruct' => 'bool',
'msg_destruct_time' => 'int',
'latest_msg_destruct_time' => 'datetime',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $d_id
* @property array $logs
* @property int $version
* @property bool $deleted
* @property datetime $last_update
*/
class ConversationVersion extends \app\model\Base
{
protected $table = 'conversation_version';
protected $schema = [
'd_id' => 'string',
'logs' => 'array',
'version' => 'int',
'deleted' => 'bool',
'last_update' => 'datetime',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $key
* @property string $value
*/
class DataVersion extends \app\model\Base
{
protected $table = 'data_version';
protected $schema = [
'key' => 'string',
'value' => 'string',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $friend_id
* @property string $owner_user_id
* @property string $friend_user_id
* @property string $remark
* @property datetime $create_time
* @property int $add_source
* @property string $operator_user_id
* @property string $ex
* @property bool $is_pinned
*/
class Friend extends \app\model\Base
{
protected $table = 'friend';
protected $schema = [
'owner_user_id' => 'string',
'friend_user_id' => 'string',
'remark' => 'string',
'create_time' => 'datetime',
'add_source' => 'int',
'operator_user_id' => 'string',
'ex' => 'string',
'is_pinned' => 'bool',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $from_user_id
* @property string $to_user_id
* @property int $handle_result
* @property string $req_msg
* @property datetime $create_time
* @property string $handler_user_id
* @property string $handle_msg
* @property datetime $handle_time
* @property string $ex
*/
class FriendRequest extends \app\model\Base
{
protected $table = 'friend_request';
protected $schema = [
'from_user_id' => 'string',
'to_user_id' => 'string',
'handle_result' => 'int',
'req_msg' => 'string',
'create_time' => 'datetime',
'handler_user_id' => 'string',
'handle_msg' => 'string',
'handle_time' => 'datetime',
'ex' => 'string',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $d_id
* @property array $logs
* @property int $version
* @property bool $deleted
* @property datetime $last_update
*/
class FriendVersion extends \app\model\Base
{
protected $table = 'friend_version';
protected $schema = [
'd_id' => 'string',
'logs' => 'array',
'version' => 'int',
'deleted' => 'bool',
'last_update' => 'datetime',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $group_id
* @property string $group_name
* @property string $notification
* @property string $introduction
* @property string $face_url
* @property datetime $create_time
* @property string $ex
* @property int $status
* @property string $creator_user_id
* @property int $group_type
* @property int $need_verification
* @property int $look_member_info
* @property int $apply_member_friend
* @property datetime $notification_update_time
* @property string $notification_user_id
*/
class Group extends \app\model\Base
{
protected $table = 'group';
protected $schema = [
'group_id' => 'string',
'group_name' => 'string',
'notification' => 'string',
'introduction' => 'string',
'face_url' => 'string',
'create_time' => 'datetime',
'ex' => 'string',
'status' => 'int',
'creator_user_id' => 'string',
'group_type' => 'int',
'need_verification' => 'int',
'look_member_info' => 'int',
'apply_member_friend' => 'int',
'notification_update_time' => 'datetime',
'notification_user_id' => 'string',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $d_id
* @property array $logs
* @property int $version
* @property bool $deleted
* @property datetime $last_update
*/
class GroupJoinVersion extends \app\model\Base
{
protected $table = 'group_join_version';
protected $schema = [
'd_id' => 'string',
'logs' => 'array',
'version' => 'int',
'deleted' => 'bool',
'last_update' => 'datetime',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $group_id
* @property string $user_id
* @property string $nickname
* @property string $face_url
* @property int $role_level
* @property datetime $join_time
* @property int $join_source
* @property string $inviter_user_id
* @property string $operator_user_id
* @property datetime $mute_end_time
* @property string $ex
*/
class GroupMember extends \app\model\Base
{
protected $table = 'group_member';
protected $schema = [
'group_id' => 'string',
'user_id' => 'string',
'nickname' => 'string',
'face_url' => 'string',
'role_level' => 'int',
'join_time' => 'datetime',
'join_source' => 'int',
'inviter_user_id' => 'string',
'operator_user_id' => 'string',
'mute_end_time' => 'datetime',
'ex' => 'string',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $d_id
* @property array $logs
* @property int $version
* @property bool $deleted
* @property datetime $last_update
*/
class GroupMemberVersion extends \app\model\Base
{
protected $table = 'group_member_version';
protected $schema = [
'd_id' => 'string',
'logs' => 'array',
'version' => 'int',
'deleted' => 'bool',
'last_update' => 'datetime',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $user_id
* @property string $group_id
* @property int $handle_result
* @property string $req_msg
* @property string $handled_msg
* @property datetime $req_time
* @property string $handle_user_id
* @property datetime $handled_time
* @property int $join_source
* @property string $inviter_user_id
* @property string $ex
* @property string $handle_msg
*/
class GroupRequest extends \app\model\Base
{
protected $table = 'group_request';
protected $schema = [
'user_id' => 'string',
'group_id' => 'string',
'handle_result' => 'int',
'req_msg' => 'string',
'handled_msg' => 'string',
'req_time' => 'datetime',
'handle_user_id' => 'string',
'handled_time' => 'datetime',
'join_source' => 'int',
'inviter_user_id' => 'string',
'ex' => 'string',
'handle_msg' => 'string',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $level
* @property string $message
* @property array $context
* @property array $extra
* @property datetime $timestamp
*/
class Log extends \app\model\Base
{
protected $table = 'log';
protected $schema = [
'level' => 'string',
'message' => 'string',
'context' => 'array',
'extra' => 'array',
'timestamp' => 'datetime',
];
protected function getOptions(): array
{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $doc_id
* @property array $msgs
*/
class Msg extends \app\model\Base
{
protected $table = 'msg';
protected $schema = [
'doc_id' => 'string',
'msgs' => 'array',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $engine
* @property string $name
* @property string $content_type
* @property datetime $create_time
* @property string $group
* @property string $key
* @property int $size
*/
class S3 extends \app\model\Base
{
protected $table = 's3';
protected $schema = [
'engine' => 'string',
'name' => 'string',
'content_type' => 'string',
'create_time' => 'datetime',
'group' => 'string',
'key' => 'string',
'size' => 'int',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $conversation_id
* @property int $max_seq
* @property int $min_seq
*/
class Seq extends \app\model\Base
{
protected $table = 'seq';
protected $schema = [
'conversation_id' => 'string',
'max_seq' => 'int',
'min_seq' => 'int',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $conversation_id
* @property string $user_id
* @property int $max_seq
* @property int $min_seq
* @property int $read_seq
*/
class SeqUser extends \app\model\Base
{
protected $table = 'seq_user';
protected $schema = [
'conversation_id' => 'string',
'user_id' => 'string',
'max_seq' => 'int',
'min_seq' => 'int',
'read_seq' => 'int',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace app\model\Openim;
use think\Model;
/**
* @property string $user_id
* @property string $nickname
* @property string $face_url
* @property string $ex
* @property int $app_manger_level
* @property int $global_recv_msg_opt
* @property datetime $create_time
*/
class User extends \app\model\Base
{
protected $table = 'user';
protected $schema = [
'user_id' => 'string',
'nickname' => 'string',
'face_url' => 'string',
'ex' => 'string',
'app_manger_level' => 'int',
'global_recv_msg_opt' => 'int',
'create_time' => 'datetime',
];
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'connection' => 'immongodb',
]);
}
}
+1 -1
View File
@@ -15,7 +15,7 @@
use support\Request; use support\Request;
return [ return [
'debug' => \support\Env::get('app.debug',false), 'debug' => false,
'error_reporting' => E_ALL & ~E_WARNING, 'error_reporting' => E_ALL & ~E_WARNING,
'default_timezone' => 'Asia/Shanghai', 'default_timezone' => 'Asia/Shanghai',
'request_class' => Request::class, 'request_class' => Request::class,
+18 -25
View File
@@ -28,31 +28,6 @@ return [
// 自定义分页类 // 自定义分页类
'bootstrap' => '' 'bootstrap' => ''
], ],
'immysql' => [
// 数据库类型
'type' => 'mysql',
'hostname' => '172.17.0.2',
'hostport' => \support\Env::get('mysql.port','3306'),
'database' => 'im',
'username' => 'root',
'password' => 'n1e5a6s6m7',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'prefix' => \support\Env::get('mysql.prefix','wa_'),
// 数据库连接参数
'params' => [
\PDO::ATTR_TIMEOUT => 3,// 连接超时3秒
\PDO::ATTR_PERSISTENT => true //设置是否使用持久化连接。
],
// 开启字段缓存
'fields_cache' => true,
// 断线重连
'break_reconnect' => true,
// 关闭SQL监听日志
'trigger_sql' => true,
// 自定义分页类
'bootstrap' => ''
],
'mongodb' => [ 'mongodb' => [
'type' => 'mongo', 'type' => 'mongo',
'hostname' => \support\Env::get('mongodb.host','127.0.0.1'), 'hostname' => \support\Env::get('mongodb.host','127.0.0.1'),
@@ -69,6 +44,24 @@ return [
'params' => [ 'params' => [
'persist' => 'mongodb_persist', // 持久化连接标识 'persist' => 'mongodb_persist', // 持久化连接标识
], ],
],
'immongodb' => [
'type' => 'mongo',
'hostname' => '127.0.0.1',
'hostport' => '37017',
'database' => 'openim_v3',
'username' => 'openIM',
'password' => 'n1e5a6s6m7',
'prefix' => 'wa_',
'pk_convert_id' => true,
// 开启字段缓存
'fields_cache' => true,
// 监听SQL
'trigger_sql' => true,
'params' => [
'persist' => 'mongodb_persist',
'authSource' => 'openim_v3',
],
] ]
], ],
]; ];