|
|
@@ -1580,77 +1580,63 @@ public class FeiYunUtils {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
sb.append("<AUDIO-REFUND>");
|
|
|
- sb.append("#").append(tbOrder.getCountOrder()).append("-").append("墨轩云商<BR>");
|
|
|
+ sb.append("#").append(tbOrder.getOrderSequence()).append("-").append("墨轩云商<BR>");
|
|
|
sb.append("<CB>用户已取消,请勿继续配送</CB><BR>");
|
|
|
sb.append(tbOrder.getShopName()+"<BR>");
|
|
|
sb.append("订单号:").append(tbOrder.getOrderNumber()).append("<BR>");
|
|
|
- sb.append("类型:").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append("<BR>");
|
|
|
sb.append("<BR>");
|
|
|
sb.append("<CUT>");
|
|
|
|
|
|
- String content = sb.toString();
|
|
|
- RequestConfig requestConfig = RequestConfig.custom()
|
|
|
- .setSocketTimeout(30000)//读取超时
|
|
|
- .setConnectTimeout(30000)//连接超时
|
|
|
- .build();
|
|
|
+ doRequest(sn, sb.toString());
|
|
|
|
|
|
- CloseableHttpClient httpClient = HttpClients.custom()
|
|
|
- .setDefaultRequestConfig(requestConfig)
|
|
|
- .build();
|
|
|
- String URL = commonInfoService.findOne(325).getValue();
|
|
|
- String USER = commonInfoService.findOne(326).getValue();
|
|
|
- String UKEY = commonInfoService.findOne(327).getValue();
|
|
|
- HttpPost post = new HttpPost(URL);
|
|
|
- List<NameValuePair> nvps = new ArrayList<>();
|
|
|
- nvps.add(new BasicNameValuePair("user", USER));
|
|
|
- String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
|
|
- nvps.add(new BasicNameValuePair("stime", STIME));
|
|
|
- nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
|
|
|
- nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改
|
|
|
- nvps.add(new BasicNameValuePair("sn", sn));
|
|
|
- nvps.add(new BasicNameValuePair("content", content));
|
|
|
- nvps.add(new BasicNameValuePair("times", "1"));//打印联数
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("退款小票打印失败:{},{}" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- CloseableHttpResponse response = null;
|
|
|
- String result = null;
|
|
|
- try {
|
|
|
- post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
|
|
|
- response = httpClient.execute(post);
|
|
|
- int statecode = response.getStatusLine().getStatusCode();
|
|
|
- if (statecode == 200) {
|
|
|
- HttpEntity httpentity = response.getEntity();
|
|
|
- if (httpentity != null) {
|
|
|
- //服务器返回的JSON字符串,建议要当做日志记录起来
|
|
|
- result = EntityUtils.toString(httpentity);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- if (response != null) {
|
|
|
- response.close();
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- try {
|
|
|
- post.abort();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- try {
|
|
|
- httpClient.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ private static void doRequest(String sn, String content) {
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom()
|
|
|
+ .setSocketTimeout(30000)//读取超时
|
|
|
+ .setConnectTimeout(30000)//连接超时
|
|
|
+ .build();
|
|
|
+
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build()) {
|
|
|
+ String url = commonInfoService.findOne(325).getValue();
|
|
|
+ String user = commonInfoService.findOne(326).getValue();
|
|
|
+ String uKey = commonInfoService.findOne(327).getValue();
|
|
|
+ HttpPost post = new HttpPost(url);
|
|
|
+ List<NameValuePair> nameValuePairs = new ArrayList<>();
|
|
|
+
|
|
|
+ String sTime = String.valueOf(System.currentTimeMillis() / 1000);
|
|
|
+
|
|
|
+ nameValuePairs.add(new BasicNameValuePair("user", user));
|
|
|
+ nameValuePairs.add(new BasicNameValuePair("stime", sTime));
|
|
|
+ nameValuePairs.add(new BasicNameValuePair("sig", signature(user, uKey, sTime)));
|
|
|
+ nameValuePairs.add(new BasicNameValuePair("apiname", "Open_printMsg"));
|
|
|
+ nameValuePairs.add(new BasicNameValuePair("sn", sn));
|
|
|
+ nameValuePairs.add(new BasicNameValuePair("content", content));
|
|
|
+ nameValuePairs.add(new BasicNameValuePair("times", "1"));
|
|
|
+
|
|
|
+ post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
|
|
|
+ CloseableHttpResponse response = httpClient.execute(post);
|
|
|
+ int stateCode = response.getStatusLine().getStatusCode();
|
|
|
+
|
|
|
+ if (stateCode == 200) {
|
|
|
+ HttpEntity httpentity = response.getEntity();
|
|
|
+ String result = "";
|
|
|
+ if (httpentity != null) {
|
|
|
+ result = EntityUtils.toString(httpentity);
|
|
|
}
|
|
|
+
|
|
|
+ log.info("打印请求成功,打印机sn:{},打印内容:{},响应结果:{}", sn, content, result);
|
|
|
+ } else {
|
|
|
+ log.error("打印请求失败,响应码为:{}", stateCode);
|
|
|
}
|
|
|
- return result;
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error("打印异常:" + e.getMessage(), e);
|
|
|
+ log.error("打印请求失败,失败原因:{}", e.getMessage());
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
/**
|