|
|
@@ -6,6 +6,7 @@ import com.izouma.yags.domain.CampToken;
|
|
|
import com.izouma.yags.exception.BusinessException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.*;
|
|
|
+import okhttp3.logging.HttpLoggingInterceptor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
@@ -15,6 +16,21 @@ import java.util.List;
|
|
|
@Slf4j
|
|
|
public class CampApiService {
|
|
|
|
|
|
+ private volatile OkHttpClient client;
|
|
|
+
|
|
|
+ private OkHttpClient getClient() {
|
|
|
+ if (client == null) {
|
|
|
+ synchronized (CampApiService.class) {
|
|
|
+ if (client == null) {
|
|
|
+ client = new OkHttpClient.Builder()
|
|
|
+ .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return client;
|
|
|
+ }
|
|
|
+
|
|
|
private CampToken getCampToken() {
|
|
|
CampToken campToken = new CampToken();
|
|
|
campToken.setUserId("436174868");
|
|
|
@@ -37,22 +53,82 @@ public class CampApiService {
|
|
|
.url("https://ssl.kohsocialapp.qq.com:10001/game/battleprofile")
|
|
|
.post(formBody)
|
|
|
.build();
|
|
|
- try (Response response = client.newCall(request).execute()) {
|
|
|
+ try (Response response = getClient().newCall(request).execute()) {
|
|
|
ResponseBody responseBody = response.body();
|
|
|
if (responseBody != null) {
|
|
|
String body = responseBody.string();
|
|
|
- JSONObject res = JSON.parseObject(body);
|
|
|
- int returnCode = res.getInteger("returnCode");
|
|
|
- if (res.getInteger("returnCode") == 0) {
|
|
|
- QueryRole data = res.getObject("data", QueryRole.class);
|
|
|
+ ApiResponse res = JSON.parseObject(body, ApiResponse.class);
|
|
|
+ if (res.getReturnCode() == 0) {
|
|
|
+ QueryRole data = ((JSONObject) res.getData()).toJavaObject(QueryRole.class);
|
|
|
return data.getRolelist();
|
|
|
} else {
|
|
|
- String msg = res.getString("returnMsg");
|
|
|
- log.error("获取角色列表失败, returnCode={}, msg={}", returnCode, msg);
|
|
|
+ log.error("获取角色列表失败, returnCode={}, msg={}", res.getReturnCode(), res.getReturnMsg());
|
|
|
throw new BusinessException("查询游戏角色失败");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
throw new BusinessException("查询游戏角色失败");
|
|
|
}
|
|
|
+
|
|
|
+ public QueryBattle queryBattle(String roleId) throws IOException {
|
|
|
+ CampToken token = getCampToken();
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
+ content.put("friendRoleId", roleId);
|
|
|
+ content.put("userId", token.getUserId());
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .addHeader("userId", token.getUserId())
|
|
|
+ .addHeader("token", token.getToken())
|
|
|
+ .url("https://kohcamp.qq.com/game/morebattlelist")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json"), content.toJSONString()))
|
|
|
+ .build();
|
|
|
+ try (Response response = getClient().newCall(request).execute()) {
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String body = responseBody.string();
|
|
|
+ ApiResponse res = JSON.parseObject(body, ApiResponse.class);
|
|
|
+ if (res.getReturnCode() == 0) {
|
|
|
+ QueryBattle data = ((JSONObject) res.getData()).toJavaObject(QueryBattle.class);
|
|
|
+ return data;
|
|
|
+ } else {
|
|
|
+ log.error("查询对战信息失败, returnCode={}, msg={}", res.getReturnCode(), res.getReturnMsg());
|
|
|
+ throw new BusinessException("查询对战信息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ throw new BusinessException("查询对战信息失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ public QueryBattleDetail queryBattleDetail(String gameSeq, String gameSvrId, Integer pvpType, String toAppRoleId, String relaySvrId) throws IOException {
|
|
|
+ CampToken token = getCampToken();
|
|
|
+ RequestBody content = new FormBody.Builder()
|
|
|
+ .add("gameSeq", gameSeq)
|
|
|
+ .add("gameSvrId", gameSvrId)
|
|
|
+ .add("pvpType", pvpType.toString())
|
|
|
+ .add("toAppRoleId", toAppRoleId)
|
|
|
+ .add("relaySvrId", relaySvrId)
|
|
|
+ .add("userId", token.getUserId())
|
|
|
+ .add("token", token.getToken())
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .addHeader("userId", token.getUserId())
|
|
|
+ .addHeader("token", token.getToken())
|
|
|
+ .url("https://ssl.kohsocialapp.qq.com:10001/role/h5getplaydetail")
|
|
|
+ .post(content)
|
|
|
+ .build();
|
|
|
+ try (Response response = getClient().newCall(request).execute()) {
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String body = responseBody.string();
|
|
|
+ ApiResponse res = JSON.parseObject(body, ApiResponse.class);
|
|
|
+ if (res.getReturnCode() == 0) {
|
|
|
+ QueryBattleDetail data = ((JSONObject) res.getData()).toJavaObject(QueryBattleDetail.class);
|
|
|
+ return data;
|
|
|
+ } else {
|
|
|
+ log.error("查询对战信息失败, returnCode={}, msg={}", res.getReturnCode(), res.getReturnMsg());
|
|
|
+ throw new BusinessException("查询对战信息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ throw new BusinessException("查询对战信息失败");
|
|
|
+ }
|
|
|
}
|