|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link http://www.tintsoft.com/ |
|
4
|
|
|
* @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd. |
|
5
|
|
|
* @license http://www.tintsoft.com/license/ |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace yuncms\broadcast; |
|
9
|
|
|
|
|
10
|
|
|
use Yii; |
|
11
|
|
|
use yii\base\InvalidConfigException; |
|
12
|
|
|
use AliyunMNS\Config; |
|
|
|
|
|
|
13
|
|
|
use AliyunMNS\Http\HttpClient; |
|
|
|
|
|
|
14
|
|
|
use AliyunMNS\Requests\CreateTopicRequest; |
|
|
|
|
|
|
15
|
|
|
use AliyunMNS\Requests\DeleteTopicRequest; |
|
|
|
|
|
|
16
|
|
|
use AliyunMNS\Responses\CreateTopicResponse; |
|
|
|
|
|
|
17
|
|
|
use AliyunMNS\Responses\DeleteTopicResponse; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Aliyun |
|
21
|
|
|
* |
|
22
|
|
|
* @author Tongle Xu <[email protected]> |
|
23
|
|
|
* @since 3.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
class Aliyun extends Broadcast |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
public $endPoint; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
public $accessId; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
public $accessKey; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var null|string |
|
44
|
|
|
*/ |
|
45
|
|
|
public $securityToken = null; |
|
46
|
|
|
|
|
47
|
|
|
/** @var string 默认操作的主题 */ |
|
48
|
|
|
public $topicName; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var null|Config |
|
52
|
|
|
*/ |
|
53
|
|
|
public $config = null; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var HttpClient |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $client; |
|
59
|
|
|
/** |
|
60
|
|
|
* 初始化组件 |
|
61
|
|
|
* @throws InvalidConfigException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function init() |
|
64
|
|
|
{ |
|
65
|
|
|
parent::init(); |
|
66
|
|
|
if (empty ($this->endPoint)) { |
|
67
|
|
|
throw new InvalidConfigException ('The "endPoint" property must be set.'); |
|
68
|
|
|
} |
|
69
|
|
|
if (empty ($this->accessId)) { |
|
70
|
|
|
throw new InvalidConfigException ('The "accessId" property must be set.'); |
|
71
|
|
|
} |
|
72
|
|
|
if (empty ($this->accessKey)) { |
|
73
|
|
|
throw new InvalidConfigException ('The "accessKey" property must be set.'); |
|
74
|
|
|
} |
|
75
|
|
|
if (empty ($this->topicName)) { |
|
76
|
|
|
$this->topicName = Yii::$app->id; |
|
77
|
|
|
} |
|
78
|
|
|
$this->client = new HttpClient($this->endPoint, $this->accessId, $this->accessKey, $this->securityToken, $this->config); |
|
79
|
|
|
} |
|
80
|
|
|
/** |
|
81
|
|
|
* 获取主题(广播) |
|
82
|
|
|
* @param string $topicName |
|
83
|
|
|
* @return Topic |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getTopicRef($topicName = null) |
|
86
|
|
|
{ |
|
87
|
|
|
return new Topic([ |
|
|
|
|
|
|
88
|
|
|
'client' => $this->client, |
|
89
|
|
|
'topicName' => !is_null($topicName) ? $topicName : $this->topicName |
|
90
|
|
|
]); |
|
91
|
|
|
} |
|
92
|
|
|
/** |
|
93
|
|
|
* 向主题推送消息 |
|
94
|
|
|
* @param string|array $messageBody |
|
95
|
|
|
* @param string $messageTag |
|
96
|
|
|
* @param null $messageAttributes |
|
|
|
|
|
|
97
|
|
|
* @param string $topicName |
|
98
|
|
|
* @return \AliyunMNS\Responses\BaseResponse |
|
|
|
|
|
|
99
|
|
|
*/ |
|
100
|
|
|
public function publishMessage($messageBody, $messageTag = null, $messageAttributes = null, $topicName = null) |
|
101
|
|
|
{ |
|
102
|
|
|
$topic = $this->getTopicRef($topicName); |
|
103
|
|
|
return $topic->publishMessage($messageBody, $messageTag, $messageAttributes); |
|
104
|
|
|
} |
|
105
|
|
|
/** |
|
106
|
|
|
* 创建主题 |
|
107
|
|
|
* @param string $topicName |
|
108
|
|
|
* @return \AliyunMNS\Responses\BaseResponse |
|
109
|
|
|
*/ |
|
110
|
|
|
public function create($topicName) |
|
111
|
|
|
{ |
|
112
|
|
|
$request = new CreateTopicRequest($topicName); |
|
113
|
|
|
$response = new CreateTopicResponse($request->getTopicName()); |
|
114
|
|
|
return $this->client->sendRequest($request, $response); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* 删除主题 |
|
119
|
|
|
* @param string $topicName |
|
120
|
|
|
* @return \AliyunMNS\Responses\BaseResponse |
|
121
|
|
|
*/ |
|
122
|
|
|
public function delete($topicName) |
|
123
|
|
|
{ |
|
124
|
|
|
$request = new DeleteTopicRequest($topicName); |
|
125
|
|
|
$response = new DeleteTopicResponse(); |
|
126
|
|
|
return $this->client->sendRequest($request, $response); |
|
127
|
|
|
} |
|
128
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths