Skip to content

Commit

Permalink
修复获取limit数据失败报错的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
xiezefan committed Jan 4, 2016
1 parent aada0da commit 3900848
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
27 changes: 21 additions & 6 deletions src/JPush/core/DevicePayload.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

class DevicePayload {
private static $LIMIT_KEYS = array('X-Rate-Limit-Limit'=>'rateLimitLimit', 'X-Rate-Limit-Remaining'=>'rateLimitRemaining', 'X-Rate-Limit-Reset'=>'rateLimitReset');

const DEVICE_URL = 'https://device.jpush.cn/v3/devices/';
const DEVICE_STATUS_URL = 'https://device.jpush.cn/v3/devices/status/';
Expand All @@ -27,17 +28,19 @@ public function getDevices($registrationId) {
return $this->__processResp($response);
}

public function updateDevice($registrationId, $alias = null, $addTags = null, $removeTags = null) {
public function updateDevice($registrationId, $alias = null, $mobile=null, $addTags = null, $removeTags = null) {
$payload = array();
if (!is_string($registrationId)) {
throw new InvalidArgumentException('Invalid registration_id');
}

$aliasIsNull = is_null($alias);
$mobileIsNull = is_null($mobile);
$addTagsIsNull = is_null($addTags);
$removeTagsIsNull = is_null($removeTags);

if ($aliasIsNull && $addTagsIsNull && $removeTagsIsNull) {

if ($aliasIsNull && $addTagsIsNull && $removeTagsIsNull && $mobileIsNull) {
throw new InvalidArgumentException("alias, addTags, removeTags not all null");
}

Expand All @@ -49,6 +52,14 @@ public function updateDevice($registrationId, $alias = null, $addTags = null, $r
}
}

if (!$mobileIsNull) {
if (is_string($mobile)) {
$payload['mobile'] = $mobile;
} else {
throw new InvalidArgumentException("Invalid mobile string");
}
}

$tags = array();

if (!$addTagsIsNull) {
Expand Down Expand Up @@ -227,10 +238,14 @@ private function __processResp($response) {
$headers = $response['headers'];
if (is_array($headers)) {
$limit = array();
$limit['rateLimitLimit'] = $headers['X-Rate-Limit-Limit'];
$limit['rateLimitRemaining'] = $headers['X-Rate-Limit-Remaining'];
$limit['rateLimitReset'] = $headers['X-Rate-Limit-Reset'];
$body['limit'] = (object)$limit;
foreach (self::$LIMIT_KEYS as $key => $value) {
if (array_key_exists($key, $headers)) {
$limit[$value] = $headers[$key];
}
}
if (count($limit) > 0) {
$body['limit'] = (object)$limit;
}
return (object)$body;
}
return $body;
Expand Down
15 changes: 10 additions & 5 deletions src/JPush/core/PushPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class PushPayload {
private static $EFFECTIVE_DEVICE_TYPES = array('ios', 'android', 'winphone');
private static $LIMIT_KEYS = array('X-Rate-Limit-Limit'=>'rateLimitLimit', 'X-Rate-Limit-Remaining'=>'rateLimitRemaining', 'X-Rate-Limit-Reset'=>'rateLimitReset');
const PUSH_URL = 'https://api.jpush.cn/v3/push';
const PUSH_VALIDATE_URL = ' https://api.jpush.cn/v3/push/validate';
private $client;
Expand Down Expand Up @@ -559,13 +560,17 @@ private function __processResp($response) {
$headers = $response['headers'];
if (is_array($headers)) {
$limit = array();
$limit['rateLimitLimit'] = $headers['X-Rate-Limit-Limit'];
$limit['rateLimitRemaining'] = $headers['X-Rate-Limit-Remaining'];
$limit['rateLimitReset'] = $headers['X-Rate-Limit-Reset'];
$body['limit'] = (object)$limit;
foreach (self::$LIMIT_KEYS as $key => $value) {
if (array_key_exists($key, $headers)) {
$limit[$value] = $headers[$key];
}
}
if (count($limit) > 0) {
$body['limit'] = (object)$limit;
}
return (object)$body;
}
return (object)$body;
return $body;
} else {
throw new APIRequestException($response);
}
Expand Down
15 changes: 10 additions & 5 deletions src/JPush/core/ReportPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ReportPayload {
private static $EFFECTIVE_TIME_UNIT = array('HOUR', 'DAY', 'MONTH');

private static $LIMIT_KEYS = array('X-Rate-Limit-Limit'=>'rateLimitLimit', 'X-Rate-Limit-Remaining'=>'rateLimitRemaining', 'X-Rate-Limit-Reset'=>'rateLimitReset');
const REPORT_URL = 'https://report.jpush.cn/v3/received';
const MESSAGES_URL = 'https://report.jpush.cn/v3/messages';
const USERS_URL = 'https://report.jpush.cn/v3/users';
Expand Down Expand Up @@ -81,12 +81,17 @@ private function __request($url) {
$body = array();
$body['data'] = (array)json_decode($response['body']);
$headers = $response['headers'];

if (is_array($headers)) {
$limit = array();
$limit['rateLimitLimit'] = $headers['X-Rate-Limit-Limit'];
$limit['rateLimitRemaining'] = $headers['X-Rate-Limit-Remaining'];
$limit['rateLimitReset'] = $headers['X-Rate-Limit-Reset'];
$body['limit'] = (object)$limit;
foreach (self::$LIMIT_KEYS as $key => $value) {
if (array_key_exists($key, $headers)) {
$limit[$value] = $headers[$key];
}
}
if (count($limit) > 0) {
$body['limit'] = (object)$limit;
}
return (object)$body;
}
return $body;
Expand Down
14 changes: 10 additions & 4 deletions src/JPush/core/SchedulePayload.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class SchedulePayload {
private static $LIMIT_KEYS = array('X-Rate-Limit-Limit'=>'rateLimitLimit', 'X-Rate-Limit-Remaining'=>'rateLimitRemaining', 'X-Rate-Limit-Reset'=>'rateLimitReset');

const SCHEDULES_URL = 'https://api.jpush.cn/v3/schedules';
private $client;

Expand Down Expand Up @@ -171,10 +173,14 @@ private function __processResp($response) {
$headers = $response['headers'];
if (is_array($headers)) {
$limit = array();
$limit['rateLimitLimit'] = $headers['X-Rate-Limit-Limit'];
$limit['rateLimitRemaining'] = $headers['X-Rate-Limit-Remaining'];
$limit['rateLimitReset'] = $headers['X-Rate-Limit-Reset'];
$body['limit'] = (object)$limit;
foreach (self::$LIMIT_KEYS as $key => $value) {
if (array_key_exists($key, $headers)) {
$limit[$value] = $headers[$key];
}
}
if (count($limit) > 0) {
$body['limit'] = (object)$limit;
}
return (object)$body;
}
return $body;
Expand Down

0 comments on commit 3900848

Please sign in to comment.