更新 NetworkUtil.java

dev
wangsiyuan 2023-12-12 16:53:10 +08:00
parent 5fd4acf9fb
commit a5e081a0a1
1 changed files with 6 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import com.google.gson.Gson;
import com.nbee.echolink.R;
import com.nbee.echolink.model.CallInfo;
import com.nbee.echolink.model.SMSInfo;
import com.nbee.echolink.model.WeChatMsg;
import com.nbee.echolink.response.ApiResponse;
@ -22,6 +23,7 @@ public class NetworkUtil {
private final String TAG = "NetworkUtil";
private String callApiUrl;
private String smsApiUrl;
private String wechatApiUrl;
private String accessToken;
private Handler handler = new Handler();
private static final int MAX_RETRIES = 3;
@ -33,6 +35,7 @@ public class NetworkUtil {
public NetworkUtil(Context context) {
callApiUrl = context.getResources().getString(R.string.call_api_url);
smsApiUrl = context.getResources().getString(R.string.message_api_url);
wechatApiUrl= context.getResources().getString(R.string.send_wechat_msg_api_url);
accessToken = context.getResources().getString(R.string.access_token);
}
@ -42,6 +45,8 @@ public class NetworkUtil {
postRequestWithRetry(dataObject, 0, callApiUrl);
} else if (dataObject instanceof SMSInfo) {
postRequestWithRetry(dataObject, 0, smsApiUrl);
} else if (dataObject instanceof WeChatMsg){
postRequestWithRetry(dataObject,0,wechatApiUrl);
}
}
@ -73,6 +78,7 @@ public class NetworkUtil {
// ... 处理响应 ...
Gson gson1 = new Gson();
ApiResponse apiResponse = gson1.fromJson(response.body().string(), ApiResponse.class);
Timber.d("ApiResponse" + apiResponse);
if (apiResponse.getCode().equals(0)){
Timber.d("Received response from " + apiUrl + ": " + apiResponse.getCode() + " - " + apiResponse.getMsg());
}