|
|
@ -1,5 +1,7 @@ |
|
|
|
package awesome.group.game.service; |
|
|
|
|
|
|
|
import awesome.group.game.service.bo.citrus.UMengRes; |
|
|
|
import awesome.group.game.service.bo.matrix.UmengConfigBo; |
|
|
|
import awesome.group.game.service.common.exception.PaganiException; |
|
|
|
import awesome.group.game.service.common.exception.PaganiExceptionCode; |
|
|
|
import awesome.group.game.service.common.log.L; |
|
|
@ -36,17 +38,19 @@ public class UMengService { |
|
|
|
|
|
|
|
private final OkHttpClient httpClient = new OkHttpClient().newBuilder().connectTimeout(2, TimeUnit.SECONDS).readTimeout(5, TimeUnit.SECONDS).connectionPool(new ConnectionPool(8, 5, TimeUnit.MINUTES)).build(); |
|
|
|
|
|
|
|
public String getMobile(String token) { |
|
|
|
public String getMobile(String token, UmengConfigBo umengConfigBo) { |
|
|
|
Map<String, Object> data = new HashMap<>(); |
|
|
|
data.put("token", token); |
|
|
|
String api = "/api/v1/mobile/info?appkey=" + APP_KEY_UMENT; |
|
|
|
String res = doHttpPost(api, data); |
|
|
|
System.out.println(res); |
|
|
|
|
|
|
|
return res; |
|
|
|
String api = "/api/v1/mobile/info?appkey=" + umengConfigBo.umengAppKey; |
|
|
|
String res = doHttpPost(api, data, umengConfigBo); |
|
|
|
UMengRes uMengRes = gson.fromJson(res, UMengRes.class); |
|
|
|
if (uMengRes.success) { |
|
|
|
return uMengRes.data.mobile; |
|
|
|
} |
|
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "获取手机号失败"); |
|
|
|
} |
|
|
|
|
|
|
|
public String doHttpPost(String url, Map<String, Object> jsonBody) { |
|
|
|
public String doHttpPost(String url, Map<String, Object> jsonBody, UmengConfigBo configBo) { |
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
String body = gson.toJson(jsonBody); |
|
|
|
|
|
|
@ -55,7 +59,7 @@ public class UMengService { |
|
|
|
header.put("X-Ca-Version", "1"); |
|
|
|
header.put("X-Ca-Signature-Headers", "X-Ca-Version,X-Ca-Stage,X-Ca-Key,X-Ca-Timestamp"); |
|
|
|
header.put("X-Ca-Stage", "RELEASE"); |
|
|
|
header.put("X-Ca-Key", APP_KEY); |
|
|
|
header.put("X-Ca-Key", configBo.umengAppKeyAli); |
|
|
|
header.put("X-Ca-Timestamp", String.valueOf(System.currentTimeMillis())); |
|
|
|
header.put("X-Ca-Nonce", UUID.randomUUID().toString()); |
|
|
|
header.put("Content-MD5", Base64.encodeBase64String(DigestUtils.md5(body.getBytes()))); |
|
|
@ -66,7 +70,7 @@ public class UMengService { |
|
|
|
|
|
|
|
try { |
|
|
|
Mac hmacSha256 = Mac.getInstance("HmacSHA256"); |
|
|
|
byte[] keyBytes = APP_SECRET.getBytes(StandardCharsets.UTF_8); |
|
|
|
byte[] keyBytes = configBo.umengAppSecret.getBytes(StandardCharsets.UTF_8); |
|
|
|
hmacSha256.init(new SecretKeySpec(keyBytes, 0, keyBytes.length, "HmacSHA256")); |
|
|
|
String sign = new String(Base64.encodeBase64(hmacSha256.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8)))); |
|
|
|
header.put("X-Ca-Signature", sign); |
|
|
|