2025-11-22 15:31:01 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\command;
|
|
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
use support\think\Db;
|
|
|
|
|
|
|
|
|
|
class OpenIm extends Command
|
|
|
|
|
{
|
|
|
|
|
protected static $defaultName = 'openim';
|
|
|
|
|
protected static $defaultDescription = 'OpenIm';
|
2026-02-27 13:53:53 +08:00
|
|
|
public $sdk= null;
|
2026-03-06 02:27:52 +08:00
|
|
|
function fixurl(){
|
|
|
|
|
$sdk = $this->getSdk();
|
|
|
|
|
$search = 'http://103.39.222.184:10002/object/';
|
|
|
|
|
$replace = 'https://s1.shun777.com/imapi/object/';
|
|
|
|
|
$users = Db::name('User')
|
|
|
|
|
->whereLike('avatar','%'.$search)
|
|
|
|
|
->field('avatar,id,userID')
|
|
|
|
|
->select();
|
|
|
|
|
foreach($users as $k=>$user){
|
|
|
|
|
$avatar = str_replace($search,$replace,$user['avatar']);
|
|
|
|
|
Db::name('User')
|
|
|
|
|
->where('id',$user['id'])
|
|
|
|
|
->update(['avatar'=>$avatar]);
|
|
|
|
|
$sdata = [
|
|
|
|
|
'faceURL' => $avatar
|
|
|
|
|
];
|
|
|
|
|
$sdk->user->updateUserInfo($user['userID'],$sdata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$model = new \app\model\Openim\Group();
|
|
|
|
|
$list = $model->whereLike('face_url', '%'.$search)->select();
|
|
|
|
|
foreach($list as $k=>$group){
|
|
|
|
|
$avatar = str_replace($search,$replace,$group['face_url']);
|
|
|
|
|
$model->where('id',$group['id'])->update(['face_url'=>$avatar]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$model = new \app\model\Openim\Msg();
|
|
|
|
|
$total = $model->count('id');
|
|
|
|
|
$count = 0;
|
|
|
|
|
for($i=0;$i<$total;$i+=1000){
|
|
|
|
|
$list = $model->limit($i,1000)->select();
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
if(!empty($item['msgs']) && is_array($item['msgs'])){
|
|
|
|
|
$msgs = [];
|
|
|
|
|
foreach($item['msgs'] as $key => $msg){
|
|
|
|
|
if(is_null($msg['msg'])){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$msgs[] = $msg;
|
|
|
|
|
}
|
|
|
|
|
$item->msgs = $msgs;
|
|
|
|
|
}
|
|
|
|
|
$item->save();
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
function convertUserID(InputInterface $input, OutputInterface $output): int
|
|
|
|
|
{
|
|
|
|
|
$userID = $input->getOption('userID');
|
|
|
|
|
$this->_convertUserID($userID,$output);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
function _convertUserID($userID,$output): int
|
|
|
|
|
{
|
|
|
|
|
$oldUserID = \support\Encrypt::userIDEncode($userID);
|
|
|
|
|
$newUserID = \support\Encrypt::intEncode($userID);
|
|
|
|
|
|
|
|
|
|
cp("开始转换用户ID: {$userID} -> {$oldUserID} -> {$newUserID}");
|
|
|
|
|
// $this->convertBlackTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertConversationTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertVersionTables($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertFriendTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertFriendRequestTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertGroupTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertGroupMemberTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertGroupRequestTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertMsgTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertSeqTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertSeqUserTable($oldUserID, $newUserID, $output);
|
|
|
|
|
// $this->convertUserTable($oldUserID, $newUserID, $output);
|
|
|
|
|
for ($i=100006;$i<102028;$i++){
|
|
|
|
|
$newUserID = \support\Encrypt::intEncode($i);
|
|
|
|
|
Db::name('User')->where('id',$i)->update(['userID'=>$newUserID]);
|
|
|
|
|
}
|
|
|
|
|
cp("用户ID:{$userID} -> {$newUserID} 转换完成");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
protected function convertFriendTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\Friend();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
if($item['owner_user_id']){
|
|
|
|
|
$savedata['owner_user_id'] = $this->turnID($item['owner_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['friend_user_id']){
|
|
|
|
|
$savedata['friend_user_id'] = $this->turnID($item['friend_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['operator_user_id']){
|
|
|
|
|
$savedata['operator_user_id'] = $this->turnID($item['operator_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if(!empty($savedata)){
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
}
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("Friend 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function convertFriendRequestTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\FriendRequest();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
if($item['from_user_id']){
|
|
|
|
|
$savedata['from_user_id'] = $this->turnID($item['from_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['to_user_id']){
|
|
|
|
|
$savedata['to_user_id'] = $this->turnID($item['to_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['handler_user_id']){
|
|
|
|
|
$savedata['handler_user_id'] = $this->turnID($item['handler_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if(!empty($savedata)){
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
}
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("FriendRequest 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
protected function convertGroupTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\Group();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
if($item['creator_user_id']){
|
|
|
|
|
$savedata['creator_user_id'] = $this->turnID($item['creator_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['notification_user_id']){
|
|
|
|
|
$savedata['notification_user_id'] = $this->turnID($item['notification_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if(!empty($savedata)){
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
}
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("Group 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function convertGroupMemberTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\GroupMember();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
if($item['user_id']){
|
|
|
|
|
$savedata['user_id'] = $this->turnID($item['user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['inviter_user_id']){
|
|
|
|
|
$savedata['inviter_user_id'] = $this->turnID($item['inviter_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['operator_user_id']){
|
|
|
|
|
$savedata['operator_user_id'] = $this->turnID($item['operator_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if(!empty($savedata)){
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
}
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("GroupMember 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function convertBlackTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\Black();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
if($item['block_user_id']){
|
|
|
|
|
$savedata['block_user_id'] = $this->turnID($item['block_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['owner_user_id']){
|
|
|
|
|
$savedata['owner_user_id'] = $this->turnID($item['owner_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['operator_user_id']){
|
|
|
|
|
$savedata['operator_user_id'] = $this->turnID($item['operator_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if(!empty($savedata)){
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
}
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("Black 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
protected function convertConversationTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\Conversation();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
if($item['user_id']){
|
|
|
|
|
$savedata['user_id'] = $this->turnID($item['user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['owner_user_id']){
|
|
|
|
|
$savedata['owner_user_id'] = $this->turnID($item['owner_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['conversation_id']){
|
|
|
|
|
$savedata['conversation_id'] = $this->handlerConversationID($item['conversation_id']);
|
|
|
|
|
}
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
//$item->save();
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("Conversation 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function convertUserTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\User();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
foreach($list as $k=>$user){
|
|
|
|
|
$model->where('id',$user['id'])->update([
|
|
|
|
|
'user_id' => $this->turnID($user['user_id'])
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function convertGroupRequestTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\GroupRequest();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
if($item['user_id']){
|
|
|
|
|
$savedata['user_id'] = $this->turnID($item['user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['handle_user_id']){
|
|
|
|
|
$savedata['handle_user_id'] = $this->turnID($item['handle_user_id']);
|
|
|
|
|
}
|
|
|
|
|
if($item['inviter_user_id']){
|
|
|
|
|
$savedata['inviter_user_id'] = $this->turnID($item['inviter_user_id']);
|
|
|
|
|
}
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("GroupRequest 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function convertSeqTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\Seq();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$model->where('id',$item['id'])->update([
|
|
|
|
|
'conversation_id' => $this->handlerConversationID($item['conversation_id'])
|
|
|
|
|
]);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("Seq 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function convertSeqUserTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\SeqUser();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
//cp($model->getLastSql());
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$model->where('id',$item['id'])->update([
|
|
|
|
|
'user_id' => $this->turnID($item->user_id),
|
|
|
|
|
'conversation_id' => $this->handlerConversationID($item['conversation_id'])
|
|
|
|
|
]);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
if($count){
|
|
|
|
|
$output->writeln("SeqUser 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function convertVersionTables($oldUserID, $newUserID, $output){
|
|
|
|
|
$this->convertConversationVersionTable($oldUserID, $newUserID, $output);
|
|
|
|
|
$this->convertFriendVersionTable($oldUserID, $newUserID, $output);
|
|
|
|
|
$this->convertGroupMemberVersionTable($oldUserID, $newUserID, $output);
|
|
|
|
|
$this->convertGroupJoinVersionTable($oldUserID, $newUserID, $output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function convertConversationVersionTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\ConversationVersion();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
$savedata['d_id'] = $this->turnID($item['d_id']);
|
|
|
|
|
if(!empty($item['logs']) && is_array($item['logs'])){
|
|
|
|
|
$logs = $item['logs'];
|
|
|
|
|
foreach($logs as $key => $log){
|
|
|
|
|
if(isset($log['e_id'])){
|
|
|
|
|
$logs[$key]['e_id'] = $this->handlerConversationID($log['e_id']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$savedata['logs'] = $logs;
|
|
|
|
|
}
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("ConversationVersion 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function convertFriendVersionTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\FriendVersion();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
$savedata['d_id'] = $this->turnID($item['d_id']);
|
|
|
|
|
if(!empty($item['logs']) && is_array($item['logs'])){
|
|
|
|
|
$logs = $item['logs'];
|
|
|
|
|
foreach($logs as $key => $log){
|
|
|
|
|
if(isset($log['e_id'])){
|
|
|
|
|
$logs[$key]['e_id'] = $this->handlerConversationID($log['e_id']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$savedata['logs'] = $logs;
|
|
|
|
|
}
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("FriendVersion 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function convertGroupMemberVersionTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\GroupMemberVersion();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
$savedata['d_id'] = $this->turnID($item['d_id']);
|
|
|
|
|
if(!empty($item['logs']) && is_array($item['logs'])){
|
|
|
|
|
$logs = $item['logs'];
|
|
|
|
|
foreach($logs as $key => $log){
|
|
|
|
|
if(isset($log['e_id'])){
|
|
|
|
|
$logs[$key]['e_id'] = $this->handlerConversationID($log['e_id']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$savedata['logs'] = $logs;
|
|
|
|
|
}
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("GroupMemberVersion 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function convertGroupJoinVersionTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\GroupJoinVersion();
|
|
|
|
|
$list = $model->select();
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
$savedata['d_id'] = $this->turnID($item['d_id']);
|
|
|
|
|
if(!empty($item['logs']) && is_array($item['logs'])){
|
|
|
|
|
$logs = $item['logs'];
|
|
|
|
|
foreach($logs as $key => $log){
|
|
|
|
|
if(isset($log['e_id'])){
|
|
|
|
|
$logs[$key]['e_id'] = $this->handlerConversationID($log['e_id']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$savedata['logs'] = $logs;
|
|
|
|
|
}
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
$output->writeln("GroupJoinVersion 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
function turnID($id){
|
|
|
|
|
if($id == 'official_team' || $id == 'officialteam'){
|
|
|
|
|
return 'SystemOfficialTeam';
|
|
|
|
|
}
|
|
|
|
|
if($id == 'group_bot'){
|
|
|
|
|
return 'SystemGroupBot';
|
|
|
|
|
}
|
|
|
|
|
if($id == 'imAdmin'){
|
|
|
|
|
return 'SystemImAdmin';
|
|
|
|
|
}
|
|
|
|
|
if($id == 'system'){
|
|
|
|
|
return 'SystemAccount';
|
|
|
|
|
}
|
|
|
|
|
try{
|
|
|
|
|
return \support\Encrypt::intEncode(\support\Encrypt::userIDDecode($id));
|
|
|
|
|
}catch(\Exception $e){
|
|
|
|
|
return $id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
protected function convertMsgTable($oldUserID, $newUserID, $output){
|
|
|
|
|
$model = new \app\model\Openim\Msg();
|
|
|
|
|
$total = $model->count('id');
|
|
|
|
|
$count = 0;
|
|
|
|
|
for($i=0;$i<$total;$i+=1000){
|
|
|
|
|
$list = $model->limit($i,1000)->select();
|
|
|
|
|
foreach($list as $item){
|
|
|
|
|
$savedata = [];
|
|
|
|
|
$doc_id = explode(':',$item['doc_id']);
|
|
|
|
|
$doc_id[0] = $this->handlerConversationID($doc_id[0]);
|
|
|
|
|
$savedata['doc_id'] = $doc_id[0].':'.$doc_id[1];
|
|
|
|
|
foreach($item['msgs'] as $key => $msg){
|
|
|
|
|
if(isset($msg['msg']['send_id'])){
|
|
|
|
|
$savedata['msgs'][$key]['msg']['send_id'] = $this->turnID($msg['msg']['send_id']);
|
|
|
|
|
}
|
|
|
|
|
if(isset($msg['msg']['recv_id'])){
|
|
|
|
|
$savedata['msgs'][$key]['msg']['recv_id'] = $this->turnID($msg['msg']['recv_id']);
|
|
|
|
|
}
|
|
|
|
|
$content = [];
|
|
|
|
|
if($msg['msg']['content']){
|
|
|
|
|
$content = json_decode($msg['msg']['content'],true);
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '101'){
|
|
|
|
|
//cp($content);
|
|
|
|
|
//break 2;
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '102'){
|
|
|
|
|
$urlFields = ['sourcePath'];
|
|
|
|
|
$this->handlerUrl($content,$urlFields);
|
|
|
|
|
if(isset($content['sourcePicture'])){
|
|
|
|
|
$urlFields = ['url'];
|
|
|
|
|
$this->handlerUrl($content['sourcePicture'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($content['bigPicture'])){
|
|
|
|
|
$urlFields = ['url'];
|
|
|
|
|
$this->handlerUrl($content['bigPicture'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($content['snapshotPicture'])){
|
|
|
|
|
$urlFields = ['url'];
|
|
|
|
|
$this->handlerUrl($content['snapshotPicture'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
//cp($content);
|
|
|
|
|
//break 2;
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '103'){
|
|
|
|
|
$urlFields = ['soundPath','sourceUrl'];
|
|
|
|
|
$this->handlerUrl($content,$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '104'){
|
|
|
|
|
$urlFields = ['videoUrl','snapshotUrl','snapshotPath','videoPath'];
|
|
|
|
|
$this->handlerUrl($content,$urlFields);
|
|
|
|
|
//cp($content);
|
|
|
|
|
//break 2;
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '106'){
|
|
|
|
|
if(isset($content['atUserList'])){
|
|
|
|
|
foreach($content['atUserList'] as $k=>$userID){
|
|
|
|
|
$content['atUserList'][$k] = $this->turnID($userID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(isset($content['atUsersInfo'])){
|
|
|
|
|
foreach($content['atUsersInfo'] as $k=>$v){
|
|
|
|
|
$content['atUsersInfo'][$k]['atUserID'] = $this->turnID($v['atUserID']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '108'){
|
|
|
|
|
$this->handlerUserId($content,['userID']);
|
|
|
|
|
$this->handlerUrl($content,['faceURL']);
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '109'){
|
|
|
|
|
//cp($content);
|
|
|
|
|
//break 2;
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '114'){
|
|
|
|
|
if(isset($content['quoteMessage'])){
|
|
|
|
|
$userIDFields = ['sendID','recvID'];
|
|
|
|
|
$this->handlerUserId($detail['quoteMessage'],$userIDFields);
|
|
|
|
|
$urlFields = ['senderFaceUrl'];
|
|
|
|
|
$this->handlerUrl($detail['quoteMessage'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '1201'){
|
|
|
|
|
//cp($content['detail']);
|
|
|
|
|
$detail = json_decode($content['detail'],true);
|
|
|
|
|
if(isset($detail['fromToUserID'])){
|
|
|
|
|
$userIDFields = ['fromUserID','toUserID'];
|
|
|
|
|
$this->handlerUserId($detail['fromToUserID'],$userIDFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['request'])){
|
|
|
|
|
$userIDFields = ['handlerUserID','fromUserID','toUserID'];
|
|
|
|
|
$this->handlerUserId($detail['request'],$userIDFields);
|
|
|
|
|
$urlFields = ['fromFaceURL','toFaceURL'];
|
|
|
|
|
$this->handlerUrl($detail['request'],$urlFields);
|
2025-11-22 15:31:01 +08:00
|
|
|
|
2026-03-06 02:27:52 +08:00
|
|
|
}
|
|
|
|
|
$content['detail'] = json_encode($detail,JSON_UNESCAPED_UNICODE);
|
|
|
|
|
//cp($detail);
|
|
|
|
|
//break 2;
|
|
|
|
|
}
|
|
|
|
|
if(in_array($msg['msg']['content_type'],['1501','1504','1507','1508','1509','1510','1512','1513','1514','1519','1515','1520'])){
|
|
|
|
|
$detail = json_decode($content['detail'],true);
|
|
|
|
|
|
|
|
|
|
if(isset($detail['memberList'])){
|
|
|
|
|
foreach($detail['memberList'] as $memberIndex => $member){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($member,$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($member,$urlFields);
|
|
|
|
|
$detail['memberList'][$memberIndex] = $member;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['invitedUserList'])){
|
|
|
|
|
foreach($detail['invitedUserList'] as $memberIndex => $member){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($member,$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($member,$urlFields);
|
|
|
|
|
$detail['invitedUserList'][$memberIndex] = $member;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['groupOwnerUser'])){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($detail['groupOwnerUser'],$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($detail['groupOwnerUser'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['inviterUser'])){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($detail['inviterUser'],$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($detail['inviterUser'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['oldGroupOwnerInfo'])){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($detail['oldGroupOwnerInfo'],$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($detail['oldGroupOwnerInfo'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['newGroupOwner'])){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($detail['newGroupOwner'],$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($detail['newGroupOwner'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['entrantUser'])){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($detail['entrantUser'],$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($detail['entrantUser'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['mutedUser'])){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($detail['mutedUser'],$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($detail['mutedUser'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['group'])){
|
|
|
|
|
$userIDFields = ['ownerUserID','creatorUserID'];
|
|
|
|
|
$this->handlerUserId($detail['group'],$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($detail['group'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['opUser'])){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($detail['opUser'],$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($detail['opUser'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['quitUser'])){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($detail['quitUser'],$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($detail['quitUser'],$urlFields);
|
|
|
|
|
}
|
|
|
|
|
if(isset($detail['kickedUserList'])){
|
|
|
|
|
foreach($detail['kickedUserList'] as $memberIndex => $member){
|
|
|
|
|
$userIDFields = ['userID','operatorUserID','inviterUserID'];
|
|
|
|
|
$this->handlerUserId($member,$userIDFields);
|
|
|
|
|
$urlFields = ['faceURL'];
|
|
|
|
|
$this->handlerUrl($member,$urlFields);
|
|
|
|
|
$detail['kickedUserList'][$memberIndex] = $member;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$content['detail'] = json_encode($detail,JSON_UNESCAPED_UNICODE);
|
|
|
|
|
//break 2;
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '1701'){
|
|
|
|
|
$detail = json_decode($content['detail'],true);
|
|
|
|
|
$userIDFields = ['recvID','sendID'];
|
|
|
|
|
$this->handlerUserId($detail,$userIDFields);
|
|
|
|
|
if(isset($detail['conversationID'])){
|
|
|
|
|
$detail['conversationID'] = $this->handlerConversationID($detail['conversationID']);
|
|
|
|
|
}
|
|
|
|
|
$content['detail'] = json_encode($detail,JSON_UNESCAPED_UNICODE);
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '2001'){
|
|
|
|
|
//cp($content);
|
|
|
|
|
//break 2;
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '2200'){
|
|
|
|
|
$detail = json_decode($content['detail'],true);
|
|
|
|
|
$userIDFields = ['markAsReadUserID'];
|
|
|
|
|
$this->handlerUserId($detail,$userIDFields);
|
|
|
|
|
if(isset($detail['conversationID'])){
|
|
|
|
|
$detail['conversationID'] = $this->handlerConversationID($detail['conversationID']);
|
|
|
|
|
}
|
|
|
|
|
//cp($detail);
|
|
|
|
|
$content['detail'] = json_encode($detail,JSON_UNESCAPED_UNICODE);
|
|
|
|
|
//break 2;
|
|
|
|
|
}
|
|
|
|
|
if($msg['msg']['content_type'] == '2101'){
|
|
|
|
|
$detail = json_decode($content['detail'],true);
|
|
|
|
|
$userIDFields = ['revokerUserID'];
|
|
|
|
|
$this->handlerUserId($detail,$userIDFields);
|
|
|
|
|
$detail['conversationID'] = $this->handlerConversationID($detail['conversationID']);
|
|
|
|
|
$content['detail'] = json_encode($detail,JSON_UNESCAPED_UNICODE);
|
|
|
|
|
}
|
|
|
|
|
$msg['msg']['content'] = json_encode($content,JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$savedata['msgs'][$key] = $msg;
|
|
|
|
|
}
|
|
|
|
|
if(!empty($savedata)){
|
|
|
|
|
$model->where('id',$item['id'])->update($savedata);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//log_alert($contentTypes,'cansnow');
|
|
|
|
|
//$output->writeln("Msg 表转换完成,共 {$count} 条记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handlerConversationID($data){
|
|
|
|
|
$data = str_replace('official_team','officialteam',$data);
|
|
|
|
|
$cids = explode('_',$data);
|
|
|
|
|
$cids[1] = $this->turnID($cids[1]);
|
|
|
|
|
if(count($cids) >2){
|
|
|
|
|
$cids[2] = $this->turnID($cids[2]);
|
|
|
|
|
}
|
|
|
|
|
$data = implode('_',$cids);
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
function handlerUserId(&$data,$userIDFields){
|
|
|
|
|
foreach($userIDFields as $userIDField){
|
|
|
|
|
if(isset($data[$userIDField]) && $data[$userIDField]){
|
|
|
|
|
$data[$userIDField] = $this->turnID($data[$userIDField]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function handlerUrl(&$data,$urlFields){
|
|
|
|
|
foreach($urlFields as $urlField){
|
|
|
|
|
if(isset($data[$urlField])){
|
|
|
|
|
$data[$urlField] = $this->cdn($data[$urlField]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cdn($url){
|
|
|
|
|
if(substr(0,2) =='//'){
|
|
|
|
|
$url = 'https:'.$url;
|
|
|
|
|
}
|
|
|
|
|
if(substr(0,7) =='http://'){
|
|
|
|
|
$url = 'https://'.substr($url,7);
|
|
|
|
|
}
|
|
|
|
|
return $url;
|
|
|
|
|
}
|
|
|
|
|
function getUser(){
|
|
|
|
|
$im = $this->getSdk();
|
|
|
|
|
$data = $im->user->searchNotificationAccount('');
|
|
|
|
|
cp($data);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2025-11-22 15:31:01 +08:00
|
|
|
/**
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function configure()
|
|
|
|
|
{
|
|
|
|
|
$this->addOption('action','a', InputArgument::OPTIONAL, '操作类型');
|
2026-03-06 02:27:52 +08:00
|
|
|
$this->addOption('conversationID','c', InputArgument::OPTIONAL, '会话ID');
|
|
|
|
|
$this->addOption('userID','u', InputArgument::OPTIONAL, '用户ID');
|
2025-11-22 15:31:01 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 02:27:52 +08:00
|
|
|
|
|
|
|
|
|
2025-11-22 15:31:01 +08:00
|
|
|
/**
|
|
|
|
|
* @param InputInterface $input
|
|
|
|
|
* @param OutputInterface $output
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
|
{
|
|
|
|
|
$action = $input->getOption('action');
|
|
|
|
|
if(!$action){
|
|
|
|
|
$output->writeln('空操作');
|
|
|
|
|
return self::FAILURE;
|
|
|
|
|
}
|
|
|
|
|
if(method_exists($this, $action)){
|
|
|
|
|
return $this->$action($input, $output);
|
|
|
|
|
}
|
2026-02-27 13:53:53 +08:00
|
|
|
$output->writeln($action.'不存在');
|
2025-11-22 15:31:01 +08:00
|
|
|
return self::FAILURE;
|
|
|
|
|
}
|
2025-12-24 16:59:05 +08:00
|
|
|
private function change_user(InputInterface $input, OutputInterface $output):int{
|
|
|
|
|
|
2026-02-27 13:53:53 +08:00
|
|
|
$im = $this->getSdk();
|
2026-03-01 21:05:19 +08:00
|
|
|
$data = $im->user->updateUserInfo(\support\Encrypt::userIDencode('100006'),['userInfo'=>['userId'=>'wx100001']]);
|
2025-12-24 16:59:05 +08:00
|
|
|
cp($data);
|
|
|
|
|
return self::SUCCESS;
|
|
|
|
|
}
|
2025-11-22 15:31:01 +08:00
|
|
|
private function sync_users(InputInterface $input, OutputInterface $output):int{
|
2026-02-27 13:53:53 +08:00
|
|
|
$im = $this->getSdk();
|
2025-11-22 15:31:01 +08:00
|
|
|
$data = $im->user->getAllUsersUid(1,1000);
|
2025-12-24 16:59:05 +08:00
|
|
|
cp($data);
|
|
|
|
|
return self::SUCCESS;
|
2025-11-22 15:31:01 +08:00
|
|
|
$exsit_user_ids = Db::name('user')->whereIn('id',$data['userIDs'])->column('id');
|
|
|
|
|
$not_exsit_user_ids =array_diff($data['userIDs'],$exsit_user_ids);
|
|
|
|
|
if(count($not_exsit_user_ids)> 0){
|
|
|
|
|
//同步用户
|
|
|
|
|
$res = $im->user->getUsersInfo($not_exsit_user_ids);
|
|
|
|
|
$save_data = [];
|
|
|
|
|
foreach($res['usersInfo'] as $k=>$_user){
|
|
|
|
|
array_push($save_data,[
|
|
|
|
|
'id' => $_user['userID'],
|
|
|
|
|
'nickname' => $_user['nickname'],
|
|
|
|
|
'password' => '123456',
|
|
|
|
|
'avatar' => $_user['faceURL']
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// "ex": "",
|
|
|
|
|
// "createTime": 1688454168302,
|
|
|
|
|
// "appMangerLevel": 18,
|
|
|
|
|
// "globalRecvMsgOpt": 0
|
|
|
|
|
}
|
|
|
|
|
if(!empty($save_data)){
|
|
|
|
|
Db::name('user')->insertAll($save_data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return self::SUCCESS;
|
|
|
|
|
}
|
2026-02-27 13:53:53 +08:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2025-11-22 15:31:01 +08:00
|
|
|
}
|