Exemple #1
0
 public static function actionPushMessage()
 {
     $results = array();
     switch ($auth = static::getAuthIfUserCanDoIt(Utility::getCurrentUserID(), 'push', null)) {
         case 'admin':
             //有管理权限
             $title = W2HttpRequest::getRequestString('title', false);
             $content = W2HttpRequest::getRequestString('content', false);
             $type = W2HttpRequest::getRequestInt('type', 5, false, 1, 1);
             //1单人 2所有人 3所有安卓 4所有ios
             $customtype = W2HttpRequest::getRequestInt('customtype');
             $customvalue = W2HttpRequest::getRequestString('customvalue');
             $deployStatus = W2HttpRequest::getRequestInt('deploystatus', 2, false, 1, 2);
             W2PUSH::$DEPLOY_STATUS = $deployStatus;
             if ($content == '') {
                 return Utility::getArrayForResults(RUNTIME_CODE_ERROR_PARAM, '请输入正确的推送内容');
             }
             // $tag_name = 't'.date('G');
             $tag_name = null;
             switch ($type) {
                 case 1:
                     //1单人
                     $userID = W2HttpRequest::getRequestInt('userid');
                     $telephone = W2HttpRequest::getRequestTelephone('telephone', false);
                     if ($userID != null) {
                         $results = array_merge($results, DeviceController::pushMessageToUser($userID, $title, $content, $customtype, $customvalue, $tag_name));
                     } else {
                         if ($telephone != null) {
                             $results = array_merge($results, DeviceController::pushMessageToTelephone($telephone, $title, $content, $customtype, $customvalue, $tag_name));
                         } else {
                             return Utility::getArrayForResults(RUNTIME_CODE_ERROR_PARAM, '请输入正确的userid 或 telephone');
                         }
                     }
                     break;
                 case 2:
                     //2所有人
                 //2所有人
                 case 3:
                     //3所有安卓
                     $push_type = 2;
                     // 2部分人(*常用)
                     $results[] = W2PUSH::pushMessage($push_type, $device_type = 3, $title, $content, $customtype, $customvalue, null, $tag_name);
                     if ($type == 3) {
                         break;
                     }
                 case 4:
                     //4所有ios
                     $push_type = 2;
                     // 2部分人(*常用)
                     $results[] = W2PUSH::pushMessage($push_type, $device_type = 4, $title, $content, $customtype, $customvalue, null, $tag_name);
                     break;
                 default:
                     return Utility::getArrayForResults(RUNTIME_CODE_ERROR_PARAM, '请输入正确的推送类型');
                     break;
             }
             break;
         case 'self':
             //作者
         //作者
         case 'normal':
             //正常用户
         //正常用户
         case 'draft':
             //未激活
         //未激活
         case 'pending':
             //待审禁言
         //待审禁言
         case 'disabled':
             //封号
         //封号
         case 'visitor':
             //游客
         //游客
         default:
             return Utility::getArrayForResults(RUNTIME_CODE_ERROR_NO_AUTH, '您没有权限执行该操作');
             break;
     }
     $success_amount_total = 0;
     foreach ($results as $ret) {
         if (array_key_exists('result', $ret) && array_key_exists('response_params', $ret['result']) && array_key_exists('success_amount', $ret['result']['response_params'])) {
             $success_amount_total += $ret['result']['response_params']['success_amount'];
         }
     }
     return Utility::getArrayForResults(RUNTIME_CODE_OK, '', $results, array('success_amount_total' => $success_amount_total));
 }