package com.example.firstapp.database.service
|
|
import com.example.firstapp.database.response.SmsProcessResponse
|
import retrofit2.Retrofit
|
import retrofit2.converter.gson.GsonConverterFactory
|
import retrofit2.http.Body
|
import retrofit2.http.POST
|
|
/**
|
* 模型相关接口
|
*/
|
interface ModelService {
|
|
@POST("process-sms")
|
suspend fun processSms(@Body body: Map<String, String>): SmsProcessResponse
|
}
|
|
// 创建Retrofit实例(单例)
|
object RetrofitModelClient {
|
|
private const val BASE_URL = "http://192.168.1.213:5000/"
|
|
//添加Gson解析器,用于自动将JSON响应转换为Kotlin/Java对象
|
private val retrofit = Retrofit
|
.Builder()
|
.baseUrl(BASE_URL)
|
.addConverterFactory(GsonConverterFactory.create())
|
.build()
|
|
//通过动态代理技术创建ApiService接口的具体实现类
|
val modelService: ModelService = retrofit.create(ModelService::class.java)
|
|
}
|