From fc030d197a869d5fecab582d36ff17be7e67cc3f Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Mon, 24 Apr 2023 15:41:22 +0800
Subject: [PATCH] 巡查工作流接入
---
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/intelligentCall/controller/CallController.java | 217 +++++++++++++++++++++++++++++-------------------------
1 files changed, 117 insertions(+), 100 deletions(-)
diff --git a/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/intelligentCall/controller/CallController.java b/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/intelligentCall/controller/CallController.java
index 4896522..144fdf1 100644
--- a/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/intelligentCall/controller/CallController.java
+++ b/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/intelligentCall/controller/CallController.java
@@ -1,6 +1,9 @@
package cn.gistack.sm.intelligentCall.controller;
import cn.gistack.sm.intelligentCall.constant.CallConstant;
+import cn.gistack.sm.intelligentCall.entity.ThirdBaseParam;
+import cn.gistack.sm.intelligentCall.entity.ThirdPartyResult;
+import cn.gistack.sm.intelligentCall.entity.ThirdRequestHead;
import cn.gistack.sm.intelligentCall.entity.User;
import cn.gistack.sm.intelligentCall.util.HttpClientUtils;
import com.alibaba.fastjson.JSON;
@@ -15,6 +18,10 @@
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
+
+import static cn.gistack.sm.intelligentCall.util.CallUtil.getRandom;
+import static cn.gistack.sm.intelligentCall.util.CallUtil.getToken;
+import static cn.gistack.sm.intelligentCall.util.ThirdPartyValidate.validateToken;
/**
* 智能呼叫控制层
@@ -32,56 +39,128 @@
* 创建任务
* @return
*/
- @GetMapping("/createCall2")
- public R createCall2(){
- String url2 = CallConstant.HOST + CallConstant.createTaskUrl1;
- // 请求2
+ @GetMapping("/createCall")
+ public R createCall(){
+ // 请求
Map<String, Object> map = new HashMap<>();
- map.put("p2",createCall(url2));
+ map.put("p1",createCallUtil());
// 返回
return R.data(map);
}
/**
* 创建任务
- * @param url
* @return
*/
- public String createCall(String url){
- // 计算token
+ @GetMapping("/createCall1")
+ public R createCall1(){
+ // 请求
+ Map<String, Object> map = new HashMap<>();
+ map.put("p1",createCallUtil());
+ // 返回
+ return R.data(map);
+ }
+
+ /**
+ * 创建任务
+ * @return
+ */
+ public static String createCallUtil(){
Date date = new Date();
- String dateFormat0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
- String dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(date);
- String dateFormats = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date);
- Random random = new Random();
- //把随机生成的数字转成字符串
- String str = String.valueOf(random.nextInt(9));
- for (int i = 0; i < 5; i++) {
- str += random.nextInt(9);
- }
- String formatString ="appId" + CallConstant.AppKey
- + "timestamp" + dateFormat
- + "transId" + dateFormats
- + str;
- // 请求参数拼接
+ String dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
+ String timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(date);
+ String transId = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date) + getRandom();
+
Map<String, Object> map = new HashMap<>();
map.put("taskName","测试");
- map.put("sceneId",1);
- map.put("callingNumbers", Arrays.asList(101,102));
- map.put("taskScheduleTime",dateFormat0);
- List<User> list = new ArrayList<>();
- User user = new User();
- user.setName("张三");
- user.setPhone("15170720695");
- user.setName("先生");
- list.add(user);
+ map.put("sceneId",230);
+ map.put("callingNumbers", Arrays.asList("00862787222298"));
+ map.put("taskScheduleTime",dateFormat);
+ List<Map<String,Object>> list = new ArrayList<>();
+ Map<String,Object> maps = new HashMap<>();
+ maps.put("被叫号码","15170720695");
+ maps.put("水库名称","测试水库");
+ maps.put("超汛限多少米","0");
+ maps.put("水库编码","1241241122");
+ maps.put("用户名","zrj");
+ maps.put("用户id","123456");
+ list.add(maps);
map.put("calleeData",list);
- String jsonString = JSON.toJSONString(map);
- String lastString = formatString + jsonString + CallConstant.AppSecret;
- // md5 小写,md5 生成token
- String encryption = encryption(lastString);
- String httpPost = HttpClientUtils.httpPost(url, CallConstant.AppKey, dateFormat, dateFormats + str, encryption, map);
+ ThirdBaseParam thirdBaseParam = new ThirdBaseParam();
+ ThirdRequestHead thirdRequestHead = new ThirdRequestHead();
+ thirdRequestHead.setAppId(CallConstant.AppKey);
+ thirdRequestHead.setTimestamp(timestamp);
+ thirdRequestHead.setToken(getToken(timestamp, transId, map));
+ thirdRequestHead.setTransId(transId);
+ thirdBaseParam.setHead(thirdRequestHead);
+ thirdBaseParam.setSecretString(JSON.toJSONString(map));
+
+ // 验证token
+ boolean b = validateToken(thirdBaseParam, CallConstant.AppSecret, new ThirdPartyResult());
+ System.out.println("token 验证结果 = " + b);
+
+ String token = getToken(timestamp, transId, map);
+ String url = CallConstant.HOST + CallConstant.createTaskUrl1;
+ String httpPost = HttpClientUtils.httpPost(url, CallConstant.AppKey, timestamp, transId, token, map);
+ // 返回
+ return httpPost;
+ }
+
+ /**
+ * 创建任务
+ * @return
+ */
+ public static String createCallUtil1(){
+ Date date = new Date();
+ String dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
+ String timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(date);
+ String transId = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date) + getRandom();
+
+ Map<String, Object> map = new HashMap<>();
+ map.put("taskName","测试");
+ map.put("sceneId",230);
+ map.put("callingNumbers", Arrays.asList("00862787222298"));
+ map.put("taskScheduleTime",dateFormat);
+ List<Map<String,Object>> list = new ArrayList<>();
+ Map<String,Object> maps = new HashMap<>();
+ maps.put("被叫号码","15170720695");
+ maps.put("水库名称","测试水库");
+ maps.put("超汛限多少米","0");
+ maps.put("水库编码","1241241122");
+ maps.put("用户名","zrj");
+ maps.put("用户id","123456");
+ list.add(maps);
+ map.put("calleeData",list);
+
+ String token = getToken(timestamp, transId, map);
+ String jsonString = JSON.toJSONString(map);
+ HashMap<Object, Object> hashMap = new HashMap<>(4);
+ hashMap.put("appId",CallConstant.AppKey);
+ hashMap.put("timestamp",timestamp);
+ hashMap.put("transId",transId);
+ hashMap.put("token",token);
+
+ Map<String, String> stringHashMap = new HashMap<>();
+ stringHashMap.put("head",hashMap.toString());
+ stringHashMap.put("body",jsonString);
+
+ ThirdBaseParam thirdBaseParam = new ThirdBaseParam();
+ ThirdRequestHead thirdRequestHead = new ThirdRequestHead();
+ thirdRequestHead.setAppId(CallConstant.AppKey);
+ thirdRequestHead.setTimestamp(timestamp);
+ thirdRequestHead.setToken(token);
+ thirdRequestHead.setTransId(transId);
+ thirdBaseParam.setHead(thirdRequestHead);
+ thirdBaseParam.setSecretString(JSON.toJSONString(map));
+
+ // 验证token
+ boolean b = validateToken(thirdBaseParam, CallConstant.AppSecret, new ThirdPartyResult());
+ System.out.println("token 验证结果 = " + b);
+
+
+ String url = CallConstant.HOST + CallConstant.createTaskUrl1;
+ String httpPost = HttpClientUtils.doPost(url, stringHashMap);
// 返回
return httpPost;
}
@@ -93,72 +172,10 @@
// * @param args
// */
// public static void main(String[] args) {
-// // 计算token
-// Date date = new Date();
-// String dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(date);
-// String dateFormats = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date);
-// Random random = new Random();
-// //把随机生成的数字转成字符串
-// String str = String.valueOf(random.nextInt(9));
-// for (int i = 0; i < 5; i++) {
-// str += random.nextInt(9);
-// }
-// String formatString ="appId" + CallConstant.AppKey
-// + "timestamp" + dateFormat
-// + "transId" + dateFormats
-// + str;
-// // 请求参数拼接
// Map<String, Object> map = new HashMap<>();
-// map.put("taskName","测试");
-// map.put("sceneId",1);
-// map.put("callingNumbers", Arrays.asList(101,102));
-// map.put("taskScheduleTime","2020-02-29 14:00:00");
-// List<User> list = new ArrayList<>();
-// User user = new User();
-// user.setName("张三");
-// user.setPhone("15170720695");
-// user.setName("先生");
-// list.add(user);
-// map.put("calleeData",list);
-// String jsonString = JSON.toJSONString(map);
-// String lastString = formatString + jsonString + CallConstant.AppSecret;
-// // md5 小写,md5 生成token
-// String encryption = encryption(lastString);
-// String url = CallConstant.HOST + CallConstant.createTaskUrl;
-// String httpPost = HttpClientUtils.httpPost(url, CallConstant.AppKey, dateFormat, dateFormats + str, encryption, map);
-//
-//
-// System.out.println("encryption = " + encryption);
+// map.put("p1",createCallUtil());
+//// map.put("p1",createCallUtil());
//
// }
- /**
- * md5加密 32位 小写
- * @param plainText
- * @return
- */
- public static String encryption(String plainText) {
- String re_md5 = new String();
- try {
- MessageDigest md = MessageDigest.getInstance("MD5");
- md.update(plainText.getBytes());
- byte b[] = md.digest();
- int i;
- StringBuffer buf = new StringBuffer("");
- for (int offset = 0; offset < b.length; offset++) {
- i = b[offset];
- if (i < 0) {
- i += 256;
- }
- if (i < 16) {
- buf.append("0");
- }
- buf.append(Integer.toHexString(i));
- }
- re_md5 = buf.toString();
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- return re_md5;
- }
}
--
Gitblit v1.9.3