正在显示
9 个修改的文件
包含
1069 行增加
和
2 行删除
@@ -37,6 +37,16 @@ | @@ -37,6 +37,16 @@ | ||
37 | <artifactId>mybatis-spring-boot-starter</artifactId> | 37 | <artifactId>mybatis-spring-boot-starter</artifactId> |
38 | <version>2.1.1</version> | 38 | <version>2.1.1</version> |
39 | </dependency> | 39 | </dependency> |
40 | + <dependency> | ||
41 | + <groupId>cn.hutool</groupId> | ||
42 | + <artifactId>hutool-all</artifactId> | ||
43 | + <version>4.0.12</version> | ||
44 | + </dependency> | ||
45 | + <!--websocket--> | ||
46 | + <dependency> | ||
47 | + <groupId>org.springframework.boot</groupId> | ||
48 | + <artifactId>spring-boot-starter-websocket</artifactId> | ||
49 | + </dependency> | ||
40 | <!--clound--> | 50 | <!--clound--> |
41 | <dependency> | 51 | <dependency> |
42 | <groupId>org.springframework.cloud</groupId> | 52 | <groupId>org.springframework.cloud</groupId> |
@@ -198,5 +208,35 @@ | @@ -198,5 +208,35 @@ | ||
198 | </plugin> | 208 | </plugin> |
199 | </plugins> | 209 | </plugins> |
200 | </build> | 210 | </build> |
211 | + <repositories> | ||
212 | + <repository> | ||
213 | + <id>spring-snapshots</id> | ||
214 | + <name>Spring Snapshots</name> | ||
215 | + <url>https://repo.spring.io/snapshot</url> | ||
216 | + <snapshots> | ||
217 | + <enabled>true</enabled> | ||
218 | + </snapshots> | ||
219 | + </repository> | ||
220 | + <repository> | ||
221 | + <id>spring-milestones</id> | ||
222 | + <name>Spring Milestones</name> | ||
223 | + <url>https://repo.spring.io/milestone</url> | ||
224 | + </repository> | ||
225 | + </repositories> | ||
226 | + <pluginRepositories> | ||
227 | + <pluginRepository> | ||
228 | + <id>spring-snapshots</id> | ||
229 | + <name>Spring Snapshots</name> | ||
230 | + <url>https://repo.spring.io/snapshot</url> | ||
231 | + <snapshots> | ||
232 | + <enabled>true</enabled> | ||
233 | + </snapshots> | ||
234 | + </pluginRepository> | ||
235 | + <pluginRepository> | ||
236 | + <id>spring-milestones</id> | ||
237 | + <name>Spring Milestones</name> | ||
238 | + <url>https://repo.spring.io/milestone</url> | ||
239 | + </pluginRepository> | ||
240 | + </pluginRepositories> | ||
201 | 241 | ||
202 | </project> | 242 | </project> |
@@ -8,6 +8,7 @@ import com.sunyo.customer.order.activity.dao.JOBMapper; | @@ -8,6 +8,7 @@ import com.sunyo.customer.order.activity.dao.JOBMapper; | ||
8 | import com.sunyo.customer.order.activity.dao.ProcessFormMapper; | 8 | import com.sunyo.customer.order.activity.dao.ProcessFormMapper; |
9 | import com.sunyo.customer.order.activity.model.JOB; | 9 | import com.sunyo.customer.order.activity.model.JOB; |
10 | import com.sunyo.customer.order.activity.model.ProcessForm; | 10 | import com.sunyo.customer.order.activity.model.ProcessForm; |
11 | +import com.sunyo.customer.order.websocket.WebSocketServer; | ||
11 | import org.activiti.engine.*; | 12 | import org.activiti.engine.*; |
12 | import org.activiti.engine.repository.DeploymentBuilder; | 13 | import org.activiti.engine.repository.DeploymentBuilder; |
13 | import org.activiti.engine.repository.ProcessDefinition; | 14 | import org.activiti.engine.repository.ProcessDefinition; |
@@ -56,10 +57,11 @@ public class ProcessController { | @@ -56,10 +57,11 @@ public class ProcessController { | ||
56 | public ResultJson<PageInfo> startActivityDemo(@RequestParam(value = "pageNum",required = false,defaultValue = "1") | 57 | public ResultJson<PageInfo> startActivityDemo(@RequestParam(value = "pageNum",required = false,defaultValue = "1") |
57 | int pageNum, | 58 | int pageNum, |
58 | @RequestParam(value = "pageSize",required = false,defaultValue = "5") | 59 | @RequestParam(value = "pageSize",required = false,defaultValue = "5") |
59 | - int pageSize){ | 60 | + int pageSize)throws Exception{ |
60 | Page<ProcessForm> page = PageHelper.startPage(pageNum,pageSize); | 61 | Page<ProcessForm> page = PageHelper.startPage(pageNum,pageSize); |
61 | List<ProcessForm> list= processFormMapper.selectAllWithUser(); | 62 | List<ProcessForm> list= processFormMapper.selectAllWithUser(); |
62 | PageInfo<ProcessForm> result = new PageInfo<ProcessForm>(list); | 63 | PageInfo<ProcessForm> result = new PageInfo<ProcessForm>(list); |
64 | + | ||
63 | return new ResultJson("200","success",result); | 65 | return new ResultJson("200","success",result); |
64 | } | 66 | } |
65 | 67 |
1 | +package com.sunyo.customer.order.activity.controller; | ||
2 | + | ||
3 | +import com.sunyo.customer.order.activity.controller.response.ResultJson; | ||
4 | +import com.sunyo.customer.order.websocket.WebSocketServer; | ||
5 | +import org.springframework.web.bind.annotation.*; | ||
6 | +import org.springframework.web.servlet.ModelAndView; | ||
7 | + | ||
8 | +import java.io.IOException; | ||
9 | + | ||
10 | +/** | ||
11 | + * Created by XYH on 2019/12/24. | ||
12 | + */ | ||
13 | +@RestController | ||
14 | +@RequestMapping("/checkcenter") | ||
15 | +public class WebSocketController { | ||
16 | + //页面请求 | ||
17 | + @GetMapping("/socket/{cid}") | ||
18 | + public ResultJson socket(@PathVariable String cid) { | ||
19 | + | ||
20 | + return new ResultJson("200","success",cid); | ||
21 | + } | ||
22 | + //推送数据接口 | ||
23 | + /*@ResponseBody | ||
24 | + @RequestMapping("/socket/push/{cid}") | ||
25 | + public ResultJson pushToWeb(@PathVariable String cid,String message) { | ||
26 | + try { | ||
27 | + WebSocketServer.sendInfo(message,cid); | ||
28 | + } catch (IOException e) { | ||
29 | + e.printStackTrace(); | ||
30 | + return new ResultJson("200","success",cid+"#"+e.getMessage()); | ||
31 | + } | ||
32 | + return new ResultJson("200","success",cid); | ||
33 | + }*/ | ||
34 | +} |
1 | +package com.sunyo.customer.order.mydemo; | ||
2 | + | ||
3 | +import phonicapi.PhonicConst; | ||
4 | +import phonicapi.PhonicHandler; | ||
5 | +import phonicapi.PhonicNative; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by XYH on 2020/1/8. | ||
9 | + */ | ||
10 | +public class IncomingCall implements PhonicHandler { | ||
11 | + private int uBoxHndOne = 0; //线路1操作句柄 | ||
12 | + private int uBoxHndTwo = 0; //线路2操作句柄 | ||
13 | + private int uBoxId = 0;// 设备类型 | ||
14 | + private boolean bHookOff = false; | ||
15 | + private String strDir = "C:\\"; | ||
16 | + //打开设备 | ||
17 | + public boolean openUBox() | ||
18 | + { | ||
19 | + PhonicNative.ubox_open_logfile(0); | ||
20 | + int nOpen = PhonicNative.ubox_open(this, PhonicConst.WORK_MODE_RECORD); | ||
21 | + System.out.println("ubox_open="+nOpen); | ||
22 | + if(nOpen == 0) | ||
23 | + { | ||
24 | + return true; | ||
25 | + } | ||
26 | + return false; | ||
27 | + } | ||
28 | + | ||
29 | + //关闭设备 | ||
30 | + public boolean closeUBox() | ||
31 | + { | ||
32 | + uBoxHndOne = 0; | ||
33 | + uBoxHndTwo = 0; | ||
34 | + PhonicNative.ubox_close(); | ||
35 | + return true; | ||
36 | + } | ||
37 | + //设备事件 | ||
38 | + public void event(int uboxHnd, int eventID, int param1, int param2, int param3, int param4) { | ||
39 | + switch (eventID) | ||
40 | + { | ||
41 | + case UBOX_EVENT_DEVICE_PLUG_IN: | ||
42 | + { | ||
43 | + //检测型号正确 | ||
44 | + //if(1 == PhonicNative.ubox_get_product_ID(uboxHnd)) | ||
45 | + { | ||
46 | + if(0 == uBoxHndOne) | ||
47 | + { | ||
48 | + uBoxHndOne = uboxHnd; | ||
49 | + uBoxId = PhonicNative.ubox_get_product_ID(uboxHnd); | ||
50 | + System.out.println(PhonicNative.ubox_get_device_versionnum(uboxHnd)); | ||
51 | + System.out.println(PhonicNative.ubox_get_product_name(uboxHnd)); | ||
52 | + if(uBoxId == 8) //无线设备 | ||
53 | + { | ||
54 | + PhonicNative.ubox_set_gsm_work_mode(uboxHnd, 1, 0); //如果不用电话机,关闭电话机模式,否则振铃的时候,戴着耳麦会听到很大的给电话机送来电号码声音,体验效果不好。 | ||
55 | + } | ||
56 | + } | ||
57 | + else if(0 == uBoxHndTwo) | ||
58 | + { | ||
59 | + uBoxHndTwo = uboxHnd; | ||
60 | + } | ||
61 | + else | ||
62 | + { | ||
63 | + uBoxHndOne = uboxHnd; | ||
64 | + uBoxHndTwo = 0; | ||
65 | + } | ||
66 | + } | ||
67 | + System.out.println("收到设备插入事件:" + uboxHnd); | ||
68 | + } | ||
69 | + break; | ||
70 | + case UBOX_EVENT_DEVICE_PLUG_OUT: | ||
71 | + { | ||
72 | + System.out.println("收到设备拔出事件:" + uboxHnd); | ||
73 | + } | ||
74 | + break; | ||
75 | + case UBOX_EVENT_LINE_HOOK_UP: | ||
76 | + { | ||
77 | + | ||
78 | + if(uBoxId == 8) | ||
79 | + { | ||
80 | + if(param1 == 1) | ||
81 | + { | ||
82 | + System.out.println("收到GSM模块挂机:" + uboxHnd); | ||
83 | + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 0); //被叫能够听不到耳麦说话的声音 | ||
84 | + } | ||
85 | + else if(param1 == 2) | ||
86 | + { | ||
87 | + System.out.println("收到电话机挂机:" + uboxHnd); | ||
88 | + } | ||
89 | + else if(param1 == 3) | ||
90 | + { | ||
91 | + System.out.println("收到耳麦挂机:" + uboxHnd); | ||
92 | + } | ||
93 | + } | ||
94 | + else | ||
95 | + { | ||
96 | + System.out.println("收到设备挂机事件:" + uboxHnd); | ||
97 | + } | ||
98 | + } | ||
99 | + break; | ||
100 | + case UBOX_EVENT_LINE_HOOK_OFF: | ||
101 | + { | ||
102 | + if(uBoxId == 8) | ||
103 | + { | ||
104 | + if(param1 == 0) | ||
105 | + { | ||
106 | + System.out.println("收到电话机摘机:" + uboxHnd); | ||
107 | + } | ||
108 | + else if(param1 == 2) | ||
109 | + { | ||
110 | + System.out.println("收到耳麦摘机:" + uboxHnd); | ||
111 | + } | ||
112 | + else if(param1 == 6) | ||
113 | + { | ||
114 | + System.out.println("收到GSM模块摘机:" + uboxHnd); | ||
115 | + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 1); //被叫能够听到耳麦说话的声音 | ||
116 | + } | ||
117 | + } | ||
118 | + else | ||
119 | + { | ||
120 | + System.out.println("收到设备摘机事件:" + uboxHnd); | ||
121 | + } | ||
122 | + } | ||
123 | + break; | ||
124 | + case UBOX_EVENT_LINE_RINGING: | ||
125 | + { | ||
126 | + System.out.println("收到设备检测线路振铃开始事件:" + uboxHnd); | ||
127 | + } | ||
128 | + break; | ||
129 | + case UBOX_EVENT_DEVICE_PLAY_END: | ||
130 | + { | ||
131 | + System.out.println("收到放音结束事件:" + uboxHnd); | ||
132 | + } | ||
133 | + break; | ||
134 | + case UBOX_EVENT_RING_CANCEL: | ||
135 | + { | ||
136 | + System.out.println("收到设备检测线路振铃停止事件:" + uboxHnd); | ||
137 | + } | ||
138 | + break; | ||
139 | + case UBOX_EVENT_DEVICE_BUSY_TONE: | ||
140 | + { | ||
141 | + System.out.println("收到设备检测线路忙音事件:" + uboxHnd); | ||
142 | + } | ||
143 | + break; | ||
144 | + case UBOX_EVENT_ALARM: | ||
145 | + { | ||
146 | + System.out.println("收到设备工作警告事件:" + uboxHnd); | ||
147 | + } | ||
148 | + break; | ||
149 | + case UBOX_EVENT_DEVICE_ERROR: | ||
150 | + { | ||
151 | + System.out.println("收到设备错误事件:" + uboxHnd); | ||
152 | + } | ||
153 | + break; | ||
154 | + case UBOX_EVENT_LINE_RING_STOP: | ||
155 | + { | ||
156 | + System.out.println("收到设备检测线路振铃闪停事件:" + uboxHnd); | ||
157 | + } | ||
158 | + break; | ||
159 | + case UBOX_EVENT_LINE_HANG: | ||
160 | + { | ||
161 | + System.out.println("收到设备悬空事件:" + uboxHnd); | ||
162 | + } | ||
163 | + break; | ||
164 | + case UBOX_EVENT_LINE_VOLTAGE: | ||
165 | + { | ||
166 | + System.out.println("收到设备线路当前电压事件:" + uboxHnd); | ||
167 | + } | ||
168 | + break; | ||
169 | + case UBOX_EVENT_STREAM_VOICE: | ||
170 | + { | ||
171 | + System.out.println("收到流式录音数据包事件:" + uboxHnd); | ||
172 | + } | ||
173 | + break; | ||
174 | + case UBOX_EVENT_DTMF_DOWN: | ||
175 | + { | ||
176 | + //System.out.println("按键事件:" + uboxHnd); | ||
177 | + } | ||
178 | + break; | ||
179 | + case UBOX_EVENT_DTMF_UP: | ||
180 | + { | ||
181 | + System.out.println("收到按键释放事件:" + uboxHnd); | ||
182 | + } | ||
183 | + break; | ||
184 | + case UBOX_EVENT_DEVICE_PLAY_ERROR: | ||
185 | + { | ||
186 | + System.out.println("收到放音错误事件:" + uboxHnd); | ||
187 | + } | ||
188 | + break; | ||
189 | + case UBOX_EVENT_CALLOUTFINISH: | ||
190 | + { | ||
191 | + System.out.println("收到软件拨号完成事件:" + uboxHnd); | ||
192 | + } | ||
193 | + break; | ||
194 | + case UBOX_EVENT_POLARITY: | ||
195 | + { | ||
196 | + System.out.println("收到检测极性反转事件:" + uboxHnd); | ||
197 | + } | ||
198 | + break; | ||
199 | + case UBOX_EVENT_SIM_STATE: | ||
200 | + { | ||
201 | + if(param2 == 1) | ||
202 | + { | ||
203 | + System.out.println("卡状态事件, 当前选择sim卡" + param1); | ||
204 | + } | ||
205 | + else if(param2 == 2) | ||
206 | + { | ||
207 | + System.out.println("卡状态事件, sim卡" + param1 +" GSM 模块检查Sim卡未插入"); | ||
208 | + } | ||
209 | + else if(param2 == 3) | ||
210 | + { | ||
211 | + System.out.println("卡状态事件, sim卡" + param1 +" 检测到卡存在,并且是插好的"); | ||
212 | + } | ||
213 | + else if(param2 > 3) | ||
214 | + { | ||
215 | + System.out.println("卡状态事件, sim卡" + param1 +" 检测到卡有错误,错误值:"+param2); | ||
216 | + } | ||
217 | + } | ||
218 | + break; | ||
219 | + case UBOX_EVENT_ANSWER: | ||
220 | + { | ||
221 | + System.out.println(" 被叫已经应答了"); | ||
222 | + | ||
223 | + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 1); //被叫能够听到耳麦说话的声音 | ||
224 | + } | ||
225 | + break; | ||
226 | + case UBOX_EVENT_SIGNALE_SIZE: | ||
227 | + { | ||
228 | + System.out.println(" 信号大小:"+param1); | ||
229 | + } | ||
230 | + break; | ||
231 | + case UBOX_EVENT_SHORT_MSG_SIZE: | ||
232 | + { | ||
233 | + System.out.println(" 被叫已经应答了"); | ||
234 | + } | ||
235 | + break; | ||
236 | + case UBOX_EVENT_SIM_REG: | ||
237 | + { | ||
238 | + if(param2 == 0) | ||
239 | + { | ||
240 | + System.out.println("sim卡" + param1+1 + " 网络未注册,当前没有搜索到要注册业务的新营运商 "); | ||
241 | + } | ||
242 | + else if(param2 == 1) | ||
243 | + { | ||
244 | + System.out.println("sim卡" + param1+1 + " 网络已注册"); | ||
245 | + //btnCall.setEnabled(true); //网络已经注册好了,可以拨打电话和发短信 | ||
246 | + //btnSendMsg.setEnabled(true); | ||
247 | + } | ||
248 | + else if(param2 == 2) | ||
249 | + { | ||
250 | + System.out.println("sim卡" + param1+1 + " 网络未注册,正在搜索要注册业务的新营运商"); | ||
251 | + } | ||
252 | + else if(param2 == 3) | ||
253 | + { | ||
254 | + System.out.println("sim卡" + param1+1 + " 注册被拒绝"); | ||
255 | + } | ||
256 | + else if(param2 == 4) | ||
257 | + { | ||
258 | + System.out.println("sim卡" + param1+1 + " 未注册, 未知原因"); | ||
259 | + } | ||
260 | + else if(param2 == 5) | ||
261 | + { | ||
262 | + System.out.println("sim卡" + param1+1 + " 已注册,漫游"); | ||
263 | + } | ||
264 | + } | ||
265 | + break; | ||
266 | + case UBOX_EVENT_SHORT_MSG_SEND_REPORT: | ||
267 | + { | ||
268 | + if(param1 == 0) | ||
269 | + { | ||
270 | + System.out.println("短信发送失败"); | ||
271 | + } | ||
272 | + else if(param1 == 1) | ||
273 | + { | ||
274 | + System.out.println("短信发送成功"); | ||
275 | + } | ||
276 | + else if(param1 == 2) | ||
277 | + { | ||
278 | + System.out.println("短信发送超时"); | ||
279 | + } | ||
280 | + } | ||
281 | + break; | ||
282 | + default: | ||
283 | + { | ||
284 | + System.out.println("未知事件[uboxHnd=" + uboxHnd + "][eventID=" + eventID | ||
285 | + + "][param1=" + param1 + "][param2=" + param2 + "][param3=" | ||
286 | + + param3 + "][param4=" + param4 + "]"); | ||
287 | + } | ||
288 | + break; | ||
289 | + } | ||
290 | + } | ||
291 | + | ||
292 | + public void callInNumber(int uboxHnd, String number) { | ||
293 | + System.out.println("收到主叫号码[uboxHnd=" + uboxHnd + "][number=" + number + "]"); | ||
294 | + } | ||
295 | + | ||
296 | + public void ShortMsg(int uboxHnd, String PhoneNumber, String stTime, String msg, String strDived) { | ||
297 | + System.out.println("收到短信[uboxHnd=" + uboxHnd + "][发件人=" + PhoneNumber + "]" + ", 时间:"+stTime +", 内容:" +msg+ " "+strDived); | ||
298 | + } | ||
299 | + | ||
300 | + public void CmdMsg(int uboxHnd, String cmd) { | ||
301 | + System.out.println("收到消息[uboxHnd=" + uboxHnd + "][内容=" + cmd + "]"); | ||
302 | + } | ||
303 | + public static void main(String[] args){ | ||
304 | + IncomingCall call=new IncomingCall(); | ||
305 | + call.openUBox(); | ||
306 | + } | ||
307 | +} |
1 | +package com.sunyo.customer.order.mydemo; | ||
2 | + | ||
3 | +import phonicapi.PhonicConst; | ||
4 | +import phonicapi.PhonicHandler; | ||
5 | +import phonicapi.PhonicNative; | ||
6 | + | ||
7 | +import javax.swing.*; | ||
8 | +import java.awt.*; | ||
9 | +import java.awt.event.ActionEvent; | ||
10 | +import java.awt.event.ActionListener; | ||
11 | +import java.awt.event.WindowAdapter; | ||
12 | +import java.awt.event.WindowEvent; | ||
13 | +import java.io.File; | ||
14 | +import java.text.DateFormat; | ||
15 | +import java.text.SimpleDateFormat; | ||
16 | +import java.util.Date; | ||
17 | + | ||
18 | + | ||
19 | +public class MainFrame extends JFrame implements PhonicHandler{ | ||
20 | + private JButton btnHookOff = new JButton("摘机"); | ||
21 | + private JButton btnHookOn = new JButton("挂机"); | ||
22 | + private JButton btnCall = new JButton("拨号"); | ||
23 | + | ||
24 | + private JButton btnSendMsg = new JButton("发送短信"); | ||
25 | + private JTextField txtNumb = new JTextField(); | ||
26 | + private JComboBox cbxLine = new JComboBox(); | ||
27 | + private JTextField txtShortMsgNumber = new JTextField(); | ||
28 | + private JTextField txtShortMsg = new JTextField(); | ||
29 | + private int uBoxHndOne = 0; //线路1操作句柄 | ||
30 | + private int uBoxHndTwo = 0; //线路2操作句柄 | ||
31 | + private int uBoxId = 0;// 设备类型 | ||
32 | + private boolean bHookOff = false; | ||
33 | + private String strDir = "C:\\"; | ||
34 | + | ||
35 | + MainFrame () | ||
36 | + { | ||
37 | + try{ | ||
38 | + File directory = new File(""); | ||
39 | + strDir = directory.getAbsolutePath(); | ||
40 | + System.out.println(strDir); | ||
41 | + }catch(Exception e){} | ||
42 | + | ||
43 | + //线路 | ||
44 | + cbxLine.setBounds(20, 20, 160, 20); | ||
45 | + cbxLine.addItem("线路1"); | ||
46 | + cbxLine.addItem("线路2"); | ||
47 | + cbxLine.setSelectedItem("线路1"); | ||
48 | + | ||
49 | + //摘机 | ||
50 | + btnHookOff.setBounds(20, 60, 60, 20); | ||
51 | + btnHookOff.addActionListener(new ActionListener() { | ||
52 | + public void actionPerformed(ActionEvent e) { | ||
53 | + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; | ||
54 | + int nResult = PhonicNative.ubox_soft_hook_off(uBoxHnd); | ||
55 | + System.out.println(nResult); | ||
56 | + if(0 == nResult) | ||
57 | + { | ||
58 | + bHookOff = true; | ||
59 | + cbxLine.setEnabled(false); | ||
60 | + btnHookOff.setEnabled(false); | ||
61 | + btnHookOn.setEnabled(true); | ||
62 | + btnCall.setEnabled(true); | ||
63 | + txtNumb.setEnabled(true); | ||
64 | + | ||
65 | + //开始录音 | ||
66 | + Date nowDate = new Date(); | ||
67 | + DateFormat dfDate = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); | ||
68 | + String strPath = strDir+"\\"+dfDate.format(nowDate)+".wav"; | ||
69 | + System.out.println(strPath); | ||
70 | + PhonicNative.ubox_record_file(uBoxHnd, strPath, CODER_ALAW); | ||
71 | + } | ||
72 | + } | ||
73 | + }); | ||
74 | + //挂机 | ||
75 | + btnHookOn.setEnabled(false); | ||
76 | + btnHookOn.setBounds(120, 60, 60, 20); | ||
77 | + btnHookOn.addActionListener(new ActionListener() { | ||
78 | + public void actionPerformed(ActionEvent e) { | ||
79 | + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; | ||
80 | + int nResult = PhonicNative.ubox_soft_hook_on(uBoxHnd); | ||
81 | + System.out.println(nResult); | ||
82 | + if(0 == nResult) | ||
83 | + { | ||
84 | + bHookOff = false; | ||
85 | + cbxLine.setEnabled(true); | ||
86 | + btnHookOff.setEnabled(true); | ||
87 | + btnHookOn.setEnabled(false); | ||
88 | + btnCall.setEnabled(true); | ||
89 | + txtNumb.setEnabled(true); | ||
90 | + | ||
91 | + //停止录音 | ||
92 | + PhonicNative.ubox_stop_record(uBoxHnd); | ||
93 | + } | ||
94 | + } | ||
95 | + }); | ||
96 | + | ||
97 | + //拨号 | ||
98 | + btnCall.setBounds(120, 100, 60, 20); | ||
99 | + btnCall.addActionListener(new ActionListener() { | ||
100 | + public void actionPerformed(ActionEvent e) { | ||
101 | + if(uBoxId == 8) | ||
102 | + { | ||
103 | + if(txtNumb.getText().length() > 0) | ||
104 | + { | ||
105 | + cbxLine.setEnabled(false); | ||
106 | + btnHookOff.setEnabled(false); | ||
107 | + btnHookOn.setEnabled(true); | ||
108 | + btnCall.setEnabled(true); | ||
109 | + txtNumb.setEnabled(true); | ||
110 | + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; | ||
111 | + int nResult = PhonicNative.ubox_makecall(uBoxHnd, txtNumb.getText()); | ||
112 | + System.out.println(nResult); | ||
113 | + | ||
114 | + | ||
115 | + } | ||
116 | + } | ||
117 | + else | ||
118 | + { | ||
119 | + //摘机 | ||
120 | + if(!bHookOff) | ||
121 | + { | ||
122 | + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; | ||
123 | + int nResult = PhonicNative.ubox_soft_hook_off(uBoxHnd); | ||
124 | + System.out.println(nResult); | ||
125 | + if(0 == nResult) | ||
126 | + { | ||
127 | + bHookOff = true; | ||
128 | + cbxLine.setEnabled(false); | ||
129 | + btnHookOff.setEnabled(false); | ||
130 | + btnHookOn.setEnabled(true); | ||
131 | + btnCall.setEnabled(true); | ||
132 | + txtNumb.setEnabled(true); | ||
133 | + | ||
134 | + //开始录音 | ||
135 | + Date nowDate = new Date(); | ||
136 | + DateFormat dfDate = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); | ||
137 | + String strPath = strDir+"\\"+dfDate.format(nowDate)+".wav"; | ||
138 | + System.out.println(strPath); | ||
139 | + PhonicNative.ubox_record_file(uBoxHnd, strPath, CODER_ALAW); | ||
140 | + } | ||
141 | + //等待0.5秒再拨号 | ||
142 | + try{ | ||
143 | + Thread.sleep(500); | ||
144 | + }catch(Exception ee){ | ||
145 | + ee.printStackTrace(); | ||
146 | + } | ||
147 | + } | ||
148 | + | ||
149 | + if(txtNumb.getText().length() > 0) | ||
150 | + { | ||
151 | + btnCall.setEnabled(false); | ||
152 | + txtNumb.setEnabled(false); | ||
153 | + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; | ||
154 | + int nResult = PhonicNative.ubox_send_dtmf(uBoxHnd, txtNumb.getText()); | ||
155 | + System.out.println(nResult); | ||
156 | + } | ||
157 | + } | ||
158 | + } | ||
159 | + }); | ||
160 | + | ||
161 | + btnCall.setEnabled(false); | ||
162 | + btnSendMsg.setEnabled(false); | ||
163 | + //号码输入框 | ||
164 | + txtNumb.setBounds(20, 100, 80, 20); | ||
165 | + txtNumb.setText("910000"); | ||
166 | + | ||
167 | + txtShortMsgNumber.setBounds(20, 140, 80, 20); //收件号码 | ||
168 | + txtShortMsgNumber.setText("8615907558923");//发短信,需要在号码前加国际区号 ,中国"86" | ||
169 | + | ||
170 | + txtShortMsg.setBounds(120, 140, 200, 20); //短信内容 | ||
171 | + txtShortMsg.setText("");//发短信,需要在号码前加国际区号 ,中国"86" | ||
172 | + | ||
173 | + //发送短信 | ||
174 | + btnSendMsg.setBounds(340, 140, 120, 20); | ||
175 | + btnSendMsg.addActionListener(new ActionListener() { | ||
176 | + public void actionPerformed(ActionEvent e) { | ||
177 | + if(uBoxId == 8) | ||
178 | + { | ||
179 | + if(txtShortMsgNumber.getText().length() > 0 && txtShortMsg.getText().length() > 0) | ||
180 | + { | ||
181 | + | ||
182 | + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo; | ||
183 | + int nResult = PhonicNative.ubox_send_gsm_msg(uBoxHnd, 1, txtShortMsgNumber.getText(), txtShortMsg.getText(),txtShortMsg.getText().length()); | ||
184 | + System.out.println(nResult); | ||
185 | + | ||
186 | + | ||
187 | + } | ||
188 | + } | ||
189 | + } | ||
190 | + }); | ||
191 | + //添加控件 | ||
192 | + add(cbxLine); | ||
193 | + add(btnHookOff); | ||
194 | + add(btnHookOn); | ||
195 | + add(btnCall); | ||
196 | + add(txtNumb); | ||
197 | + | ||
198 | + add(txtShortMsgNumber); | ||
199 | + add(txtShortMsg); | ||
200 | + add(btnSendMsg); | ||
201 | + //初始化 | ||
202 | + openUBox(); | ||
203 | + } | ||
204 | + | ||
205 | + //打开设备 | ||
206 | + public boolean openUBox() | ||
207 | + { | ||
208 | + PhonicNative.ubox_open_logfile(0); | ||
209 | + int nOpen = PhonicNative.ubox_open(this, PhonicConst.WORK_MODE_RECORD); | ||
210 | + System.out.println("ubox_open="+nOpen); | ||
211 | + if(nOpen == 0) | ||
212 | + { | ||
213 | + return true; | ||
214 | + } | ||
215 | + return false; | ||
216 | + } | ||
217 | + | ||
218 | + //关闭设备 | ||
219 | + public boolean closeUBox() | ||
220 | + { | ||
221 | + uBoxHndOne = 0; | ||
222 | + uBoxHndTwo = 0; | ||
223 | + PhonicNative.ubox_close(); | ||
224 | + return true; | ||
225 | + } | ||
226 | + | ||
227 | + | ||
228 | + //设备事件 | ||
229 | + public void event(int uboxHnd, int eventID, int param1, int param2, int param3, int param4) { | ||
230 | + switch (eventID) | ||
231 | + { | ||
232 | + case UBOX_EVENT_DEVICE_PLUG_IN: | ||
233 | + { | ||
234 | + //检测型号正确 | ||
235 | + //if(1 == PhonicNative.ubox_get_product_ID(uboxHnd)) | ||
236 | + { | ||
237 | + if(0 == uBoxHndOne) | ||
238 | + { | ||
239 | + uBoxHndOne = uboxHnd; | ||
240 | + uBoxId = PhonicNative.ubox_get_product_ID(uboxHnd); | ||
241 | + System.out.println(PhonicNative.ubox_get_device_versionnum(uboxHnd)); | ||
242 | + System.out.println(PhonicNative.ubox_get_product_name(uboxHnd)); | ||
243 | + if(uBoxId == 8) //无线设备 | ||
244 | + { | ||
245 | + PhonicNative.ubox_set_gsm_work_mode(uboxHnd, 1, 0); //如果不用电话机,关闭电话机模式,否则振铃的时候,戴着耳麦会听到很大的给电话机送来电号码声音,体验效果不好。 | ||
246 | + } | ||
247 | + } | ||
248 | + else if(0 == uBoxHndTwo) | ||
249 | + { | ||
250 | + uBoxHndTwo = uboxHnd; | ||
251 | + } | ||
252 | + else | ||
253 | + { | ||
254 | + uBoxHndOne = uboxHnd; | ||
255 | + uBoxHndTwo = 0; | ||
256 | + } | ||
257 | + } | ||
258 | + System.out.println("收到设备插入事件:" + uboxHnd); | ||
259 | + } | ||
260 | + break; | ||
261 | + case UBOX_EVENT_DEVICE_PLUG_OUT: | ||
262 | + { | ||
263 | + System.out.println("收到设备拔出事件:" + uboxHnd); | ||
264 | + } | ||
265 | + break; | ||
266 | + case UBOX_EVENT_LINE_HOOK_UP: | ||
267 | + { | ||
268 | + | ||
269 | + if(uBoxId == 8) | ||
270 | + { | ||
271 | + if(param1 == 1) | ||
272 | + { | ||
273 | + System.out.println("收到GSM模块挂机:" + uboxHnd); | ||
274 | + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 0); //被叫能够听不到耳麦说话的声音 | ||
275 | + } | ||
276 | + else if(param1 == 2) | ||
277 | + { | ||
278 | + System.out.println("收到电话机挂机:" + uboxHnd); | ||
279 | + } | ||
280 | + else if(param1 == 3) | ||
281 | + { | ||
282 | + System.out.println("收到耳麦挂机:" + uboxHnd); | ||
283 | + } | ||
284 | + } | ||
285 | + else | ||
286 | + { | ||
287 | + System.out.println("收到设备挂机事件:" + uboxHnd); | ||
288 | + } | ||
289 | + } | ||
290 | + break; | ||
291 | + case UBOX_EVENT_LINE_HOOK_OFF: | ||
292 | + { | ||
293 | + if(uBoxId == 8) | ||
294 | + { | ||
295 | + if(param1 == 0) | ||
296 | + { | ||
297 | + System.out.println("收到电话机摘机:" + uboxHnd); | ||
298 | + } | ||
299 | + else if(param1 == 2) | ||
300 | + { | ||
301 | + System.out.println("收到耳麦摘机:" + uboxHnd); | ||
302 | + } | ||
303 | + else if(param1 == 6) | ||
304 | + { | ||
305 | + System.out.println("收到GSM模块摘机:" + uboxHnd); | ||
306 | + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 1); //被叫能够听到耳麦说话的声音 | ||
307 | + } | ||
308 | + } | ||
309 | + else | ||
310 | + { | ||
311 | + System.out.println("收到设备摘机事件:" + uboxHnd); | ||
312 | + } | ||
313 | + } | ||
314 | + break; | ||
315 | + case UBOX_EVENT_LINE_RINGING: | ||
316 | + { | ||
317 | + System.out.println("收到设备检测线路振铃开始事件:" + uboxHnd); | ||
318 | + } | ||
319 | + break; | ||
320 | + case UBOX_EVENT_DEVICE_PLAY_END: | ||
321 | + { | ||
322 | + System.out.println("收到放音结束事件:" + uboxHnd); | ||
323 | + } | ||
324 | + break; | ||
325 | + case UBOX_EVENT_RING_CANCEL: | ||
326 | + { | ||
327 | + System.out.println("收到设备检测线路振铃停止事件:" + uboxHnd); | ||
328 | + } | ||
329 | + break; | ||
330 | + case UBOX_EVENT_DEVICE_BUSY_TONE: | ||
331 | + { | ||
332 | + System.out.println("收到设备检测线路忙音事件:" + uboxHnd); | ||
333 | + } | ||
334 | + break; | ||
335 | + case UBOX_EVENT_ALARM: | ||
336 | + { | ||
337 | + System.out.println("收到设备工作警告事件:" + uboxHnd); | ||
338 | + } | ||
339 | + break; | ||
340 | + case UBOX_EVENT_DEVICE_ERROR: | ||
341 | + { | ||
342 | + System.out.println("收到设备错误事件:" + uboxHnd); | ||
343 | + } | ||
344 | + break; | ||
345 | + case UBOX_EVENT_LINE_RING_STOP: | ||
346 | + { | ||
347 | + System.out.println("收到设备检测线路振铃闪停事件:" + uboxHnd); | ||
348 | + } | ||
349 | + break; | ||
350 | + case UBOX_EVENT_LINE_HANG: | ||
351 | + { | ||
352 | + System.out.println("收到设备悬空事件:" + uboxHnd); | ||
353 | + } | ||
354 | + break; | ||
355 | + case UBOX_EVENT_LINE_VOLTAGE: | ||
356 | + { | ||
357 | + System.out.println("收到设备线路当前电压事件:" + uboxHnd); | ||
358 | + } | ||
359 | + break; | ||
360 | + case UBOX_EVENT_STREAM_VOICE: | ||
361 | + { | ||
362 | + System.out.println("收到流式录音数据包事件:" + uboxHnd); | ||
363 | + } | ||
364 | + break; | ||
365 | + case UBOX_EVENT_DTMF_DOWN: | ||
366 | + { | ||
367 | + //System.out.println("按键事件:" + uboxHnd); | ||
368 | + } | ||
369 | + break; | ||
370 | + case UBOX_EVENT_DTMF_UP: | ||
371 | + { | ||
372 | + System.out.println("收到按键释放事件:" + uboxHnd); | ||
373 | + } | ||
374 | + break; | ||
375 | + case UBOX_EVENT_DEVICE_PLAY_ERROR: | ||
376 | + { | ||
377 | + System.out.println("收到放音错误事件:" + uboxHnd); | ||
378 | + } | ||
379 | + break; | ||
380 | + case UBOX_EVENT_CALLOUTFINISH: | ||
381 | + { | ||
382 | + System.out.println("收到软件拨号完成事件:" + uboxHnd); | ||
383 | + } | ||
384 | + break; | ||
385 | + case UBOX_EVENT_POLARITY: | ||
386 | + { | ||
387 | + System.out.println("收到检测极性反转事件:" + uboxHnd); | ||
388 | + } | ||
389 | + break; | ||
390 | + case UBOX_EVENT_SIM_STATE: | ||
391 | + { | ||
392 | + if(param2 == 1) | ||
393 | + { | ||
394 | + System.out.println("卡状态事件, 当前选择sim卡" + param1); | ||
395 | + } | ||
396 | + else if(param2 == 2) | ||
397 | + { | ||
398 | + System.out.println("卡状态事件, sim卡" + param1 +" GSM 模块检查Sim卡未插入"); | ||
399 | + } | ||
400 | + else if(param2 == 3) | ||
401 | + { | ||
402 | + System.out.println("卡状态事件, sim卡" + param1 +" 检测到卡存在,并且是插好的"); | ||
403 | + } | ||
404 | + else if(param2 > 3) | ||
405 | + { | ||
406 | + System.out.println("卡状态事件, sim卡" + param1 +" 检测到卡有错误,错误值:"+param2); | ||
407 | + } | ||
408 | + } | ||
409 | + break; | ||
410 | + case UBOX_EVENT_ANSWER: | ||
411 | + { | ||
412 | + System.out.println(" 被叫已经应答了"); | ||
413 | + | ||
414 | + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 1); //被叫能够听到耳麦说话的声音 | ||
415 | + } | ||
416 | + break; | ||
417 | + case UBOX_EVENT_SIGNALE_SIZE: | ||
418 | + { | ||
419 | + System.out.println(" 信号大小:"+param1); | ||
420 | + } | ||
421 | + break; | ||
422 | + case UBOX_EVENT_SHORT_MSG_SIZE: | ||
423 | + { | ||
424 | + System.out.println(" 被叫已经应答了"); | ||
425 | + } | ||
426 | + break; | ||
427 | + case UBOX_EVENT_SIM_REG: | ||
428 | + { | ||
429 | + if(param2 == 0) | ||
430 | + { | ||
431 | + System.out.println("sim卡" + param1+1 + " 网络未注册,当前没有搜索到要注册业务的新营运商 "); | ||
432 | + } | ||
433 | + else if(param2 == 1) | ||
434 | + { | ||
435 | + System.out.println("sim卡" + param1+1 + " 网络已注册"); | ||
436 | + btnCall.setEnabled(true); //网络已经注册好了,可以拨打电话和发短信 | ||
437 | + btnSendMsg.setEnabled(true); | ||
438 | + } | ||
439 | + else if(param2 == 2) | ||
440 | + { | ||
441 | + System.out.println("sim卡" + param1+1 + " 网络未注册,正在搜索要注册业务的新营运商"); | ||
442 | + } | ||
443 | + else if(param2 == 3) | ||
444 | + { | ||
445 | + System.out.println("sim卡" + param1+1 + " 注册被拒绝"); | ||
446 | + } | ||
447 | + else if(param2 == 4) | ||
448 | + { | ||
449 | + System.out.println("sim卡" + param1+1 + " 未注册, 未知原因"); | ||
450 | + } | ||
451 | + else if(param2 == 5) | ||
452 | + { | ||
453 | + System.out.println("sim卡" + param1+1 + " 已注册,漫游"); | ||
454 | + } | ||
455 | + } | ||
456 | + break; | ||
457 | + case UBOX_EVENT_SHORT_MSG_SEND_REPORT: | ||
458 | + { | ||
459 | + if(param1 == 0) | ||
460 | + { | ||
461 | + System.out.println("短信发送失败"); | ||
462 | + } | ||
463 | + else if(param1 == 1) | ||
464 | + { | ||
465 | + System.out.println("短信发送成功"); | ||
466 | + } | ||
467 | + else if(param1 == 2) | ||
468 | + { | ||
469 | + System.out.println("短信发送超时"); | ||
470 | + } | ||
471 | + } | ||
472 | + break; | ||
473 | + default: | ||
474 | + { | ||
475 | + System.out.println("未知事件[uboxHnd=" + uboxHnd + "][eventID=" + eventID | ||
476 | + + "][param1=" + param1 + "][param2=" + param2 + "][param3=" | ||
477 | + + param3 + "][param4=" + param4 + "]"); | ||
478 | + } | ||
479 | + break; | ||
480 | + } | ||
481 | + } | ||
482 | + | ||
483 | + public void callInNumber(int uboxHnd, String number) { | ||
484 | + System.out.println("收到主叫号码[uboxHnd=" + uboxHnd + "][number=" + number + "]"); | ||
485 | + } | ||
486 | + | ||
487 | + public void ShortMsg(int uboxHnd, String PhoneNumber, String stTime, String msg, String strDived) { | ||
488 | + System.out.println("收到短信[uboxHnd=" + uboxHnd + "][发件人=" + PhoneNumber + "]" + ", 时间:"+stTime +", 内容:" +msg+ " "+strDived); | ||
489 | + } | ||
490 | + | ||
491 | + public void CmdMsg(int uboxHnd, String cmd) { | ||
492 | + System.out.println("收到消息[uboxHnd=" + uboxHnd + "][内容=" + cmd + "]"); | ||
493 | + } | ||
494 | + | ||
495 | + public static void main(String[] args) | ||
496 | + { | ||
497 | + final MainFrame myFrame = new MainFrame(); | ||
498 | + myFrame.setTitle("电话示例"); | ||
499 | + myFrame.setSize(800, 600); | ||
500 | + myFrame.setLayout(null); | ||
501 | + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | ||
502 | + Dimension frameSize = myFrame.getSize(); | ||
503 | + myFrame.setLocation((screenSize.width-frameSize.width)/2, (screenSize.height-frameSize.height)/2); | ||
504 | + myFrame.setDefaultCloseOperation(EXIT_ON_CLOSE); | ||
505 | + myFrame.addWindowListener(new WindowAdapter(){ | ||
506 | + public void windowClosing(WindowEvent e){ | ||
507 | + myFrame.closeUBox(); | ||
508 | + } | ||
509 | + }); | ||
510 | + myFrame.setVisible(true); | ||
511 | + System.out.println("退出"); | ||
512 | + | ||
513 | + } | ||
514 | +} | ||
515 | + |
1 | +package com.sunyo.customer.order.websocket; | ||
2 | + | ||
3 | +import org.springframework.beans.BeansException; | ||
4 | +import org.springframework.beans.factory.BeanFactory; | ||
5 | +import org.springframework.context.ApplicationContext; | ||
6 | +import org.springframework.context.ApplicationContextAware; | ||
7 | + | ||
8 | +import javax.websocket.server.ServerEndpointConfig; | ||
9 | + | ||
10 | +/** | ||
11 | + * Created by XYH on 2019/12/24. | ||
12 | + */ | ||
13 | +public class MySpringConfigurator extends ServerEndpointConfig.Configurator implements ApplicationContextAware { | ||
14 | + private static volatile BeanFactory context; | ||
15 | + | ||
16 | + @Override | ||
17 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
18 | + MySpringConfigurator.context = applicationContext; | ||
19 | + } | ||
20 | + | ||
21 | + @Override | ||
22 | + public <T> T getEndpointInstance(Class<T> clazz) throws InstantiationException { | ||
23 | + return context.getBean(clazz); | ||
24 | + } | ||
25 | +} |
1 | +package com.sunyo.customer.order.websocket; | ||
2 | + | ||
3 | +import org.springframework.context.annotation.Bean; | ||
4 | +import org.springframework.context.annotation.Configuration; | ||
5 | +import org.springframework.web.socket.server.standard.ServerEndpointExporter; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by XYH on 2019/12/23. | ||
9 | + */ | ||
10 | +@Configuration | ||
11 | +public class WebSocketConfig { | ||
12 | + @Bean | ||
13 | + public ServerEndpointExporter serverEndpointExporter() { | ||
14 | + return new ServerEndpointExporter(); | ||
15 | + } | ||
16 | + @Bean | ||
17 | + public MySpringConfigurator mySpringConfigurator() { | ||
18 | + return new MySpringConfigurator(); | ||
19 | + } | ||
20 | +} |
1 | +package com.sunyo.customer.order.websocket; | ||
2 | + | ||
3 | + | ||
4 | +import cn.hutool.log.Log; | ||
5 | +import cn.hutool.log.LogFactory; | ||
6 | +import org.springframework.stereotype.Component; | ||
7 | + | ||
8 | +import javax.websocket.*; | ||
9 | +import javax.websocket.server.PathParam; | ||
10 | +import javax.websocket.server.ServerEndpoint; | ||
11 | +import java.io.IOException; | ||
12 | +import java.util.concurrent.CopyOnWriteArraySet; | ||
13 | + | ||
14 | +/** | ||
15 | + * Created by XYH on 2019/12/23. | ||
16 | + */ | ||
17 | +@ServerEndpoint(value="/websocket",configurator = MySpringConfigurator.class) | ||
18 | +@Component | ||
19 | +public class WebSocketServer { | ||
20 | + | ||
21 | + static Log log= LogFactory.get(WebSocketServer.class); | ||
22 | + //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。 | ||
23 | + private static int onlineCount = 0; | ||
24 | + //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。 | ||
25 | + private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<WebSocketServer>(); | ||
26 | + | ||
27 | + //与某个客户端的连接会话,需要通过它来给客户端发送数据 | ||
28 | + private Session session; | ||
29 | + | ||
30 | + //接收sid | ||
31 | + private String sid=""; | ||
32 | + /** | ||
33 | + * 连接建立成功调用的方法*/ | ||
34 | + @OnOpen | ||
35 | + public void onOpen(Session session,@PathParam("sid") String sid) { | ||
36 | + this.session = session; | ||
37 | + webSocketSet.add(this); //加入set中 | ||
38 | + addOnlineCount(); //在线数加1 | ||
39 | + log.info("有新窗口开始监听:"+sid+",当前在线人数为" + getOnlineCount()); | ||
40 | + this.sid=sid; | ||
41 | + try { | ||
42 | + sendMessage("连接成功"); | ||
43 | + } catch (IOException e) { | ||
44 | + log.error("websocket IO异常"); | ||
45 | + } | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * 连接关闭调用的方法 | ||
50 | + */ | ||
51 | + @OnClose | ||
52 | + public void onClose() { | ||
53 | + webSocketSet.remove(this); //从set中删除 | ||
54 | + subOnlineCount(); //在线数减1 | ||
55 | + log.info("有一连接关闭!当前在线人数为" + getOnlineCount()); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * 收到客户端消息后调用的方法 | ||
60 | + * | ||
61 | + * @param message 客户端发送过来的消息*/ | ||
62 | + @OnMessage | ||
63 | + public void onMessage(String message, Session session) { | ||
64 | + log.info("收到来自窗口"+sid+"的信息:"+message); | ||
65 | + //群发消息 | ||
66 | + for (WebSocketServer item : webSocketSet) { | ||
67 | + try { | ||
68 | + item.sendMessage(message); | ||
69 | + } catch (IOException e) { | ||
70 | + e.printStackTrace(); | ||
71 | + } | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * | ||
77 | + * @param session | ||
78 | + * @param error | ||
79 | + */ | ||
80 | + @OnError | ||
81 | + public void onError(Session session, Throwable error) { | ||
82 | + log.error("发生错误"); | ||
83 | + error.printStackTrace(); | ||
84 | + } | ||
85 | + /** | ||
86 | + * 实现服务器主动推送 | ||
87 | + */ | ||
88 | + public void sendMessage(String message) throws IOException { | ||
89 | + this.session.getBasicRemote().sendText(message); | ||
90 | + } | ||
91 | + | ||
92 | + | ||
93 | + /** | ||
94 | + * 群发自定义消息 | ||
95 | + * */ | ||
96 | + public static void sendInfo(String message,@PathParam("sid") String sid) throws IOException { | ||
97 | + //log.info("推送消息到窗口"+sid+",推送内容:"+message); | ||
98 | + for (WebSocketServer item : webSocketSet) { | ||
99 | + try { | ||
100 | + //这里可以设定只推送给这个sid的,为null则全部推送 | ||
101 | + if(sid==null) { | ||
102 | + item.sendMessage(message); | ||
103 | + }else if(item.sid.equals(sid)){ | ||
104 | + item.sendMessage(message); | ||
105 | + } | ||
106 | + } catch (IOException e) { | ||
107 | + continue; | ||
108 | + } | ||
109 | + } | ||
110 | + } | ||
111 | + | ||
112 | + public static synchronized int getOnlineCount() { | ||
113 | + return onlineCount; | ||
114 | + } | ||
115 | + | ||
116 | + public static synchronized void addOnlineCount() { | ||
117 | + WebSocketServer.onlineCount++; | ||
118 | + } | ||
119 | + | ||
120 | + public static synchronized void subOnlineCount() { | ||
121 | + WebSocketServer.onlineCount--; | ||
122 | + } | ||
123 | +} | ||
124 | + |
@@ -32,7 +32,7 @@ spring: | @@ -32,7 +32,7 @@ spring: | ||
32 | ddl-auto: update | 32 | ddl-auto: update |
33 | show-sql: true | 33 | show-sql: true |
34 | resources: | 34 | resources: |
35 | - static-locations: classpath:/META-INF/resources/,classpath:/static,classpath:/resources/,classpath:/public/,file:${web.upload-path} | 35 | + static-locations: classpath:/META-INF/resources/,classpath:/bin,classpath:/static,classpath:/resources/,classpath:/public/,file:${web.upload-path} |
36 | 36 | ||
37 | application: | 37 | application: |
38 | name: HQPT-PROCESS | 38 | name: HQPT-PROCESS |
-
请 注册 或 登录 后发表评论