我正在尝试使用 RoyalPay SDK 创建订单并进行支付宝付款。响应代码是 200,但我无法解析 JSON 作为响应。
我该如何解决这个问题?
我创建 api 请求的代码:
interface RoyalPayApi {
@FormUrlEncoded
@Headers("Accept: application/json", "Content-Type: application/json")
@PUT("/api/v1.0/gateway/partners/{partner_code}/app_orders/{order_id}")
fun createRoyalPaySDKOrder(@Path(value = "partner_code", encoded = true) partner_code: String, @Path(value = "order_id", encoded = true) order_id: String,
@Query("time") time: Long, @Query("nonce_str") nonce_str: String, @Query("sign") sign: String,
@Field("description") description: String,
@Field("price") price: Int,
@Field("currency") currency: String,
@Field("channel") channel: String,
@Field("operator") operator: String,
@Field("system") system: String): Call<JSONObject> // com.alibaba.fastjson.JSONObject
}
我得到改造服务的代码:
fun createService(): RoyalPayApi {
val retrofit = Retrofit.Builder()
.baseUrl(ROYAL_PAY_ADDRESS)
.addConverterFactory(FastJsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
return retrofit.create(RoyalPayApi::class.java)
}
我发送请求和接收响应的代码:
var api = createService()
var call = api.createRoyalPaySDKOrder(ROYAL_PAY_PARTNER_CODE, order_id, time, ROYAL_PAY_NONCE_STR, sign,
description, price, "AUD", channel, "kate", "android")
call.enqueue(object : Callback<JSONObject>{
override fun onResponse(call: Call<JSONObject>, response: Response<JSONObject>) {
val str = ""
}
override fun onFailure(call: Call<JSONObject>, t: Throwable) {
val str = ""
}
})
这是我收到的回复:
这是响应体(这里中文应该不影响理解):
这包括原始响应(使用 com.google.gson.JsonObject):