public static function mobiletoken_update(\ApiParam $params) { if ($params->mobile) { try { $user = User::user_show($params); $userId = $user->id; $userMobile = $user->mobile; } catch (\Exception $e) { $userId = ''; $userMobile = ''; } } if ($params->userId) { try { $user = new \User(); $user->load($params->userId); $userId = $params->userId; $userMobile = $user->mobile; } catch (\Exception $e) { $userId = ''; $userMobile = ''; } } \NotificationToken::updateDevice($params->appType, $params->appVersion, $params->deviceUniqueIdentifier, $params->deviceToken, $userId, $userMobile); return true; }
private static function mobile_debug_push(\ApiParam $params) { $udid = $params->udid; $apiKey = $params->api_key; $deviceToken = $params->deviceToken; $action = $params->action ?: "info"; $title = $params->title ?: "<" . $action . "> Pust Test Title 0 1 2 3 4 5 6 7 8 9 10." . " 0 1 2 3 4 5 6 7 8 9 10. 0 1 2 3 4 5 6 7 8 9 10."; $title = date('[m-d h:m:s]') . $title; $data = $params->data ?: ""; $data = htmlspecialchars_decode($data); $jsonData = json_decode($data, true); if (!empty($data) && !is_array($jsonData)) { return self::formatResult(403, '"data" 格式错误'); } if (empty($udid) || empty($apiKey)) { return self::formatResult(403, '缺少参数 "udid" or "api_key"'); } if ($apiKey != "api_mobile_android" && empty($deviceToken)) { return self::formatResult(403, '缺少参数 "deviceToken"'); } $notificationToken = new \NotificationToken(); $pushData = null; $queryArray = new \AndQuery(new \Query('appType', $apiKey), new \Query('deviceUniqueIdentifier', $udid)); if ($apiKey != "api_mobile_android") { // 非 Android 需要 deviceToken $queryArray = new \AndQuery($queryArray, new \Query('deviceToken', $deviceToken)); } $targets = $notificationToken->find($queryArray); if (empty($targets)) { return self::formatResult(403, 'Push表中无结果'); } else { if (count($targets) > 1) { return self::formatResult(403, 'Push表异常,查出多个结果:' . count($targets)); } } if (\Cache::getCountNumber('PushTestCount', 24 * 3600) > 100) { return self::formatResult(403, '测试超限'); } \PushNotification::sendByTokens($title, $targets, $action, $title, $data); return self::formatResult(); }