post请求firebase推送通知什么都没有发生

niwlg2el  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(288)

//我正在尝试对推送通知执行post请求,但什么也没发生。。
//接口

interface RestInterface {
    @Headers("Content-Type: application/json", "Authorization: key)
    @POST("fcm/send")
    fun sendingNotification(@Body body: NotificationBody?): Call<ResponseBody?>?
 }

//通知正文

class NotificationBody(data: Data, to: String) {
    @SerializedName("notification")
    private val data: Data

    @SerializedName("to")
    private val to: String

    init {
        this.data = data
        this.to = to
    }
}

//数据类

class Data
 (@field:SerializedName("title")
 private val title: String,
 @field:SerializedName("content")
 private val content: String)

//改装请求

fun sentNotification() {
    val retrofit = Retrofit.Builder()

            .baseUrl("https://fcm.googleapis.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .build()

    var title = "My Title";
    var content = "My message";
    var to = deviceId

    var data = Data(title, content);
    var body = NotificationBody(data, to);

    val service = retrofit.create(RestInterface::class.java)

    val response = service.sendingNotification(body)

我实现了响应代码,但是得到了很多错误。提醒一下,我和Kotlin不是 java 。

response.enqueue( Callback<ResponseBody>() {
     @Override
     public void onResponse(retrofit2.Call<ResponseBody> call, 
   retrofit2.Response<ResponseBody> response) {
         Log.d("kkkk","done");
     }

     @Override
     public void onFailure(retrofit2.Call<ResponseBody> call, 
    Throwable t) {

     }
 })

}

//上面的请求设置有什么问题//如果与 Postman 一起发送信息,则通知会显示在手机上,因此onmessagereceived设置正常

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题