yshop1.4.2 商品新增多图评价,订单新增快递查询,导出最新sql

This commit is contained in:
hupeng
2019-12-09 18:04:26 +08:00
parent 696928eaf9
commit fe9bd6c901
16 changed files with 359 additions and 307 deletions

View File

@ -1,145 +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;
}
}
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 OrderCode
* @param ShipperCode
* @return
*/
public ExpressInfo getExpressInfo(String OrderCode,String ShipperCode, String LogisticCode) {
try {
String result = getOrderTracesByJson(OrderCode,ShipperCode, LogisticCode);
ObjectMapper objMap = new ObjectMapper();
ExpressInfo ei = objMap.readValue(result, ExpressInfo.class);
ei.setShipperName(getVendorName(ShipperCode));
return ei;
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return null;
}
/**
* Json方式 查询订单物流轨迹
*
* @throws Exception
*/
private String getOrderTracesByJson(String OrderCode,String ShipperCode, String LogisticCode) throws Exception {
if (!properties.isEnable()) {
return null;
}
String requestData = "{'OrderCode':'"+OrderCode+"','ShipperCode':'" + ShipperCode + "','LogisticCode':'" + LogisticCode + "'}";
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;
}
}

View File

@ -4,6 +4,7 @@
package co.yixiang.express.dao;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@ -13,6 +14,7 @@ import java.util.List;
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
@Data
public class ExpressInfo {
@JsonProperty("LogisticCode")
@ -32,81 +34,8 @@ public class ExpressInfo {
private String ShipperName;
public String getLogisticCode() {
return LogisticCode;
}
@JsonProperty("OrderCode")
private String OrderCode;
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 + '\'' +
'}';
}
}