142 lines
4.9 KiB
PHP
Executable File
142 lines
4.9 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;
|
|
use isszz\hashids\facade\Hashids;
|
|
use function GuzzleHttp\json_encode;
|
|
|
|
class User extends Command
|
|
{
|
|
protected static $defaultName = 'User';
|
|
protected static $defaultDescription = '用户';
|
|
public $sdk= null;
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
protected function configure()
|
|
{
|
|
$this->addOption('user_id','u', InputOption::VALUE_OPTIONAL, 'user_id');
|
|
$this->addOption('action','a', InputOption::VALUE_OPTIONAL, '操作类型','test');
|
|
}
|
|
|
|
/**
|
|
* @param InputInterface $input
|
|
* @param OutputInterface $output
|
|
* @return int
|
|
*/
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$action = $input->getOption('action');
|
|
if(method_exists($this, $action)){
|
|
return $this->$action($input, $output);
|
|
}
|
|
cp('操作不存在:'.$action);
|
|
return 0;
|
|
}
|
|
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
|
|
]);
|
|
return 0;
|
|
}
|
|
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;
|
|
}
|
|
$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']);
|
|
return 0;
|
|
}
|
|
function otop(InputInterface $input, OutputInterface $output){
|
|
$user_id = $input->getOption('user_id');
|
|
if(!$user_id){
|
|
return false;
|
|
}
|
|
/**
|
|
* @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;
|
|
}
|
|
//重建user_team
|
|
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']);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function register(InputInterface $input, OutputInterface $output){
|
|
$im = $this->getSdk();
|
|
try {
|
|
for($i=313;$i<333;$i++){
|
|
$mobile = '12600000000'+$i;
|
|
$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;
|
|
}
|
|
}
|