Skip to content

Commit f100b48

Browse files
author
Helperhaps
committed
mv json_encode to Http
1 parent 9975548 commit f100b48

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

src/JPush/DevicePayload.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function updateDevice($registrationId, $alias = null, $mobile = null, $ad
9595
}
9696

9797
$url = DevicePayload::DEVICE_URL . $registrationId;
98-
return Http::post($this->client, $url, json_encode($payload));
98+
return Http::post($this->client, $url, $payload);
9999
}
100100

101101
public function getTags() {
@@ -158,7 +158,7 @@ public function updateTag($tag, $addDevices = null, $removeDevices = null) {
158158

159159
$url = DevicePayload::TAG_URL . $tag;
160160
$payload = array('registration_ids'=>$registrationId);
161-
return Http::post($this->client, $url, json_encode($payload));
161+
return Http::post($this->client, $url, $payload);
162162
}
163163

164164
public function deleteTag($tag) {
@@ -219,6 +219,6 @@ public function getDevicesStatus($registrationId) {
219219
}
220220
$payload['registration_ids'] = $registrationId;
221221
$url = DevicePayload::DEVICE_STATUS_URL;
222-
return Http::post($this->client, $url, json_encode($payload));
222+
return Http::post($this->client, $url, $payload);
223223
}
224224
}

src/JPush/Http.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function delete($client, $url) {
2323
}
2424

2525
private static function sendRequest($client, $url, $method, $body=null, $times=1) {
26-
self::log($client, "Send " . $method . " " . $url . ", body:" . $body . ", times:" . $times);
26+
self::log($client, "Send " . $method . " " . $url . ", body:" . json_encode($body) . ", times:" . $times);
2727
if (!defined('CURL_HTTP_VERSION_2_0')) {
2828
define('CURL_HTTP_VERSION_2_0', 3);
2929
}
@@ -51,7 +51,7 @@ private static function sendRequest($client, $url, $method, $body=null, $times=1
5151
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
5252
}
5353
if (!is_null($body)) {
54-
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
54+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
5555
}
5656

5757
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
@@ -63,13 +63,20 @@ private static function sendRequest($client, $url, $method, $body=null, $times=1
6363
$response = array();
6464
$errorCode = curl_errno($ch);
6565

66+
// $msg = '';
67+
// $data = json_decode($body, true);
68+
// if (isset($data['options']['sendno'])) {
69+
// $sendno = $data['options']['sendno'];
70+
// $msg = 'sendno: ' . $sendno;
71+
// }
72+
6673
$msg = '';
67-
$data = json_decode($body, true);
68-
if (isset($data['options']['sendno'])) {
69-
$sendno = $data['options']['sendno'];
74+
if (isset($body['options']['sendno'])) {
75+
$sendno = $body['options']['sendno'];
7076
$msg = 'sendno: ' . $sendno;
7177
}
7278

79+
7380
if ($errorCode) {
7481
$retries = $client->getRetryTimes();
7582
if ($times < $retries) {

src/JPush/PushPayload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ public function printJSON() {
342342

343343
public function send() {
344344
$url = PushPayload::PUSH_URL;
345-
return Http::post($this->client, $url, $this->toJSON());
345+
return Http::post($this->client, $url, $this->build());
346346
}
347347

348348
public function validate() {
349349
$url = PushPayload::PUSH_VALIDATE_URL;
350-
return Http::post($this->client, $url, $this->toJSON());
350+
return Http::post($this->client, $url, $this->build());
351351
}
352352

353353
private function generateSendno() {

src/JPush/SchedulePayload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function createSingleSchedule($name, $push_payload, $trigger) {
3232
$payload['push'] = $push_payload;
3333

3434
$url = SchedulePayload::SCHEDULES_URL;
35-
return Http::post($this->client, $url, json_encode($payload));
35+
return Http::post($this->client, $url, $payload);
3636
}
3737

3838
public function createPeriodicalSchedule($name, $push_payload, $trigger) {
@@ -52,7 +52,7 @@ public function createPeriodicalSchedule($name, $push_payload, $trigger) {
5252
$payload['push'] = $push_payload;
5353

5454
$url = SchedulePayload::SCHEDULES_URL;
55-
return Http::post($this->client, $url, json_encode($payload));
55+
return Http::post($this->client, $url, $payload);
5656
}
5757

5858
public function updateSingleSchedule($schedule_id, $name=null, $enabled=null, $push_payload=null, $trigger=null) {
@@ -98,7 +98,7 @@ public function updateSingleSchedule($schedule_id, $name=null, $enabled=null, $p
9898

9999
$url = SchedulePayload::SCHEDULES_URL . "/" . $schedule_id;
100100

101-
return Http::put($this->client, $url, json_encode($payload));
101+
return Http::put($this->client, $url, $payload);
102102

103103
}
104104

@@ -144,7 +144,7 @@ public function updatePeriodicalSchedule($schedule_id, $name=null, $enabled=null
144144
}
145145

146146
$url = SchedulePayload::SCHEDULES_URL . "/" . $schedule_id;
147-
return Http::put($this->client, $url, json_encode($payload));
147+
return Http::put($this->client, $url, $payload);
148148
}
149149

150150
public function getSchedules($page = 1) {

0 commit comments

Comments
 (0)