打印机
This commit is contained in:
parent
06ebc1d05e
commit
36f1242e79
@ -0,0 +1,69 @@
|
||||
package com.ycwl.basic.printer.ticket;
|
||||
|
||||
import cn.hutool.Hutool;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FeiETicketPrinter {
|
||||
public static final String URL = "https://api.feieyun.cn/Api/Open/";
|
||||
|
||||
public static final String USER = "792602257@qq.com";
|
||||
public static final String UKEY = "GdMvD6WwCGTAgM8x";
|
||||
|
||||
public static String doPrint(String sn, String content, int times) {
|
||||
|
||||
HttpRequest post = HttpUtil.createPost(URL);
|
||||
post.header("Content-Type", "application/x-www-form-urlencoded");
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
body.put("user",USER);
|
||||
String STIME = String.valueOf(System.currentTimeMillis()/1000);
|
||||
body.put("stime",STIME);
|
||||
body.put("sig",signature(USER,UKEY,STIME));
|
||||
body.put("apiname","Open_printMsg");
|
||||
body.put("sn",sn);
|
||||
body.put("content",content);
|
||||
body.put("times",String.valueOf(times));
|
||||
try (HttpResponse response = post.form(body).execute()) {
|
||||
if (response.getStatus() != 200) {
|
||||
return null;
|
||||
}
|
||||
return response.body();
|
||||
}
|
||||
}
|
||||
//方法1
|
||||
private static String testPrint(String sn){
|
||||
//标签说明:
|
||||
//单标签:
|
||||
//"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
|
||||
//"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
|
||||
//成对标签:
|
||||
//"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
|
||||
//<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,"<RIGHT></RIGHT>"为右对齐
|
||||
//拼凑订单内容时可参考如下格式
|
||||
//根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
|
||||
|
||||
String content;
|
||||
content = "<CB>帧途AI旅拍</CB><BR>";
|
||||
content += "┏━━━━━━━━━━━━━━┓<BR>";
|
||||
content += "┃┉3制67表01符45制89表23符6┉┃<BR>";
|
||||
content += "┣━━★━━♢━━◈━━◉━━┫<BR>";
|
||||
content += "┃123制67表01符45制89表23符678┃<BR>";
|
||||
content += "┗━━━━━━━━━━━━━━┛<BR>";
|
||||
return doPrint(sn,content,1);
|
||||
}
|
||||
|
||||
|
||||
//生成签名字符串
|
||||
private static String signature(String user,String ukey,String stime){
|
||||
return DigestUtils.sha1Hex(user+ukey+stime);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(testPrint("550519002"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user