lisai17@sina.com 2020-08-31 11:13:30 +08:00
parent e355a82417
commit 8e73b1bb4a
4 changed files with 90 additions and 17 deletions

View File

@ -133,6 +133,12 @@
<version>3.4.0</version> <version>3.4.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.3</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,36 @@
package com.cowr.common.aliyun.sms;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
public class SendBatchSms {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GBjCx9Hjxg9LtaTLD43", "xsf8w9KUArVGiXIMcM94d0iIqL7q5O");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setSysMethod(MethodType.POST);
request.setSysDomain("dysmsapi.aliyuncs.com");
request.setSysVersion("2017-05-25");
request.setSysAction("SendBatchSms");
request.putQueryParameter("RegionId", "cn-hangzhou");
request.putQueryParameter("PhoneNumberJson", "[\"13627293906\"]");
request.putQueryParameter("SignNameJson", "[\"智慧砂石\"]");
request.putQueryParameter("TemplateCode", "SMS_66850327");
request.putQueryParameter("TemplateParamJson", "[{\"time\":\"test time\", \"code\":\"test code\"}]");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
}

View File

@ -1,7 +1,9 @@
package com.cowr.local.ssjygl.devicectrl.device; package com.cowr.local.ssjygl.devicectrl.device;
import com.jfinal.log.Log; import com.jfinal.log.Log;
import org.apache.poi.util.HexDump;
import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -80,15 +82,15 @@ public class LED extends Device {
InputStream in = socket.getInputStream(); InputStream in = socket.getInputStream();
byte[] buf = new byte[in.available()]; byte[] buf = new byte[in.available()];
in.read(buf); in.read(buf);
// BufferedInputStream bis = new BufferedInputStream(socket.getInputStream()); BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
// byte[] y = new byte[128]; byte[] y = new byte[128];
// int read = bis.read(y); int read = bis.read(y);
// while (!(read > 0)) { while (!(read > 0)) {
// read = bis.read(y); read = bis.read(y);
// } }
// byte[] z = new byte[read]; byte[] z = new byte[read];
// System.arraycopy(y, 0, z, 0, read); System.arraycopy(y, 0, z, 0, read);
// System.out.println(HexDump.toHex(z)); System.out.println(HexDump.toHex(z));
socket.close(); socket.close();
} finally { } finally {
lock.unlock(); lock.unlock();
@ -199,13 +201,9 @@ public class LED extends Device {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
LED led = new LED("", "192.168.0.197", 5005); LED led = new LED("", "192.168.30.201", 5005);
led.screen("12345678", "等待车辆", "%s\\n %s \\n%s"); led.screen("12345678", "等待车辆", "%s\\n %s \\n%s");
Thread.sleep(3000);
led.screen("987654321", "等待车辆", "%s\\n %s \\n%s");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -9,6 +9,7 @@ import java.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -59,8 +60,13 @@ public class LEDThread extends Device implements Runnable {
@Override @Override
public void run() { public void run() {
DateFormat df = new SimpleDateFormat("mm:ss");
while (this.running){ while (this.running){
try { try {
setWeightInfo("鄂A7D1P1", df.format(new Date()));
screen(); screen();
Thread.sleep(1000); Thread.sleep(1000);
@ -136,6 +142,8 @@ public class LEDThread extends Device implements Runnable {
// socket.close(); // socket.close();
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
reconn();
} finally { } finally {
lock.unlock(); lock.unlock();
} }
@ -245,9 +253,34 @@ public class LEDThread extends Device implements Runnable {
socket = null; socket = null;
} }
public boolean reconn(){
try {
log.debug("销毁LED连接");
if (socket != null) {
socket.close();
}
socket = null;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
try {
socket = new Socket();
socket.setSoTimeout(1000);
socket.connect(new InetSocketAddress(getIp(), getPort()), 3000);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
lock.unlock();
}
return isConnected();
}
public static void main(String[] args) { public static void main(String[] args) {
try { try {
LEDThread led = new LEDThread("", "192.168.1.16", 5005); LEDThread led = new LEDThread("", "192.168.30.201", 5005);
Thread thread = new Thread(led); Thread thread = new Thread(led);
thread.setDaemon(true); thread.setDaemon(true);
thread.start(); thread.start();
@ -255,11 +288,11 @@ public class LEDThread extends Device implements Runnable {
System.out.println("LED 启动"); System.out.println("LED 启动");
Thread.sleep(10000); Thread.sleep(10000000);
led.running = false; led.running = false;
Thread.sleep(10000); Thread.sleep(100000);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }