package cn.gistack.sm.intelligentCall.controller;
|
|
import cn.gistack.sm.intelligentCall.constant.CallConstant;
|
import cn.gistack.sm.intelligentCall.entity.User;
|
import cn.gistack.sm.intelligentCall.util.HttpClientUtils;
|
import com.alibaba.fastjson.JSON;
|
import io.swagger.annotations.Api;
|
import lombok.AllArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springblade.core.tool.api.R;
|
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.*;
|
|
/**
|
* 智能呼叫控制层
|
* @author zhongrj
|
* @date 2023-04-21
|
*/
|
@Slf4j
|
@Api(tags = "智能呼叫")
|
@RestController
|
@RequestMapping("/call/call")
|
@AllArgsConstructor
|
public class CallController {
|
|
/**
|
* 创建任务
|
* @return
|
*/
|
@GetMapping("/createCall2")
|
public R createCall2(){
|
String url2 = CallConstant.HOST + CallConstant.createTaskUrl1;
|
// 请求2
|
Map<String, Object> map = new HashMap<>();
|
map.put("p2",createCall(url2));
|
// 返回
|
return R.data(map);
|
}
|
|
/**
|
* 创建任务
|
* @param url
|
* @return
|
*/
|
public String createCall(String url){
|
// 计算token
|
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;
|
// 请求参数拼接
|
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("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);
|
// 返回
|
return httpPost;
|
}
|
|
|
|
// /**
|
// * 测试
|
// * @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);
|
//
|
// }
|
|
/**
|
* 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;
|
}
|
}
|