|
@@ -0,0 +1,89 @@
|
|
|
+package com.zanxiang.game.module.manage.service.impl;
|
|
|
+
|
|
|
+import com.zanxiang.module.util.JsonUtil;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author : lingfeng
|
|
|
+ * @time : 2024-02-22
|
|
|
+ * @description : CP接口交互
|
|
|
+ */
|
|
|
+public class CpCallServiceImpl {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * MD5加密
|
|
|
+ */
|
|
|
+ private static final String SIGN_MD5 = "MD5";
|
|
|
+
|
|
|
+// public static void main(String[] args) throws Exception{
|
|
|
+// test();
|
|
|
+// }
|
|
|
+
|
|
|
+ public static void test() throws Exception {
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+
|
|
|
+ String url = "https://ht.lttx.t5yx.cn/extapi?action=BgzszhSendTip";
|
|
|
+
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+
|
|
|
+ String msgId = "testMsgId";
|
|
|
+ param.put("msgId", msgId);
|
|
|
+
|
|
|
+ String strRan = "strRan";
|
|
|
+ param.put("strRan", strRan);
|
|
|
+
|
|
|
+ Long time = 1708484041L;
|
|
|
+ param.put("time", time);
|
|
|
+
|
|
|
+ String signStr = "key=asd123&msgId=" + msgId + "&strRan=" + strRan + "&time=" + time;
|
|
|
+
|
|
|
+ System.out.println("加密字符串 : " + signStr);
|
|
|
+
|
|
|
+
|
|
|
+ param.put("sign", CpCallServiceImpl.MD5(signStr));
|
|
|
+
|
|
|
+ param.put("serverid", 226);
|
|
|
+ List<String> roleIds = new ArrayList<>();
|
|
|
+ roleIds.add("798136551028973749");
|
|
|
+ param.put("roleIds", roleIds);
|
|
|
+
|
|
|
+ param.put("pushType", 1);
|
|
|
+
|
|
|
+ Map<String, Object> msgContent = new HashMap<>();
|
|
|
+ msgContent.put("text", "测试消息");
|
|
|
+ List<String> imgs = new ArrayList<>();
|
|
|
+ imgs.add("https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF");
|
|
|
+ msgContent.put("imgs", JsonUtil.toString(imgs));
|
|
|
+ param.put("msgContent", msgContent);
|
|
|
+
|
|
|
+ System.out.println("接口参数 param :" + JsonUtil.toString(param));
|
|
|
+
|
|
|
+
|
|
|
+ String result = restTemplate.postForObject(url, JsonUtil.toString(param), String.class);
|
|
|
+
|
|
|
+ System.out.println("返回结果" + result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * MD5加密
|
|
|
+ *
|
|
|
+ * @param data 待处理数据
|
|
|
+ * @return MD5结果
|
|
|
+ */
|
|
|
+ public static String MD5(String data) throws Exception {
|
|
|
+ java.security.MessageDigest md = MessageDigest.getInstance(SIGN_MD5);
|
|
|
+ byte[] array = md.digest(data.getBytes(StandardCharsets.UTF_8));
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (byte item : array) {
|
|
|
+ sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3);
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+}
|