我目前正在使用PHP的Firebase消息传递。我能够让它与PHP和cURL一起使用一个通知。我读过关于发出批处理请求的文献资料,并按照以下方式构造了请求字符串:
--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary
Authorization: Bearer ya29.xxxxxnY
POST /v1/projects/xxxxxxxx/messages:send
Content-Type: application/json
accept: application/json
{
"message":{
"token":"cxxxxx3",
"data":{
"typeNoti":"paiement",
"idcompte":"admin",
"typecompte":"paiement"
},
"notification":{
"title":"Test1",
"body":"Notification de test 1"
}
}
}
--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary
Authorization: Bearer yaxxxxxxY
POST /v1/projects/xxxxxx/messages:send
Content-Type: application/json
accept: application/json
{
"message":{
"token":"eoxxxxxU1",
"data":{
"typeNoti":"paiement",
"idcompte":"compte2",
"typecompte":"paiement"
},
"notification":{
"title":"Test1",
"body":"Notification de test 1"
}
}
}
--subrequest_boundary--
如文档所述,这个字符串是在一个名为batch_request.txt的文件中生成的。当尝试用cURL发送请求时,我会收到以下错误:
{
"error": {
"code": 400,
"message": "Failed to parse batch request, error: 0 items. Received batch body: (0) bytes redacted",
"status": "INVALID_ARGUMENT"
}
}
我也经历过一种奇怪的行为,即当我手动构造该字符串(在PHP中我使用HEREDOC)时,批处理请求确实发生在200ok响应中。我试过找一些隐藏的角色,但是找不到。
我知道有一个叫做firebase-php的图书馆。问题是我找不到这样一个直截了当的例子:
//authenticate with json file
//create new token if it doesn't exist or skip
//create notification array
//create data array
//send multi notifications to multiple devices
我实际上使用了for循环和mono通知(一次一个设备令牌,一个消息)。问题是,并不是所有的通知都是发送的。
非常感谢你的帮助谢谢!
发布于 2022-11-30 11:38:58
我从firebase-php文档中收集了代码。在使用composer安装库之后,我在供应商内部的Firebase目录中获得了许多错误和大量丢失的文件,如Factory.php等。
我的解决方案是不使用firebase-php库,因为我遇到了许多错误(或者错误使用),也没有为批处理请求构建REST请求文本文件。我使用的是NodeJS SDK,它很有魅力。我正在使用exec从我的php代码运行一个javascript文件。
https://stackoverflow.com/questions/74559273
复制相似问题