PHPackages                             slince/smartqq - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. slince/smartqq

ActiveLibrary[API Development](/categories/api)

slince/smartqq
==============

The wrapper for smartqq api using php

2.2.0(7y ago)8323126[6 issues](https://github.com/slince/smartqq/issues)MITPHPPHP &gt;=5.6.0

Since Aug 28Pushed 7y ago6 watchersCompare

[ Source](https://github.com/slince/smartqq)[ Packagist](https://packagist.org/packages/slince/smartqq)[ RSS](/packages/slince-smartqq/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (5)Versions (15)Used By (0)

SmartQQ协议
=========

[](#smartqq协议)

[![Build Status](https://camo.githubusercontent.com/5ecb9c65b2424eed8c99abe446411a3ba5cef79c20bfbc4e51d6a334cbb5a692/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f736c696e63652f736d61727471712f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/slince/smartqq)[![Coverage Status](https://camo.githubusercontent.com/41c587d76d57a3645dba0997415cf8b61d0fd4049104d047ffd6bf1e5d0817d4/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f736c696e63652f736d61727471712e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/slince/smartqq)[![Latest Stable Version](https://camo.githubusercontent.com/f06974012308e58cf475a9edec73e0531d300215b81b525fedd086777c032b93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736c696e63652f736d61727471712e7376673f7374796c653d666c61742d737175617265266c6162656c3d737461626c65)](https://packagist.org/packages/slince/smartqq)[![Scrutinizer](https://camo.githubusercontent.com/5d444fb571bb28ba7582b4fe9f8734269a7db0b3e9041a4a3f136ad7bf36b647/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f736c696e63652f736d61727471712e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/slince/smartqq/?branch=master)

SmartQQ(WebQQ) API的PHP实现，通过对原生web api的请求以及返回值的分析，重新进行了整理； 解决了原生接口杂乱的请求规则与混乱的数据返回；使得开发者可以更多关注自己的业务。

灵感来自于[Java SmartQQ](https://github.com/ScienJus/smartqq)，感谢原作者对SmartQQ的详尽解释。

安装
--

[](#安装)

```
composer require slince/smartqq
```

使用
--

[](#使用)

### 登录

[](#登录)

登录是获取授权的必备步骤，由于SmartQQ抛弃了用户名密码的登录方式，所以只能采用二维码登录

```
$smartQQ = new Slince\SmartQQ\Client();

$smartQQ->login(function($qrcode){ //$qrcode 是二维码字符串
    // 自定义逻辑
    @file_put_contents('/path/to/qrcode.png', $qrcode);
});
```

如果成功的话你会在`/path/to/qrcode.png`下发现二维码，使用手机扫描即可登录； 注意：程序会阻塞直到确认成功；成功之后你可以通过下面方式持久化登录凭证，用于下次查询。

```
$credential = $smartQQ->getCredential();

//将凭证对象转换为标量方便存储，写入数据库或者缓存系统
$credentialParameters = $credential->toArray();
```

通过下面方式还原一个凭证对象；需要注意的是此次凭证并不会长久有效， 如果该凭证长时间没有被用来发起查询，则很可能会失效。

```
//还原凭证对象
$credential = Credential::fromArray($credentialParameters);
$smartQQ = new Client($credential);
```

### 查询好友、群以及讨论组

[](#查询好友群以及讨论组)

#### 好友相关

[](#好友相关)

- 查询所有好友

```
$friends = $smartQQ->getFriends();

//找出昵称为张三的好友
$zhangSan = $friends->firstByAttribute('nick', '张三');

//自定义筛选，如找出所有女性并且是vip会员的好友
$girls = $friends->filter(function(Friend $friend){
     return $friend->getGender() == 'female' && $friend->isVip();
})->toArray();
```

- 查询好友详细资料

```
//上例，找出张三的资料
$profile = $smartQQ->getFriendDetail($zhangSan);
```

#### 群相关

[](#群相关)

- 查询所有群

```
$groups = $smartQQ->getGroups();

//找出名称为“少年”的群
$shaoNianGroup = $groups->firstByAttribute('name', '少年');
```

> 同样支持自定义筛选

#### 讨论组相关

[](#讨论组相关)

- 查询所有讨论组

```
$discusses = $smartQQ->getDiscusses();

//找出名称为“少年”的讨论组
$shaoNianDiscuss = $discusses->firstByAttribute('name', '少年');
```

> 一样，也支持自定义筛选

- 查询讨论组的详细资料，比如群成员信息等

接上例，查询讨论组“少年”的详细资料

```
$shaoNianDetail = $smartQQ->getDiscussDetail($shaoNianDiscuss);

//所有群成员，支持自定义筛选
$members = $shaoNianDetail->getMembers();
```

### 发送消息

[](#发送消息)

支持表情，表情短语

```
[
"微笑" ,"撇嘴" ,"色" ,"发呆" ,"得意" ,"流泪" ,"害羞" ,"闭嘴" ,"睡" ,"大哭" ,"尴尬" ,"发怒" ,"调皮" ,"呲牙" ,"惊讶" ,"难过" ,"酷" ,"冷汗" ,"抓狂" ,"吐",
"偷笑" ,"可爱" ,"白眼" ,"傲慢" ,"饥饿" ,"困" ,"惊恐" ,"流汗" ,"憨笑" ,"大兵" ,"奋斗" ,"咒骂" ,"疑问" ,"嘘" ,"晕" ,"折磨" ,"衰" ,"骷髅" ,"敲打" ,"再见",
"擦汗" ,"抠鼻" ,"鼓掌" ,"糗大了" ,"坏笑" ,"左哼哼" ,"右哼哼" ,"哈欠" ,"鄙视" ,"委屈" ,"快哭了" ,"阴险" ,"亲亲" ,"吓" ,"可怜" ,"菜刀" ,"西瓜" ,"啤酒" ,"篮球" ,"乒乓",
"咖啡" ,"饭" ,"猪头" ,"玫瑰" ,"凋谢" ,"示爱" ,"爱心" ,"心碎" ,"蛋糕" ,"闪电" ,"炸弹" ,"刀" ,"足球" ,"瓢虫" ,"便便" ,"月亮" ,"太阳" ,"礼物" ,"拥抱" ,"强",
"弱" ,"握手" ,"胜利" ,"抱拳" ,"勾引" ,"拳头" ,"差劲" ,"爱你" ,"NO" ,"OK" ,"爱情" ,"飞吻" ,"跳跳" ,"发抖" ,"怄火" ,"转圈" ,"磕头" ,"回头" ,"跳绳" ,"挥手",
"激动", "街舞", "献吻", "左太极", "右太极", "双喜", "鞭炮", "灯笼", "发财", "K歌", "购物", "邮件", "帅", "喝彩","祈祷","爆筋","棒棒糖","喝奶","下面","香蕉",
"飞机","开车","左车头","车厢","右车头","多云","下雨","钞票","熊猫","灯泡","风车","闹钟","打伞","彩球","钻戒","沙发","纸巾","药","手枪","青蛙"
]
```

#### 给好友发送消息

[](#给好友发送消息)

```
//1、找到好友
$friend = $friends->firstByAttribute('nick', '秋易');

//2、生成消息
$message = new FriendMessage($friend, '[微笑] 你好');
$result = $smartQQ->sendMessage($message);
var_dump($result);
```

#### 给群发送消息

[](#给群发送消息)

```
//1、找到群
$group = $groups->firstByAttribute('name', 'msu');
//2、生成消息
$message = new GroupMessage($group, new Content('[微笑] 哈喽'));
$result = $smartQQ->sendMessage($message);
var_dump($result);
```

#### 发送讨论组消息

[](#发送讨论组消息)

```
//1、找到讨论组
$discuss = $discusses->firstByAttribute('name', '他是个少年');
//2、生成消息
$message = new DiscussMessage($discuss, '[微笑] 讨论组消息');
$result = $smartQQ->sendMessage($message);
var_dump($result);
```

#### 给讨论组成员发消息

[](#给讨论组成员发消息)

```
$discussMember = $smartQQ->getDiscussDetail($discuss)
    ->getMembers()
    ->firstByAttribute('nick', '张三');
$message = new FriendMessage($discussMember,  '[微笑] 你好');
$result = $smartQQ->sendMessage($message);
var_dump($result);
```

### 接收消息

[](#接收消息)

```
$messages = $smartQQ->pollMessages();
```

关于消息的处理请参照 examples.

当然你也可以使用 `MessageHandler` 来帮忙维护客户端消息。

```
$handler = $smartQQ->getMessageHandler();

$handler->onMessage(function(Slince\SmartQQ\Message\Response\Message $message) use ($hander){
    var_dump($message);
    $handler->stop(); //停止消息轮询
});
```

详细使用案例以及更多其它案例请参考[examples](./examples)

其它
--

[](#其它)

- 关于103错误，多是由于webqq多点登录引起的，如果遇到错误，先到确认能够收发消息，然后退出登录。
- 关于登录凭证的时效性，smartqq是基于web接口的，对cookie有要求，登录成功之后如果长时间没有操作，cookie将会失效；此时需要重新登录。
- 本组件只是对原生的请求与数据进行了整理并进行了合理的抽象，并没有过多的进行业务层级的封装。
- SmartQQ接口一直在调整，如果api无法使用请直接提[issue](https://github.com/slince/smartqq/issues/new)，或者给我发邮件;如果你找到了原因并且有了解决方案欢迎 PR。

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~63 days

Recently: every ~54 days

Total

13

Last Release

2834d ago

Major Versions

1.x-dev → 2.0.02017-04-03

PHP version history (2 changes)1.0.0PHP &gt;=5.5.9

2.0.4PHP &gt;=5.6.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3785826?v=4)[Tao](/maintainers/slince)[@slince](https://github.com/slince)

---

Top Contributors

[![slince](https://avatars.githubusercontent.com/u/3785826?v=4)](https://github.com/slince "slince (115 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

php-qqphp-smartqqphp-webqqsmartqqwebqqqqsmartqqwebqqphp-smartqqphp-webqqphp-qq

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/slince-smartqq/health.svg)

```
[![Health](https://phpackages.com/badges/slince-smartqq/health.svg)](https://phpackages.com/packages/slince-smartqq)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.5k](/packages/aws-aws-sdk-php)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M723](/packages/sylius-sylius)[craftcms/cms

Craft CMS

3.6k3.6M3.0k](/packages/craftcms-cms)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k13](/packages/tempest-framework)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
