guoshilong
2023-04-24 5c7dab639fffc0fe7d453c5c5153ddb6036fe45a
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/intelligentCall/controller/CallController.java
@@ -1,12 +1,6 @@
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;
import cn.gistack.sm.intelligentCall.service.CallService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -14,14 +8,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.security.MessageDigest;
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;
/**
 * 智能呼叫控制层
@@ -35,147 +22,36 @@
@AllArgsConstructor
public class CallController {
   private final CallService callService;
   /**
    * 创建任务
    * @return
    */
   @GetMapping("/createCall")
   public R createCall(){
      // 请求
      Map<String, Object> map = new HashMap<>();
      map.put("p1",createCallUtil());
      // 返回
      return R.data(map);
   }
   /**
    * 创建任务
    * @return
    */
   @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 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<Map<String,String>> list = new ArrayList<>();
      Map<String,String> maps = new HashMap<>();
      maps.put("phone","15170720695");
      maps.put("name","测试水库");
      maps.put("over","1.2");
      maps.put("code","1241241122");
      maps.put("userName","zrj");
      maps.put("userId","123456");
      list.add(maps);
      map.put("calleeData",list);
      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);
      callService.createTask(list);
      // 返回
      return httpPost;
      return R.status(true);
   }
   /**
    * 创建任务
    * 获取通话详情
    * @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);
   @GetMapping("/getCallDetail")
   public R getCallDetail(String taskId,String calleeNumber){
      // 返回
      return httpPost;
      return R.data(callService.getCallDetail(taskId,calleeNumber));
   }
//   /**
//    * 测试
//    * @param args
//    */
//   public static void main(String[] args) {
//      Map<String, Object> map = new HashMap<>();
//      map.put("p1",createCallUtil());
////      map.put("p1",createCallUtil());
//
//   }
}