大趋智能打印机java api(大趋智能打印机离线)

  本篇文章为你整理了大趋智能打印机java api(大趋智能打印机离线)的详细内容,包含有大趋智能打印机连美团外卖之后怎么添加饿了吗 大趋智能打印机离线 大趋智能打印机怎么样 大趋智能打印机稳定吗 大趋智能打印机java api,希望能帮助你了解 大趋智能打印机java api。

  你我暮年,闲坐庭院。云卷云舒听雨声,星密星稀赏月影。花开花落忆江南,你话往时,我画往事。愿有岁月可回首,且以深情共白头。

  
对接飞鹅和易联云后 ,网上几乎没资料对大趋智能打印机java api分享,故此分享一波。

  官方文档地址

  

SnParam.java

 

  

package com.shanheyongmu.openapi.param;

 

  import lombok.Data;

  import lombok.NoArgsConstructor;

  @NoArgsConstructor

  @Data

  public class SnParam {

   * 打印机编号

   private String sn;

   public SnParam(String sn) {

   this.sn = sn;

  }

 

  

PrinterAddParam.java

 

  

package com.shanheyongmu.openapi.param;

 

  import lombok.Data;

  import org.hibernate.validator.constraints.Length;

  import org.hibernate.validator.constraints.Range;

  import javax.validation.constraints.NotBlank;

  @Data

  public class PrinterAddParam {

   * 打印机编号

   @NotBlank

   @Length(max = 50)

   private String sn;

   * 设备密钥

   @NotBlank

   @Length(max = 255)

   private String key;

   * 设备名称或备注

   @Length(max = 50)

   private String name;

  
@EqualsAndHashCode(callSuper = true)

  public class PrintStatusQueryParam extends SnParam {

   * 打印请求ID

   @NotNull

   private Long printId;

   public PrintStatusQueryParam(@NotNull String sn, @NotNull Long printId) {

   super(sn);

   this.printId = printId;

  }

 

  

PrintParam.java

 

  

package com.shanheyongmu.openapi.param;

 

  import lombok.Data;

  import org.hibernate.validator.constraints.Length;

  import org.hibernate.validator.constraints.Range;

   * 打印请求

  @Data

  public class PrintParam extends SnParam {

   * 打印小票模板内容

   @Length(max = 6000)

   private String content;

   * 播报音源

   @Length(max = 120)

   private String voice;

   * 播报语音次数,默认播报1次,不能超过3次

   @Range(min = 1, max = 5)

   private Integer voicePlayTimes;

   * 多次播报语音时的间隔秒数,默认3秒

   private String voicePlayInterval;

   * 打印小票张数,不传默认1, 取值范围: 1~5

   @Range(min = 1, max = 5)

   private Integer copies;

  }

 

  com.shanheyongmu.openapi.result 新建6个类

  

ResponseResult.java

 

  

package com.shanheyongmu.openapi.result;

 

  import lombok.Data;

  import java.io.Serializable;

   * 标准响应结构体

   * @param T 响应业务数据

  @Data

  public class ResponseResult T implements Serializable {

   private String code;

   private String message;

   private T data;

  }

 

  

PrinterAddResultData.java

 

  

package com.shanheyongmu.openapi.result;

 

  import lombok.Data;

  import java.util.List;

  @Data

  public class PrinterAddResultData {

   * 多台设备发生增加失败时返回原因列表,都成功时返回空列表(注意:增加单时失败的原因在message中)

   List AddFailResult fail;

   @Data

   public static class AddFailResult {

   private String sn;

   * 失败原因

   private String reason;

  }

 

  

PrinterUnbindResultData.java

 

  

package com.shanheyongmu.openapi.result;

 

  import lombok.Data;

  import java.util.List;

   * 打印解绑结果

  @Data

  public class PrinterUnbindResultData {

   * 多台设备解绑成功时,返回成功的SN列表

   List String ok;

   * 多台设备发生解绑失败时返回原因列表

   List UnbindFailResult fail;

   @Data

   public static class UnbindFailResult {

   private String sn;

   * 失败原因

   private String reason;

  }

 

  

PrinterStatusResultData.java

 

  

package com.shanheyongmu.openapi.result;

 

  import lombok.Data;

  @Data

  public class PrinterStatusResultData {

   * 在线状态 0/1

   * 0=不在线 1=在线

   int onlineStatus;

   * 设备状态

   * -1=初始化 0=就绪 1=打印中 2=缺纸 3=过温 4=打印故障

   int workStatus;

   * 设备状态说明

   String workStatusDesc;

  }

 

  

PrintRequestResultData.java

 

  

package com.shanheyongmu.openapi.result;

 

  import lombok.Data;

   * 请求打印结果

  @Data

  public class PrintRequestResultData {

   * 打印请求ID

   private long printId;

  


com.shanheyongmu.openapi.result.callback下

 

  

PrintRequestStateCallbackData.java

 

  

package com.shanheyongmu.openapi.result.callback;

 

  import lombok.Data;

   * 回调打印结果

  @Data

  public class PrintRequestStateCallbackData {

   * 打印ID

   private long printId;

   * 状态

   * 0=待打印 1=打印中 2=成功 3=失败 4=已取消

   private String status;

  }

 

  

CallbackResult.java

 

  

package com.shanheyongmu.openapi.result.callback;

 

  import lombok.Data;

   * 回调结果

  @Data

  public class CallbackResult {

   * 回调业务类型

   * 5=打印请求状态发生改变 6=打印机打印发生改变

   private int type;

   * 回调时间(unix timestamp 秒)

   private long rtime;

  
import com.shanheyongmu.openapi.result.PrinterAddResultData;

  import com.shanheyongmu.openapi.param.PrintParam;

  import com.shanheyongmu.openapi.param.PrintStatusQueryParam;

  import com.shanheyongmu.openapi.param.PrinterAddParam;

  import com.shanheyongmu.openapi.param.SnParam;

  import com.shanheyongmu.openapi.result.*;

  import org.springframework.core.ParameterizedTypeReference;

  import java.util.List;

  public class DaQuApi {

   private static String API_PREFIX = "https://printer.juhesaas.com/openapi";

   * 批量添加打印机

   public static ResponseResult PrinterAddResultData addPrinterBatch(List PrinterAddParam printerList) {

   String url = API_PREFIX + "/addPrinter";

   return DaQuRequestUtils.post(url, printerList, new ParameterizedTypeReference ResponseResult PrinterAddResultData () {

   * 查询设备状态

   public static ResponseResult PrinterStatusResultData getDeviceStatus(String sn) {

   return DaQuRequestUtils.post(API_PREFIX + "/getDeviceStatus", new SnParam(sn), new ParameterizedTypeReference ResponseResult PrinterStatusResultData () {

   * 请求打印

   public static ResponseResult PrintRequestResultData print(PrintParam printParam) {

   return DaQuRequestUtils.post(API_PREFIX + "/print", printParam, new ParameterizedTypeReference ResponseResult PrintRequestResultData () {

   * 查询小票打印结果

   public static ResponseResult PrintStatusData getPrintStatus(PrintStatusQueryParam printStatusQueryParam) {

   return DaQuRequestUtils.post(API_PREFIX + "/getPrintStatus", printStatusQueryParam, new ParameterizedTypeReference ResponseResult PrintStatusData () {

   * 解绑打印机

   public static ResponseResult PrinterUnbindResultData unbind(List String snList) {

   return DaQuRequestUtils.post(API_PREFIX + "/delPrinter", snList, new ParameterizedTypeReference ResponseResult PrinterUnbindResultData () {

  
import com.fasterxml.jackson.core.JsonProcessingException;

  import com.fasterxml.jackson.databind.ObjectMapper;

  import com.shanheyongmu.openapi.result.ResponseResult;

  import org.apache.commons.codec.digest.DigestUtils;

  import org.springframework.core.ParameterizedTypeReference;

  import org.springframework.http.HttpEntity;

  import org.springframework.http.HttpHeaders;

  import org.springframework.http.HttpMethod;

  import org.springframework.http.MediaType;

  import org.springframework.web.client.RestTemplate;

  import java.time.LocalDateTime;

  import java.time.ZoneOffset;

  import java.util.UUID;

  public class DaQuRequestUtils {

   private static ObjectMapper objectMapper = new ObjectMapper();

   * 发起请求

   * @param url url

   * @param body 请求body对象

   * @param typeReference 响应类型

   public static R, P ResponseResult R post(String url, P body, ParameterizedTypeReference ResponseResult R typeReference) {

   HttpHeaders hexSignHeader = getHeader(body);

   hexSignHeader.setContentType(MediaType.APPLICATION_JSON_UTF8);

   HttpEntity P request = new HttpEntity (body, hexSignHeader);

   return new RestTemplate().exchange(url, HttpMethod.POST, request, typeReference).getBody();

  
public static HttpHeaders getHeader(Object requestParam) {

   String appId = "{your appid}";

   String appSecret = "{your appSecret}";

   long stime = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);

   String uid = UUID.randomUUID().toString();

   String originContext = uid + appId + stime + appSecret;

   if (requestParam != null) {

   try {

   // 注意:如果有自定义Spring MVC HttpMessageConverter,请注意两边序列化规则保持一至

   originContext += objectMapper.writeValueAsString(requestParam);

   } catch (JsonProcessingException e) {

   e.printStackTrace();

   HttpHeaders headers = new HttpHeaders();

   String sign = DigestUtils.md5Hex(originContext);

   headers.add("appid", appId);

   headers.add("uid", uid);

   headers.add("stime", String.valueOf(stime));

   headers.add("sign", sign);

   return headers;

  }

 

  测试用例

  

package com.shanheyongmu.openapi.util;

 

  import com.shanheyongmu.openapi.param.PrintParam;

  import com.shanheyongmu.openapi.param.PrintStatusQueryParam;

  import com.shanheyongmu.openapi.param.PrinterAddParam;

  import com.shanheyongmu.openapi.result.*;

  import org.junit.Assert;

  import org.junit.Test;

  import java.util.ArrayList;

  import java.util.Arrays;

  import java.util.List;

  import static org.junit.Assert.*;

  public class DaQuApiTest {

   String testSN = "67002004xxxx";

   String testKey = "7w4566";

   @Test

   public void unbindTest() {

   ResponseResult PrinterUnbindResultData responseResult = DaQuApi.unbind(Arrays.asList(testSN));

   System.out.println(responseResult);

   Assert.assertEquals("0", responseResult.getCode());

   Assert.assertEquals("OK", responseResult.getMessage());

  
public void addPrinterBatchTest() {

   List PrinterAddParam printerList = new ArrayList ();

   PrinterAddParam printer1 = new PrinterAddParam();

   printer1.setSn(testSN);

   printer1.setKey(testKey);

   printer1.setName("openApiTestSN");

   printerList.add(printer1);

   ResponseResult PrinterAddResultData responseResult = DaQuApi.addPrinterBatch(printerList);

   System.out.println(responseResult);

   Assert.assertEquals("0", responseResult.getCode());

   Assert.assertEquals("OK", responseResult.getMessage());

  
public void getDeviceStatusTest() {

   ResponseResult PrinterStatusResultData responseResult = DaQuApi.getDeviceStatus(testSN);

   System.out.println(responseResult);

   Assert.assertEquals("0", responseResult.getCode());

   Assert.assertEquals("OK", responseResult.getMessage());

  
printParam.setVoice("1"); // 模拟美团接单

   ResponseResult PrintRequestResultData responseResult = DaQuApi.print(printParam);

   System.out.println(responseResult);

   Assert.assertEquals("0", responseResult.getCode());

   Assert.assertEquals("OK", responseResult.getMessage());

   Assert.assertNotNull(responseResult.getData());

   Assert.assertNotNull(responseResult.getData().getPrintId());

   Assert.assertNotNull(responseResult.getData().getQueueSize());

   @Test

   public void getPrintStatusTest() {

   PrintStatusQueryParam printStatusQueryParam = new PrintStatusQueryParam(testSN, 1045401059247738881L);

   ResponseResult PrintStatusData responseResult = DaQuApi.getPrintStatus(printStatusQueryParam);

   System.out.println(responseResult);

   Assert.assertEquals("0", responseResult.getCode());

   Assert.assertEquals("OK", responseResult.getMessage());

  }

 

  

  

  


 

 

  

  
早年同窗始相知,三载瞬逝情却萌。年少不知愁滋味,犹读红豆生南国。别离方知相思苦,心田红豆根以生。

  以上就是大趋智能打印机java api(大趋智能打印机离线)的详细内容,想要了解更多 大趋智能打印机java api的内容,请持续关注盛行IT软件开发工作室。

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: