|
|
@@ -0,0 +1,58 @@
|
|
|
+package com.izouma.yags.camp.api;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.izouma.yags.domain.CampToken;
|
|
|
+import com.izouma.yags.exception.BusinessException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.*;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class CampApiService {
|
|
|
+
|
|
|
+ private CampToken getCampToken() {
|
|
|
+ CampToken campToken = new CampToken();
|
|
|
+ campToken.setUserId("436174868");
|
|
|
+ campToken.setToken("EA8fkgWs");
|
|
|
+ return campToken;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<RongYaoRole> getRoleItems(String userId) throws IOException {
|
|
|
+ OkHttpClient client = new OkHttpClient();
|
|
|
+ CampToken token = getCampToken();
|
|
|
+ RequestBody formBody = new FormBody.Builder()
|
|
|
+ .add("friendUserId", userId)
|
|
|
+ .add("gameId", "20001")
|
|
|
+ .add("token", token.getToken())
|
|
|
+ .add("userId", token.getUserId())
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .addHeader("userId", token.getUserId())
|
|
|
+ .addHeader("token", token.getToken())
|
|
|
+ .url("https://ssl.kohsocialapp.qq.com:10001/game/battleprofile")
|
|
|
+ .post(formBody)
|
|
|
+ .build();
|
|
|
+ try (Response response = client.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);
|
|
|
+ return data.getRolelist();
|
|
|
+ } else {
|
|
|
+ String msg = res.getString("returnMsg");
|
|
|
+ log.error("获取角色列表失败, returnCode={}, msg={}", returnCode, msg);
|
|
|
+ throw new BusinessException("查询游戏角色失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ throw new BusinessException("查询游戏角色失败");
|
|
|
+ }
|
|
|
+}
|