119 lines
4.0 KiB
PHP
Executable File
119 lines
4.0 KiB
PHP
Executable File
<?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';
|
|
public $sdk= null;
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
protected function configure()
|
|
{
|
|
$this->addOption('action','a', InputArgument::OPTIONAL, '操作类型');
|
|
}
|
|
|
|
/**
|
|
* @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);
|
|
}
|
|
$output->writeln($action.'不存在');
|
|
return self::FAILURE;
|
|
}
|
|
private function change_user(InputInterface $input, OutputInterface $output):int{
|
|
|
|
$im = $this->getSdk();
|
|
$data = $im->user->updateUserInfo(idEncode('100006'),['userInfo'=>['userId'=>'wx100001']]);
|
|
cp($data);
|
|
return self::SUCCESS;
|
|
}
|
|
private function sync_users(InputInterface $input, OutputInterface $output):int{
|
|
$im = $this->getSdk();
|
|
$data = $im->user->getAllUsersUid(1,1000);
|
|
cp($data);
|
|
return self::SUCCESS;
|
|
$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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|