Giter VIP home page Giter VIP logo

smartqq's Introduction

Hi there 👋

  • 🔭 I’m currently working on Nanjing
  • 👀 I’m interested in PHP & Java & Go
  • 🌱 I’m currently learning Typescript

Slince's GitHub stats Top Langs

Achievements

💻 Languages

PHP Java Go Javascript

smartqq's People

Contributors

scrutinizer-auto-fixer avatar slince avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

smartqq's Issues

最近重新看了下smartqq,发现有些接口已经发生了更改

这次正好重新对接了下新的接口,同时对抛出的API进行了重新整理,在数据实体以及请求参数这块仔细做了抽象与重构,新的结构现在看更清晰了点;同时加上了单元测试和style ci,scrutinizer ci ;
由于这次做了大规模的重构因此版本号这次直接跳到2.0,与1.0系列并不兼容

如果我不想获取二维码后堵塞直到扫描咋办

$this->cookies = new CookieJar();
$qrSign = $this->makeQrCodeImage($loginQRImage);
$ptQrToken = Utils::hash33($qrSign);
while (true) {
$status = $this->verifyQrCodeStatus($ptQrToken);
我试了下,我把那个$ptQrToken保存,然后用js定时器来请求,每秒判断一次,可会报错

FriendMessage not working

Hi! This is my code:

$friends = $smartQQ->getFriends();
$friend = $friends->firstByAttribute('nick', 'Artem');

print_r($friend);

$message = new \Slince\SmartQQ\Message\Request\FriendMessage($friend, new \Slince\SmartQQ\Message\Content('Test message'));
$result = $smartQQ->sendMessage($message);

var_dump($result);

My results:
$friend -

Slince\SmartQQ\Entity\Friend Object
(
    [flag:protected] => 293601280
    [face:protected] => 0
    [nick:protected] => Artem
    [qq:protected] => 
    [isVip:protected] => 
    [vipLevel:protected] => 0
    [category:protected] => Slince\SmartQQ\Entity\Category Object
        (
            [name:protected] => 我的好友
            [index:protected] => 0
            [sort:protected] => 0
        )

    [markName:protected] => KarArt
    [uin:protected] => 3023354877
)

$result - bool(false)

Why I get false in $result? Thanks!

运行报错

Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in
/vendor/slince/smartqq/src/Request/GetGroupsRequest.php on line 56

我获取完二维码,判断status状态时报错

Exception at file[/root/m.lishi/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php] line[113] message:[Client error: GET https://ssl.ptlogin2.qq.com/ptqrlogin?ptqrtoken=&webqq_type=10&remember_uin=1&login2qq=1&aid=501004106&u1=http%3A%2F%2Fw.qq.com%2Fproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&ptredirect=0&ptlang=2052&daid=164&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=0-0-4303&mibao_css=m_webqq&t=undefined&g=1&js_type=0&js_ver=10203&login_sig=&pt_randsalt=0 resulted in a 403 Forbidden response]

关于ResponseException;除非是Code103ResponseException

除非是Code103ResponseException 需要退出进程重新授权;其它异常皆可捕获然后重新尝试;
在有些code异常的情况下,接口实际上还是会返回数据,但数据并不完整,处于完整性考虑就直接放弃了响应并抛出异常;此时重试即可

执行缓慢怎么破

$ptWebQQ = $this->getPtWebQQ($this->certificationUrl);
$vfWebQQ = $this->getVfWebQQ($ptWebQQ);
list($uin, $pSessionId) = $this->getUinAndPSessionId($ptWebQQ);
$this->credential = new Credential($ptWebQQ, $vfWebQQ, $pSessionId, $uin, static::$clientId, $this->cookies);
//获取在线状态避免103
$this->getFriendsOnlineStatus();
return $this->credential;
这个要执行好几分钟咋破

detail 404

Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: GET http://s.web2.qq.com/api/get_friend_uin2?tuin=2247542184&type=1&vfwebqq=5c8cf630ac770fbbb8a872eac54a2a0dffb3d4b1c0f0a5bc73a550366297cbf62833df1dcaa8bb51&t=0.1 resulted in a 404 Not Found response: <title>Apache Tomcat/7.0.50 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:w (truncated...) ' in /mnt/hgfs/htdocs/www/jiabin/demo.jiabin.cn/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111 Stack trace: #0 /mnt/hgfs/htdocs/www/jiabin/demo.jiabin.cn/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 /mnt/hgfs/htdocs/www/jiabin/demo.jiabin.cn/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response)) #2 /mnt/hgfs/htdocs/www/jiabin/demo.jiabin.cn/vendor/guzzlehttp/promises/src/Promise.php(15 in /mnt/hgfs/htdocs/www/jiabin/demo.jiabin.cn/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 111

不能获取消息了

获取消息接口返回都是这个

array(3) {
["errmsg"]=>
string(5) "error"
["retcode"]=>
int(0)
["retmsg"]=>
string(2) "ok"
}

获取用户的QQ号

$qq = $smartQQ->getFriendQQ($friend);

到了404页面:

HTTP Status 404 -
type Status report

message

description The requested resource is not available.

Apache Tomcat/7.0.50

我想给每个用户设置一个qq发送给好友的

获取二维码的接口不是会堵塞,直到扫描完成吗?那我设置的是在扫描完成后删除二维码,那如果他获取二维码,不去扫描,这样堵塞住了,那就无法执行删除二维码的程序,改怎么办?

我开了三十个那个登录验证的,就一直用swoole异步定时器轮询,报错

Exception at file[/root/m.lishi/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php] line[113] message:[Client error: GET https://ssl.ptlogin2.qq.com/ptqrlogin?ptqrtoken=780973688&webqq_type=10&remember_uin=1&login2qq=1&aid=501004106&u1=http%3A%2F%2Fw.qq.com%2Fproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&ptredirect=0&ptlang=2052&daid=164&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=0-0-4303&mibao_css=m_webqq&t=undefined&g=1&js_type=0&js_ver=10203&login_sig=&pt_randsalt=0 resulted in a 403 Forbidden response]

103

SmartQQ 我用程序定时发信息,大概两小时左右会出现103错误

接口很棒,谈一下使用感受。

代码封装很优雅,很规范,可读性很高。
配合一些缓存机制,可以大大提升性能。
轮询消息的时候不是很合理,有点粗暴,使用的时候好好调整一下。

代码写得很好在于,我基于swoole运行,基本上没报错啥的,稍微改了一下可以运行很顺畅。

接口比较坑的地方在于(这个是qq协议坑)
1、无法获取到用户实际qq号,里面提到的一个接口,我这边实际上已经访问不了了。qq好友来信,uin都是可能会变化的。
2、无法获取用户实际群号,所有群code或者之类都是一个来信号,是会变化的。
3、如果想用来做一个群签到管理, 估计难度大,因为没有一个唯一标识符是不变的,而昵称是容易冲突的。除非用备注,好友备注和群备注,或者群名片,是可以对用户唯一标识符就行区分。

以上问题如果可以解决,希望作者能指点一下。

分享一个自动登录机制的代码,这个可以通过password进行登录。依赖的实际上就是几个chromedriver之类的环境

自动登录会自动打开chrome浏览器,模拟用户输入密码之类。代码参考了java的一个轮子的一个插件。

` /**
* 开启登录流程自行获取凭证
*
* @param string $uin qq号
* @param string $password 密码
*
* @return Credential
*/
public function passwordLogin($uin,$password)
{

    echo '打开浏览器,进行自动登录,需要2到3分钟完成...'.PHP_EOL;
    $host = 'http://127.0.0.1:4444/wd/hub'; // this is the default
    $capabilities = DesiredCapabilities::chrome();
    // $capabilities = DesiredCapabilities::htmlUnitWithJS();

    $driver = RemoteWebDriver::create($host, $capabilities,5000);

    $driver->manage()->deleteAllCookies();
    
    echo '打开qq登录页面,准备输入账号密码进行登录'.PHP_EOL;
    // navigate to 'http://www.baidu.com/'
    $driver->get('http://m.qzone.com');


    // 输入账号密码
    $user = $driver->findElement(WebDriverBy::id('u'));
    $user->clear();  //将输入框清空
    $user->sendKeys($uin);  //在输入框中输入内容
    $userId = $user->getAttribute('value');    //获取输入框的文本内容

    $pass = $driver->findElement(WebDriverBy::id('p'));
    $pass->clear();  //将输入框清空
    $pass->sendKeys($password);  //在输入框中输入内容
    $password =  $pass->getAttribute('value');    //获取输入框的文本内容

    $ele = $driver->findElement(WebDriverBy::id('go'));
    $driver->executeScript("arguments[0].click();",[$ele]);

    echo '完成登录提交任务,等待网页跳转'.PHP_EOL;
    $driver->wait(5)->until(
        WebDriverExpectedCondition::visibilityOfElementLocated(
            WebDriverBy::id('nav_bar_me')
        )
    );

    echo '开始进入web2.qq.com'.PHP_EOL;
    $driver->get('http://web2.qq.com');                    
    
    $driver->wait(5)->until(
        WebDriverExpectedCondition::visibilityOfElementLocated(
            WebDriverBy::id('mainTopAll')
        )
    );
    echo '开始读取配置信息'.PHP_EOL;
    $vfWebQQ = $driver->executeScript('return mq.vfwebqq');
    $ptWebQQ = $driver->executeScript('return mq.ptwebqq');
    $pSessionId = $driver->executeScript('return mq.psessionid');
    $uin = $userId;

    echo '登录信息如下'.PHP_EOL;
    echo ($vfWebQQ).PHP_EOL;
    echo ($pSessionId).PHP_EOL;
    echo ($ptWebQQ).PHP_EOL;

    // close the browser
    
    echo '登录完成,正在关闭浏览器...'.PHP_EOL;
    $cookies = $driver->manage()->getCookies();
    
    $driver->quit();    

    echo '保存用户登录信息'.PHP_EOL;

    $newCookie =  new CookieJar();

    foreach ($cookies as $key => $value) {
        $cookie = current($value);

        $newCookie->setCookie(new SetCookie([
            'Domain'  => $value['domain'],
            'Name'    => $value['name'],
            'Value'   => $value['value'],
            'Expires'   => $value['expiry'],
            'Path'   => $value['path'],
        ]));

    }        

    $this->cookies = $newCookie;

    $this->credential = new Credential($ptWebQQ, $vfWebQQ, $pSessionId, $uin, static::$clientId, $this->cookies);
    //获取在线状态避免103
    $this->getFriendsOnlineStatus();

    return $this->credential;

}`

在调用pollMessages方法监听消息时会异常

测试隔几秒会异常腾讯接口返回code为0
从这里看到 https://github.com/pandolia/qqbot/blob/31b464ef05849696b150363492776d64e050c244/qqbot/basicqsession.py#L207
pandolia/qqbot#145
(0, 100003, 100100, 100012) 这些code都可以排除,不用抛异常 调用下获取好友状态测试下登录就行了
这些我在外部try解决了

轮询消息http接口不好用我参考这里用了https
https://github.com/pandolia/qqbot/blob/31b464ef05849696b150363492776d64e050c244/qqbot/basicqsession.py#L198

这里用获取好友在线状态测试登录过期
https://github.com/pandolia/qqbot/blob/31b464ef05849696b150363492776d64e050c244/qqbot/basicqsession.py#L174

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.