zhongrj
2023-04-24 c72f2110a469f603ff09f006aad3256e21523c9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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 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.*;
 
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;
 
/**
 * 智能呼叫控制层
 * @author zhongrj
 * @date 2023-04-21
 */
@Slf4j
@Api(tags = "智能呼叫")
@RestController
@RequestMapping("/call/call")
@AllArgsConstructor
public class CallController {
 
    /**
     * 创建任务
     * @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.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);
        // 返回
        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;
    }
 
 
 
//    /**
//     * 测试
//     * @param args
//     */
//    public static void main(String[] args) {
//        Map<String, Object> map = new HashMap<>();
//        map.put("p1",createCallUtil());
////        map.put("p1",createCallUtil());
//
//    }
 
}