Completed
Push — master ( 026b2f...fbea6a )
by Taosikai
11:48
created

examples/send_message.php (3 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * 发送消息.
4
 */
5
use Slince\SmartQQ\Client;
6
use Slince\SmartQQ\Message\Request\FriendMessage;
7
use Slince\SmartQQ\Message\Request\GroupMessage;
8
use Slince\SmartQQ\Message\Request\DiscussMessage;
9
use Slince\SmartQQ\Message\Content;
10
11
include __DIR__.'/bootstrap.php';
12
13
//创建smartQQ客户端
14
$smartQQ = new Client(getCredential());
15
16
$friends = $smartQQ->getFriends();
17
$groups = $smartQQ->getGroups();
18
$discusses = $smartQQ->getDiscusses();
19
//# 给好友发送消息
20
21
//1、找到好友
22
$friend = $friends->firstByAttribute('nick', '秋易');
23
//2、生成消息
24
//支持表情,使用中括号括起来即可,表情短语
25
/**
26
 * [.
27
"微笑" ,"撇嘴" ,"色" ,"发呆" ,"得意" ,"流泪" ,"害羞" ,"闭嘴" ,"睡" ,"大哭" ,"尴尬" ,"发怒" ,"调皮" ,"呲牙" ,"惊讶" ,"难过" ,"酷" ,"冷汗" ,"抓狂" ,"吐",
28
"偷笑" ,"可爱" ,"白眼" ,"傲慢" ,"饥饿" ,"困" ,"惊恐" ,"流汗" ,"憨笑" ,"大兵" ,"奋斗" ,"咒骂" ,"疑问" ,"嘘" ,"晕" ,"折磨" ,"衰" ,"骷髅" ,"敲打" ,"再见",
29
"擦汗" ,"抠鼻" ,"鼓掌" ,"糗大了" ,"坏笑" ,"左哼哼" ,"右哼哼" ,"哈欠" ,"鄙视" ,"委屈" ,"快哭了" ,"阴险" ,"亲亲" ,"吓" ,"可怜" ,"菜刀" ,"西瓜" ,"啤酒" ,"篮球" ,"乒乓",
30
"咖啡" ,"饭" ,"猪头" ,"玫瑰" ,"凋谢" ,"示爱" ,"爱心" ,"心碎" ,"蛋糕" ,"闪电" ,"炸弹" ,"刀" ,"足球" ,"瓢虫" ,"便便" ,"月亮" ,"太阳" ,"礼物" ,"拥抱" ,"强",
31
"弱" ,"握手" ,"胜利" ,"抱拳" ,"勾引" ,"拳头" ,"差劲" ,"爱你" ,"NO" ,"OK" ,"爱情" ,"飞吻" ,"跳跳" ,"发抖" ,"怄火" ,"转圈" ,"磕头" ,"回头" ,"跳绳" ,"挥手",
32
"激动", "街舞", "献吻", "左太极", "右太极", "双喜", "鞭炮", "灯笼", "发财", "K歌", "购物", "邮件", "帅", "喝彩","祈祷","爆筋","棒棒糖","喝奶","下面","香蕉",
33
"飞机","开车","左车头","车厢","右车头","多云","下雨","钞票","熊猫","灯泡","风车","闹钟","打伞","彩球","钻戒","沙发","纸巾","药","手枪","青蛙"
34
]
35
 */
36
$message = new FriendMessage($friend, new Content('[大哭]你好[左哼哼]'));
37
$result = $smartQQ->sendMessage($message);
38
printR($result ? 'Send Success' : 'Send Error');
39
40
//# 给群发送消息
41
//1、找到群
42
$group = $groups->firstByAttribute('name', 'msu');
43
//2、生成消息
44
$message = new GroupMessage($group, new Content('哈喽'));
0 ignored issues
show
$group is of type object|null, but the function expects a object<Slince\SmartQQ\Entity\Group>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
$result = $smartQQ->sendMessage($message);
46
printR($result ? 'Send Success' : 'Send Error');
47
48
//# 发送讨论组消息
49
//1、找到讨论组
50
$discuss = $discusses->firstByAttribute('name', '他是个少年');
51
//2、生成消息
52
$message = new DiscussMessage($discuss, '讨论组消息');
0 ignored issues
show
$discuss is of type object|null, but the function expects a object<Slince\SmartQQ\Entity\Discuss>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
$result = $smartQQ->sendMessage($message);
54
printR($result ? 'Send Success' : 'Send Error');
55
56
//# 给讨论组成员发消息
57
$discussMember = $smartQQ->getDiscussDetail($discuss)
0 ignored issues
show
$discuss is of type object|null, but the function expects a object<Slince\SmartQQ\Entity\Discuss>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
    ->getMembers()
59
    ->firstByAttribute('nick', '张三');
60
$message = new FriendMessage($discussMember, '你好');
61
$result = $smartQQ->sendMessage($message);
62
printR($result ? 'Send Success' : 'Send Error');
63
64
//# 给群成员发送消息
65
/*
66
$groupMember = $smartQQ->getGroupDetail($group)
67
    ->getMembers()
68
    ->firstByAttribute('nick', '清延°');
69
$message = new FriendMessage($discussMember,  '你好');
70
$result = $smartQQ->sendMessage($message);
71
printR($result ? 'Send Success' : 'Send Error');
72
*/