Files
im/app/command/User.php
T

142 lines
4.9 KiB
PHP
Raw Normal View History

2026-02-15 19:41:56 +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;
use isszz\hashids\facade\Hashids;
use function GuzzleHttp\json_encode;
class User extends Command
{
protected static $defaultName = 'User';
protected static $defaultDescription = '用户';
2026-04-07 02:30:37 +08:00
public $sdk= null;
2026-02-15 19:41:56 +08:00
/**
* @return void
*/
protected function configure()
{
2026-04-04 08:52:59 +08:00
$this->addOption('user_id','u', InputOption::VALUE_OPTIONAL, 'user_id');
$this->addOption('action','a', InputOption::VALUE_OPTIONAL, '操作类型','test');
2026-02-15 19:41:56 +08:00
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
2026-03-25 02:48:30 +08:00
$action = $input->getOption('action');
if(method_exists($this, $action)){
return $this->$action($input, $output);
}
cp('操作不存在:'.$action);
return 0;
2026-04-04 08:52:59 +08:00
}
2026-04-10 13:31:15 +08:00
function update_password(InputInterface $input, OutputInterface $output){
$newpassword = \plugin\admin\app\common\Util::passwordHash(MD5('qwe123'));
Db::name('User')->where('id','>',0)->save([
'loginfailure' => 0,
'password' => $newpassword
]);
2026-04-04 08:52:59 +08:00
return 0;
2026-03-25 02:48:30 +08:00
}
function login(InputInterface $input, OutputInterface $output){
// $IM = new \support\OpenImSdk\Client([
// 'host' => 'http://127.0.0.1:10002', // OpenIM API地址
// 'secret' => 'n1e5a6s6m7', // OpenIM密钥
// ]);
$user_id = $input->getOption('user_id');
if(!$user_id){
return false;
2026-02-15 19:41:56 +08:00
}
2026-03-25 02:48:30 +08:00
$user = \support\Jwt::direct($user_id);
//$imToken = $IM->auth->getUserToken($user['userID'],2);
cp('userID:' . $user['id']);
cp('nickname:' . $user['nickname']);
cp('token:' . $user['token']);
//cp('imToken:' . $imToken['token']);
2026-02-15 19:41:56 +08:00
return 0;
2026-03-25 02:48:30 +08:00
}
2026-04-06 03:10:44 +08:00
function otop(InputInterface $input, OutputInterface $output){
$user_id = $input->getOption('user_id');
if(!$user_id){
return false;
2026-03-25 02:48:30 +08:00
}
2026-04-06 03:10:44 +08:00
/**
* @var \plugin\admin\app\model\Admin $admin
*/
$admin = \plugin\admin\app\model\Admin::where('id',$user_id)->find();
if(!$admin){
return false;
}
$totp = \OTPHP\TOTP::create($admin->totp_secret);
cp($totp->now());
return 1;
2026-03-25 02:48:30 +08:00
}
2026-04-07 02:30:37 +08:00
//重建user_team
2026-04-06 03:10:44 +08:00
function build_team(){
Db::name('user_team')->where('ancestor_id','>',0)->delete();
$list = Db::name('user')->field('id,parent_id')->order('id','asc')->select();
foreach($list as $k=>$user){
build_user_team($user);
cp('user_id:'.$user['id']);
2026-03-25 02:48:30 +08:00
}
2026-04-06 03:10:44 +08:00
return 0;
2026-02-15 19:41:56 +08:00
}
2026-04-07 02:30:37 +08:00
function register(InputInterface $input, OutputInterface $output){
$im = $this->getSdk();
try {
for($i=313;$i<333;$i++){
2026-04-12 09:50:05 +08:00
$mobile = (12600000000+$i).'';
2026-04-07 02:30:37 +08:00
$password = \support\Random::build('23456789abcdefghjklmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ',8);
$data = [
'mobile' => $mobile,
'username' => $mobile,
'region' => '86',
'nickname' => $mobile,
'role_id' => 1,
'group_id' => 0,
'password' => \plugin\admin\app\common\Util::passwordHash(md5($password)),
'avatar' => '/static/img/avatar.png',
'created_at' => time(),
'updated_at' => time(),
'status' => 1,
];
$user_id = Db::name('user')->insertGetId($data);
$userID = \support\Encrypt::userIDencode($user_id);
Db::name('user')->where('id',$user_id)->update([
'userID'=>$userID
]);
$im->user->userRegister($userID,$data['nickname'],cdnurl($data['avatar']));
$user = Db::name('user')->where('id',$user_id)->find();
Hook('user.register_successed',$user);
cp($user_id,$data['mobile'],$password);
}
return 0;
} catch (\Exception $e) {
//throw $th;
cp($e->getMessage());
return 1;
}
}
protected 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;
}
2026-02-15 19:41:56 +08:00
}