Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
hfpp2012
/
vbot
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 11a8e84c
authored
Jan 20, 2017
by
HanSon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改显示二维码
1 parent
992b2a82
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
64 deletions
composer.json
example/custom.php
src/Core/Server.php
src/Support/Console.php
src/Support/System.php
composer.json
View file @
11a8e84
...
...
@@ -19,7 +19,8 @@
"php"
:
">=7.0.0"
,
"symfony/var-dumper"
:
"^3.2"
,
"aferrandini/phpqrcode"
:
"^1.0"
,
"symfony/process"
:
"^3.2"
"symfony/process"
:
"^3.2"
,
"symfony/console"
:
"^3.2"
},
"minimum-stability"
:
"dev"
,
"autoload"
:
{
...
...
example/custom.php
View file @
11a8e84
...
...
@@ -19,7 +19,7 @@ $flag = false;
$robot
->
server
->
setCustomerHandler
(
function
()
use
(
&
$flag
){
// RemarkName,代表的改用户在你通讯录的名字
$contact
=
contact
()
->
getUsernameByRemarkName
(
'hanson'
);
$contact
=
contact
()
->
getUsernameByRemarkName
(
'hanson'
);
if
(
$contact
===
false
){
dd
(
"找不到你要的联系人,请确认联系人姓名"
);
}
...
...
src/Core/Server.php
View file @
11a8e84
...
...
@@ -57,7 +57,7 @@ class Server
{
$this
->
config
=
$config
;
$this
->
config
[
'debug'
]
=
$this
->
config
[
'debug'
]
??
false
;
$this
->
config
[
'debug'
]
=
isset
(
$this
->
config
[
'debug'
])
?
$this
->
config
[
'debug'
]
:
false
;
}
/**
...
...
@@ -142,10 +142,6 @@ class Server
$file
=
$this
->
config
[
'tmp'
]
.
'qr.png'
;
$qrCode
->
save
(
$file
);
if
(
strtoupper
(
substr
(
PHP_OS
,
0
,
3
))
===
'WIN'
)
{
system
(
$file
);
}
}
/**
...
...
@@ -332,11 +328,4 @@ class Server
{
MessageHandler
::
getInstance
()
->
setExceptionHandler
(
$closure
);
}
public
function
debug
(
$debug
=
true
)
{
$this
->
debug
=
$debug
;
return
$this
;
}
}
\ No newline at end of file
src/Support/Console.php
View file @
11a8e84
...
...
@@ -13,80 +13,62 @@ use PHPQRCode\QRcode;
use
Symfony\Component\Console\Formatter\OutputFormatterStyle
;
use
Symfony\Component\Console\Output\ConsoleOutput
;
use
Symfony\Component\Console\Output\OutputInterface
;
use
Symfony\Component\Process\Exception\ProcessFailedException
;
use
Symfony\Component\Process\ProcessBuilder
;
class
Console
{
/**
* 输出字符串
*
* @param $str
*/
public
static
function
log
(
$str
)
{
echo
$str
.
PHP_EOL
;
}
private
static
function
initStyle
(
OutputInterface
$output
)
{
$style
=
new
OutputFormatterStyle
(
'black'
,
'black'
);
/**
* 初始化二维码style
*
* @param OutputInterface $output
*/
private
static
function
initQrcodeStyle
(
OutputInterface
$output
)
{
$style
=
new
OutputFormatterStyle
(
'black'
,
'black'
,
array
(
'bold'
));
$output
->
getFormatter
()
->
setStyle
(
'blackc'
,
$style
);
$style
=
new
OutputFormatterStyle
(
'white'
,
'white'
);
$style
=
new
OutputFormatterStyle
(
'white'
,
'white'
,
array
(
'bold'
)
);
$output
->
getFormatter
()
->
setStyle
(
'whitec'
,
$style
);
}
private
static
function
getTTYSize
()
{
if
(
!
posix_isatty
(
STDOUT
)){
return
false
;
}
$ttyName
=
posix_ttyname
(
STDOUT
);
$builder
=
new
ProcessBuilder
();
$process
=
$builder
->
setPrefix
(
'stty'
)
->
setArguments
(
array
(
'-f'
,
$ttyName
,
'size'
))
->
getProcess
();
try
{
$process
->
mustRun
();
}
catch
(
ProcessFailedException
$e
)
{
return
false
;
}
$output
=
$process
->
getOutput
();
if
(
!
preg_match
(
'~^(\d+)\s+(\d+)$~'
,
$output
,
$match
))
{
return
false
;
}
return
array
(
$match
[
1
],
$match
[
2
]);
}
/**
* 控制台显示二维码
*
* @param $text
*/
public
static
function
showQrCode
(
$text
)
{
$output
=
new
ConsoleOutput
();
static
::
initStyle
(
$output
);
$map
=
array
(
0
=>
'<whitec> </whitec>'
,
1
=>
'<blackc> </blackc>'
,
);
$lrPadding
=
1
;
$tbPadding
=
0
;
static
::
initQrcodeStyle
(
$output
);
if
(
System
::
isWin
()){
$pxMap
=
[
'<whitec>mm</whitec>'
,
'<blackc> </blackc>'
];
system
(
'cls'
);
}
else
{
$pxMap
=
[
'<whitec> </whitec>'
,
'<blackc> </blackc>'
];
system
(
'clear'
);
}
$text
=
QRcode
::
text
(
$text
);
$length
=
strlen
(
$text
[
0
]);
$screenSize
=
static
::
getTTYSize
();
if
(
!
$screenSize
)
{
$output
->
getErrorOutput
()
->
writeln
(
'<comment>Get Screen Size Failed</comment>'
);
}
else
{
list
(
$maxLines
,
$maxCols
)
=
$screenSize
;
$qrCols
=
2
*
(
$length
+
$lrPadding
*
2
);
$qrLines
=
count
(
$text
)
+
$tbPadding
*
2
;
if
(
$qrCols
>
$maxCols
||
$qrLines
>
$maxLines
){
$output
->
getErrorOutput
()
->
writeln
(
'<error>Max Lines/Columns Reached:请缩小控制台字体大小</error>'
);
return
;
}
}
$paddingLine
=
str_repeat
(
$map
[
0
],
$length
+
$lrPadding
*
2
)
.
"
\n
"
;
$after
=
$before
=
str_repeat
(
$paddingLine
,
$tbPadding
);
$output
->
write
(
$before
);
foreach
(
$text
as
$line
)
{
$output
->
write
(
str_repeat
(
$map
[
0
],
$lrPadding
)
);
$output
->
write
(
$pxMap
[
0
]
);
for
(
$i
=
0
;
$i
<
$length
;
$i
++
)
{
$type
=
substr
(
$line
,
$i
,
1
);
$output
->
write
(
$
m
ap
[
$type
]);
$output
->
write
(
$
pxM
ap
[
$type
]);
}
$output
->
writeln
(
str_repeat
(
$map
[
0
],
$lrPadding
)
);
$output
->
writeln
(
$pxMap
[
0
]
);
}
$output
->
write
(
$after
);
}
}
\ No newline at end of file
src/Support/System.php
0 → 100644
View file @
11a8e84
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2017/1/20
* Time: 18:37
*/
namespace
Hanson\Vbot\Support
;
class
System
{
/**
* 判断运行服务器是否windows
*
* @return bool
*/
public
static
function
isWin
()
{
return
strtoupper
(
substr
(
PHP_OS
,
0
,
3
))
===
'WIN'
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment