RequestFriend.php
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2017/1/15
* Time: 12:29
*/
namespace Hanson\Vbot\Message\Entity;
use Hanson\Vbot\Message\MessageInterface;
class RequestFriend extends Message implements MessageInterface
{
/**
* @var array 信息
*/
public $info;
public $avatar;
const ADD = 2;
const VIA = 3;
public function __construct($msg)
{
parent::__construct($msg);
$this->make();
}
public function make()
{
$this->info = $this->msg['RecommendInfo'];
$this->parseContent();
}
private function parseContent()
{
$isMatch = preg_match('/bigheadimgurl="(.+?)"/', $this->msg['Content'], $matches);
if ($isMatch) {
$this->avatar = $matches[1];
}
}
/**
* 验证通过好友
*
* @param $code
* @param null $ticket
* @return bool
*/
public function verifyUser($code, $ticket = null)
{
$url = sprintf(server()->baseUri . '/webwxverifyuser?lang=zh_CN&r=%s&pass_ticket=%s', time() * 1000, server()->passTicket);
$data = [
'BaseRequest' => server()->baseRequest,
'Opcode' => $code,
'VerifyUserListSize' => 1,
'VerifyUserList' => [$ticket ?: $this->verifyTicket()],
'VerifyContent' => '',
'SceneListCount' => 1,
'SceneList' => [33],
'skey' => server()->skey
];
$result = http()->json($url, $data, true);
return $result['BaseResponse']['Ret'] == 0;
}
/**
* 返回通过好友申请所需的数组
*
* @return array
*/
public function verifyTicket()
{
return [
'Value' => $this->info['UserName'],
'VerifyUserTicket' => $this->info['Ticket']
];
}
}