Telerik推送通知过滤

时间:2016-01-07 13:03:48

标签: c# json telerik

我正在研究一个系统,该系统在系统中发布新项目时自动发送推送消息。这很顺利。问题是我必须对软件包和专业做一些过滤。

在第一个过滤器块中,它可以工作,但是它会发送到符合其中一个条件的所有设备。我想要的(并在测试2和3中尝试过)只有当有人拥有软件包和某个专业时它才会发送。

telerik api的愚蠢之处在于它只返回一个HTTP 400,因此调试非常困难

希望有人可以帮我解决这个问题。

PS。我在代码段

中跳过了一些不相关的代码/功能
function sendNotifications(some parameters)
{
    string json = "{";
    //Test code 1 - This works
    json += "\"Filter\": {";
    json += "\"Parameters.softwarePakket\": {\"$in\": [ \"{software_package}\"]},";
    json += "\"Parameters.beroepsGroep\": {\"$in\": [\"{profession1}\", \"{profession2}\"]},";
    json += "\"Parameters.module\": {\"$in\": [\"{module}\"]}},";

    //Test code 2 - This doesn't work
    //json += "\"Filter\": {\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]}";

    //Test code 3 - And this doesn't work either
    //json += "\"Filter\": \"{\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]}\"";

    //From here its all fine
    json += "\"Android\": {\"data\": {\"title\": \"{app_title}\",\"message\": \"{message}\",\"color\": \"#ffffff\",\"largeIcon\": \"{icon}\",\"customData\": \"{type}\"}},";
    json += "\"IOS\": {\"aps\": {\"alert\": \"{message}\",\"badge\": \"+1\",\"sound\": \"default\",\"category\": \"{type}\"},\"customData\": \"{type}\"}";
    json += "}";

    json = json.Replace("{type}", type);
    json = json.Replace("{icon}", formatIcon(type));
    json = json.Replace("{message}", genericMessage(type));

    var request = (HttpWebRequest)WebRequest.Create("http://api.everlive.com/v1/{app_id}/Push/Notifications");
    request.Method = "POST";
    request.ContentType = "application/json";
    request.ContentLength = json.Length;
    using (var stream = new StreamWriter(request.GetRequestStream()))
    {
        stream.Write(json);
        stream.Flush();
        stream.Close();
    }

    var response = (HttpWebResponse)request.GetResponse();

    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}

1 个答案:

答案 0 :(得分:1)

我认为你在过滤字符串的末尾缺少一个逗号。所以代码应该是:

//Test code 2
json += "\"Filter\": {\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]},";

//Test code 3
//json += "\"Filter\": \"{\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]}\",";