Skip to content

Commit 7fd4f07

Browse files
authored
Merge pull request #4 from reallyli/fixed-pusher-component
解决 pusher 相关问题
2 parents 25d8377 + 60314c9 commit 7fd4f07

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Components/Pusher/Pusher.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Pusher
2323
*/
2424
public function trigger($channels, string $eventName, array $data, array $params = [])
2525
{
26-
$params['channel'] = is_string($channels) ? [$channels] : (array) $channels;
26+
$params['channels'] = is_string($channels) ? [$channels] : (array) $channels;
2727
$params['data'] = $data;
2828
$params['name'] = $eventName;
2929

@@ -41,23 +41,25 @@ public function trigger($channels, string $eventName, array $data, array $params
4141
*/
4242
protected function sendRequest(string $url, array $data)
4343
{
44+
$jsonData = json_encode($data);
45+
4446
$ch = curl_init($url);
4547
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
46-
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
48+
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
4749
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
4850
curl_setopt(
4951
$ch,
5052
CURLOPT_HTTPHEADER,
5153
[
5254
'Content-Type: application/json',
53-
'Content-Length: '.strlen($data),
55+
'Content-Length: '.strlen($jsonData),
5456
]
5557
);
5658

5759
$response = curl_exec($ch);
5860

5961
if ($response === false) {
60-
logger()->error('[LaravelUnicomponent] Pusher Send Request Error, data:'.json_encode($data));
62+
logger()->error('[LaravelUnicomponent] Pusher Send Request Error, data:'.$jsonData);
6163

6264
return false;
6365
}
@@ -74,7 +76,7 @@ protected function sendRequest(string $url, array $data)
7476
*/
7577
protected function getPusherUrl()
7678
{
77-
$pusherUrl = config('unicomponent.pusher.configs.pusher_url');
79+
$pusherUrl = config('unicomponent.components.pusher.configs.pusher_url');
7880

7981
throw_unless(filter_var($pusherUrl, FILTER_VALIDATE_URL), '\Exception', 'pusher url illegal');
8082

0 commit comments

Comments
 (0)