| @@ 170-206 (lines=37) @@ | ||
| 167 | /** |
|
| 168 | * 推送消息给单个设备. |
|
| 169 | */ |
|
| 170 | public function PushSingleDevice($deviceToken, $message, $environment = 0) |
|
| 171 | { |
|
| 172 | $ret = ['ret_code' => -1, 'err_msg' => 'message not valid']; |
|
| 173 | ||
| 174 | if (! ($message instanceof Message) && ! ($message instanceof MessageIOS)) { |
|
| 175 | return $ret; |
|
| 176 | } |
|
| 177 | if (! $this->ValidateMessageType($message)) { |
|
| 178 | $ret['err_msg'] = 'message type not fit accessId'; |
|
| 179 | ||
| 180 | return $ret; |
|
| 181 | } |
|
| 182 | if ($message instanceof MessageIOS) { |
|
| 183 | if ($environment != self::IOSENV_DEV && $environment != self::IOSENV_PROD) { |
|
| 184 | $ret['err_msg'] = 'ios message environment invalid'; |
|
| 185 | ||
| 186 | return $ret; |
|
| 187 | } |
|
| 188 | } |
|
| 189 | if (! $message->isValid()) { |
|
| 190 | return $ret; |
|
| 191 | } |
|
| 192 | $params = []; |
|
| 193 | $params['access_id'] = $this->accessId; |
|
| 194 | $params['expire_time'] = $message->getExpireTime(); |
|
| 195 | $params['send_time'] = $message->getSendTime(); |
|
| 196 | if ($message instanceof Message) { |
|
| 197 | $params['multi_pkg'] = $message->getMultiPkg(); |
|
| 198 | } |
|
| 199 | $params['device_token'] = $deviceToken; |
|
| 200 | $params['message_type'] = $message->getType(); |
|
| 201 | $params['message'] = $message->toJson(); |
|
| 202 | $params['timestamp'] = time(); |
|
| 203 | $params['environment'] = $environment; |
|
| 204 | ||
| 205 | return $this->callRestful(self::RESTAPI_PUSHSINGLEDEVICE, $params); |
|
| 206 | } |
|
| 207 | ||
| 208 | /** |
|
| 209 | * 推送消息给单个账户. |
|
| @@ 441-478 (lines=38) @@ | ||
| 438 | /** |
|
| 439 | * 创建批量推送任务 |
|
| 440 | */ |
|
| 441 | public function CreateMultipush($message, $environment = 0) |
|
| 442 | { |
|
| 443 | $ret = ['ret_code' => -1]; |
|
| 444 | if (! ($message instanceof Message) && ! ($message instanceof MessageIOS)) { |
|
| 445 | $ret['err_msg'] = 'message is not android or ios'; |
|
| 446 | ||
| 447 | return $ret; |
|
| 448 | } |
|
| 449 | if (! $this->ValidateMessageType($message)) { |
|
| 450 | $ret['err_msg'] = 'message type not fit accessId'; |
|
| 451 | ||
| 452 | return $ret; |
|
| 453 | } |
|
| 454 | if ($message instanceof MessageIOS) { |
|
| 455 | if ($environment != self::IOSENV_DEV && $environment != self::IOSENV_PROD) { |
|
| 456 | $ret['err_msg'] = 'ios message environment invalid'; |
|
| 457 | ||
| 458 | return $ret; |
|
| 459 | } |
|
| 460 | } |
|
| 461 | if (! $message->isValid()) { |
|
| 462 | $ret['err_msg'] = 'message not valid'; |
|
| 463 | ||
| 464 | return $ret; |
|
| 465 | } |
|
| 466 | $params = []; |
|
| 467 | $params['access_id'] = $this->accessId; |
|
| 468 | $params['expire_time'] = $message->getExpireTime(); |
|
| 469 | if ($message instanceof Message) { |
|
| 470 | $params['multi_pkg'] = $message->getMultiPkg(); |
|
| 471 | } |
|
| 472 | $params['message_type'] = $message->getType(); |
|
| 473 | $params['message'] = $message->toJson(); |
|
| 474 | $params['timestamp'] = time(); |
|
| 475 | $params['environment'] = $environment; |
|
| 476 | ||
| 477 | return $this->callRestful(self::RESTAPI_CREATEMULTIPUSH, $params); |
|
| 478 | } |
|
| 479 | ||
| 480 | /** |
|
| 481 | * 按帐号大批量推送 |
|