1.新增邮件,阿里,腾讯短信调用接口
2.新增微信模板通知,目前通知接口都是同步调用 3.添加redisson,延迟消息队列,超时订单自动取消
This commit is contained in:
@ -46,6 +46,7 @@
|
||||
<artifactId>alipay-sdk-java</artifactId>
|
||||
<version>${alipay.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
|
145
yshop-tools/src/main/java/co/yixiang/express/ExpressService.java
Normal file
145
yshop-tools/src/main/java/co/yixiang/express/ExpressService.java
Normal file
@ -0,0 +1,145 @@
|
||||
package co.yixiang.express;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import co.yixiang.express.config.ExpressProperties;
|
||||
import co.yixiang.express.dao.ExpressInfo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 物流查询服务
|
||||
* <p>
|
||||
* 快递鸟即时查询API http://www.kdniao.com/api-track
|
||||
*/
|
||||
public class ExpressService {
|
||||
|
||||
private final Log logger = LogFactory.getLog(ExpressService.class);
|
||||
//请求url
|
||||
private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
|
||||
|
||||
private ExpressProperties properties;
|
||||
|
||||
public ExpressProperties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(ExpressProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物流供应商名
|
||||
*
|
||||
* @param vendorCode
|
||||
* @return
|
||||
*/
|
||||
public String getVendorName(String vendorCode) {
|
||||
for (Map<String, String> item : properties.getVendors()) {
|
||||
if (item.get("code").equals(vendorCode))
|
||||
return item.get("name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物流信息
|
||||
*
|
||||
* @param expCode
|
||||
* @param expNo
|
||||
* @return
|
||||
*/
|
||||
public ExpressInfo getExpressInfo(String expCode, String expNo) {
|
||||
try {
|
||||
String result = getOrderTracesByJson(expCode, expNo);
|
||||
ObjectMapper objMap = new ObjectMapper();
|
||||
ExpressInfo ei = objMap.readValue(result, ExpressInfo.class);
|
||||
ei.setShipperName(getVendorName(expCode));
|
||||
return ei;
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Json方式 查询订单物流轨迹
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private String getOrderTracesByJson(String expCode, String expNo) throws Exception {
|
||||
if (!properties.isEnable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String requestData = "{'OrderCode':'','ShipperCode':'" + expCode + "','LogisticCode':'" + expNo + "'}";
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("RequestData", URLEncoder.encode(requestData, "UTF-8"));
|
||||
params.put("EBusinessID", properties.getAppId());
|
||||
params.put("RequestType", "1002");
|
||||
String dataSign = encrypt(requestData, properties.getAppKey(), "UTF-8");
|
||||
params.put("DataSign", URLEncoder.encode(dataSign, "UTF-8"));
|
||||
params.put("DataType", "2");
|
||||
|
||||
String result = HttpUtil.post(ReqURL, params);
|
||||
|
||||
//根据公司业务处理返回的信息......
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
*
|
||||
* @param str 内容
|
||||
* @param charset 编码方式
|
||||
* @throws Exception
|
||||
*/
|
||||
private String MD5(String str, String charset) throws Exception {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(str.getBytes(charset));
|
||||
byte[] result = md.digest();
|
||||
StringBuilder sb = new StringBuilder(32);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
int val = result[i] & 0xff;
|
||||
if (val <= 0xf) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(Integer.toHexString(val));
|
||||
}
|
||||
return sb.toString().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign签名生成
|
||||
*
|
||||
* @param content 内容
|
||||
* @param keyValue Appkey
|
||||
* @param charset 编码方式
|
||||
* @return DataSign签名
|
||||
*/
|
||||
private String encrypt(String content, String keyValue, String charset) {
|
||||
if (keyValue != null) {
|
||||
content = content + keyValue;
|
||||
}
|
||||
byte[] src;
|
||||
try {
|
||||
src = MD5(content, charset).getBytes(charset);
|
||||
return Base64Utils.encodeToString(src);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package co.yixiang.express.config;
|
||||
|
||||
import co.yixiang.express.ExpressService;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ExpressProperties.class)
|
||||
public class ExpressAutoConfiguration {
|
||||
|
||||
private final ExpressProperties properties;
|
||||
|
||||
public ExpressAutoConfiguration(ExpressProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ExpressService expressService() {
|
||||
ExpressService expressService = new ExpressService();
|
||||
expressService.setProperties(properties);
|
||||
return expressService;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package co.yixiang.express.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ConfigurationProperties(prefix = "yshop.express")
|
||||
public class ExpressProperties {
|
||||
private boolean enable;
|
||||
private String appId;
|
||||
private String appKey;
|
||||
private List<Map<String, String>> vendors = new ArrayList<>();
|
||||
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
public void setEnable(boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getVendors() {
|
||||
return vendors;
|
||||
}
|
||||
|
||||
public void setVendors(List<Map<String, String>> vendors) {
|
||||
this.vendors = vendors;
|
||||
}
|
||||
|
||||
public String getAppKey() {
|
||||
return appKey;
|
||||
}
|
||||
|
||||
public void setAppKey(String appKey) {
|
||||
this.appKey = appKey;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/**
|
||||
* Copyright 2018 bejson.com
|
||||
*/
|
||||
package co.yixiang.express.dao;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2018-07-19 22:27:22
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public class ExpressInfo {
|
||||
|
||||
@JsonProperty("LogisticCode")
|
||||
private String LogisticCode;
|
||||
@JsonProperty("ShipperCode")
|
||||
private String ShipperCode;
|
||||
@JsonProperty("Traces")
|
||||
private List<Traces> Traces;
|
||||
@JsonProperty("State")
|
||||
private String State;
|
||||
@JsonProperty("EBusinessID")
|
||||
private String EBusinessID;
|
||||
@JsonProperty("Success")
|
||||
private boolean Success;
|
||||
@JsonProperty("Reason")
|
||||
private String Reason;
|
||||
|
||||
private String ShipperName;
|
||||
|
||||
public String getLogisticCode() {
|
||||
return LogisticCode;
|
||||
}
|
||||
|
||||
public void setLogisticCode(String LogisticCode) {
|
||||
this.LogisticCode = LogisticCode;
|
||||
}
|
||||
|
||||
public String getShipperCode() {
|
||||
return ShipperCode;
|
||||
}
|
||||
|
||||
public void setShipperCode(String ShipperCode) {
|
||||
this.ShipperCode = ShipperCode;
|
||||
}
|
||||
|
||||
public List<Traces> getTraces() {
|
||||
return Traces;
|
||||
}
|
||||
|
||||
public void setTraces(List<Traces> Traces) {
|
||||
this.Traces = Traces;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return State;
|
||||
}
|
||||
|
||||
public void setState(String State) {
|
||||
this.State = State;
|
||||
}
|
||||
|
||||
public String getEBusinessID() {
|
||||
return EBusinessID;
|
||||
}
|
||||
|
||||
public void setEBusinessID(String EBusinessID) {
|
||||
this.EBusinessID = EBusinessID;
|
||||
}
|
||||
|
||||
public boolean getSuccess() {
|
||||
return Success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean Success) {
|
||||
this.Success = Success;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return Reason;
|
||||
}
|
||||
|
||||
public void setReason(String Reason) {
|
||||
this.Reason = Reason;
|
||||
}
|
||||
|
||||
public String getShipperName() {
|
||||
return ShipperName;
|
||||
}
|
||||
|
||||
public void setShipperName(String shipperName) {
|
||||
ShipperName = shipperName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExpressInfo{" +
|
||||
"LogisticCode='" + LogisticCode + '\'' +
|
||||
", ShipperCode='" + ShipperCode + '\'' +
|
||||
", Traces=" + Traces +
|
||||
", State='" + State + '\'' +
|
||||
", EBusinessID='" + EBusinessID + '\'' +
|
||||
", Success=" + Success +
|
||||
", Reason=" + Reason +
|
||||
", ShipperName='" + ShipperName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
37
yshop-tools/src/main/java/co/yixiang/express/dao/Traces.java
Normal file
37
yshop-tools/src/main/java/co/yixiang/express/dao/Traces.java
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2018 bejson.com
|
||||
*/
|
||||
package co.yixiang.express.dao;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2018-07-19 22:27:22
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public class Traces {
|
||||
|
||||
@JsonProperty("AcceptStation")
|
||||
private String AcceptStation;
|
||||
@JsonProperty("AcceptTime")
|
||||
private String AcceptTime;
|
||||
|
||||
public String getAcceptStation() {
|
||||
return AcceptStation;
|
||||
}
|
||||
|
||||
public void setAcceptStation(String AcceptStation) {
|
||||
this.AcceptStation = AcceptStation;
|
||||
}
|
||||
|
||||
public String getAcceptTime() {
|
||||
return AcceptTime;
|
||||
}
|
||||
|
||||
public void setAcceptTime(String AcceptTime) {
|
||||
this.AcceptTime = AcceptTime;
|
||||
}
|
||||
|
||||
}
|
174
yshop-tools/src/main/java/co/yixiang/utils/JacksonUtil.java
Normal file
174
yshop-tools/src/main/java/co/yixiang/utils/JacksonUtil.java
Normal file
@ -0,0 +1,174 @@
|
||||
package co.yixiang.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class JacksonUtil {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(JacksonUtil.class);
|
||||
|
||||
public static String parseString(String body, String field) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node;
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if (leaf != null)
|
||||
return leaf.asText();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> parseStringList(String body, String field) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node;
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
|
||||
if (leaf != null)
|
||||
return mapper.convertValue(leaf, new TypeReference<List<String>>() {
|
||||
});
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer parseInteger(String body, String field) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node;
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if (leaf != null)
|
||||
return leaf.asInt();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<Integer> parseIntegerList(String body, String field) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node;
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
|
||||
if (leaf != null)
|
||||
return mapper.convertValue(leaf, new TypeReference<List<Integer>>() {
|
||||
});
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static Boolean parseBoolean(String body, String field) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node;
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if (leaf != null)
|
||||
return leaf.asBoolean();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Short parseShort(String body, String field) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node;
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if (leaf != null) {
|
||||
Integer value = leaf.asInt();
|
||||
return value.shortValue();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Byte parseByte(String body, String field) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node;
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
JsonNode leaf = node.get(field);
|
||||
if (leaf != null) {
|
||||
Integer value = leaf.asInt();
|
||||
return value.byteValue();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T parseObject(String body, String field, Class<T> clazz) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node;
|
||||
try {
|
||||
node = mapper.readTree(body);
|
||||
node = node.get(field);
|
||||
return mapper.treeToValue(node, clazz);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object toNode(String json) {
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
|
||||
return mapper.readTree(json);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<String, String> toMap(String data) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
return objectMapper.readValue(data, new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String toJson(Object data) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
return objectMapper.writeValueAsString(data);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user