向所有用户以及特定的deviceTokens发送推送通知

时间:2015-08-18 23:01:09

标签: php json rest parse-platform

我在PHP中使用Parse REST API,并且正在努力弄清楚如何做两件事。

发送给频道的所有用户:

{
  "data": {
    "alert": "This is a test!!",
    "sound": "default",
    "badge": 1
  },
  "where": {
    "channels": [
      "puc"
    ]}
  }
}

发送JSON会给我错误:

{"code":102,"error":"equality needs a value instead of [puc] "}

发送到特定设备令牌/令牌:

{
  "data": {
    "alert": "This is a test!!",
    "sound": "default",
    "badge": 1
  },
  "where": {
    "channels": [
      "puc"
    ],
    "deviceToken": {
      "$in": [
        "DSFSAFJDSLKWRJKLJGLKASGLK"
      ]
    }
  }
}

发送JSON会给我错误:

{"code":102,"error":"equality needs a value instead of [puc] "}

我做错了什么?有人能指出我这两次推进的正确方向吗?

1 个答案:

答案 0 :(得分:1)

channels子句中使用where时,它只需要一个值,而不是一个数组:

发送给频道的所有用户:

{
  "data": {
    "alert": "This is a test!!",
    "sound": "default",
    "badge": 1
  },
  "where": {
    "channels": "puc"
    }
  }
}

发送到特定设备令牌/令牌:

{
  "data": {
    "alert": "This is a test!!",
    "sound": "default",
    "badge": 1
  },
  "where": {
    "channels": "puc",
    "deviceToken": {
      "$in": [
        "DSFSAFJDSLKWRJKLJGLKASGLK"
      ]
    }
  }
}

如果您需要传递数组,则必须像使用" deviceToken"那样使用$in

或者,当您没有除频道之外的任何其他标准时,您不需要放置where子句:

{
  "data": {
    "alert": "This is a test!!",
    "sound": "default",
    "badge": 1
  },
  "channels": [
    "puc"
  ]
}

您可以在文档中找到更多示例和信息:https://parse.com/docs/rest/guide/#push-notifications-sending-pushes