|
|
|
@@ -51,18 +51,10 @@ import java.util.TimeZone; |
|
|
|
public class DaHuaUtil { |
|
|
|
|
|
|
|
public static final String TOKEN_URL = "https://www.cloud-dahua.com/gateway/auth/oauth/token"; |
|
|
|
|
|
|
|
public static final String CREATE_ORDER = "https://open-pkc.cloud-dahua.com/jsaims/as"; |
|
|
|
|
|
|
|
public static final String QUERY_ORDER = "http://www.jslife.com.cn/jsaims/as"; |
|
|
|
|
|
|
|
public static final String QUERY_FEE = "https://open-pkc.cloud-dahua.com/openplatform/parkinglot/v1/getNotPaidAmountByCarNum"; |
|
|
|
public static final String GET_COUPON = "https://open-pkc.cloud-dahua.com/openplatform/coupon/v1/grantCoupon"; |
|
|
|
public static final String COUPON_USE = "http://www.jslife.com.cn/jsaims/as"; |
|
|
|
public static final String COUPON_USE = "https://open-pkc.cloud-dahua.com/openplatform/coupon/v1/issueCoupon"; |
|
|
|
|
|
|
|
public static final String VERIFY_USER = "http://www.jslife.com.cn/jsaims/as"; |
|
|
|
public static final String QUERY_PLAN = "http://www.jslife.com.cn/jsaims/as"; |
|
|
|
public static final String PLAN_EXECUTE = "http://www.jslife.com.cn/jsaims/as"; |
|
|
|
|
|
|
|
/** |
|
|
|
* @description UTC时间转化为本地时间 |
|
|
|
* @Params [utcTime] |
|
|
|
@@ -107,104 +99,46 @@ public class DaHuaUtil { |
|
|
|
return res.getString("access_token"); |
|
|
|
} |
|
|
|
|
|
|
|
private Map generateMap(String serviceId,Map param) { |
|
|
|
Map map = new HashMap(); |
|
|
|
map.put("serviceId", serviceId); |
|
|
|
map.put("requestType", "DATA"); |
|
|
|
map.put("attributes", param); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
public String handleCarNumber(String carNumber) { |
|
|
|
if (carNumber.contains("-")) { |
|
|
|
return carNumber; |
|
|
|
}else { |
|
|
|
carNumber = carNumber.substring(0,1)+"-"+carNumber.substring(1, carNumber.length()); |
|
|
|
return carNumber; |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* 创建订单 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String createOrder(WxPark wxPark,String cardNumber,String token) { |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
Map param = new HashMap(); |
|
|
|
param.put("businesserCode", vp.getString("cid"));//商户编号 |
|
|
|
param.put("parkCode", wxPark.getParkingId()); |
|
|
|
param.put("orderType", "VNP"); |
|
|
|
param.put("carNo", handleCarNumber(cardNumber)); |
|
|
|
Map map = generateMap("3c.pay.createorderbycarno",param); |
|
|
|
log.info("jieshunv2 create order :" + JSON.toJSONString(map)); |
|
|
|
return ProcBussiness(CREATE_ORDER, vp.getString("cid"), map, token); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询停车费 |
|
|
|
**/ |
|
|
|
public String getCarStopFee(WxPark wxPark,String orderNo,String token){ |
|
|
|
public String getCarStopFee(WxPark wxPark,String carNumber,String token){ |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
Map param = new HashMap(); |
|
|
|
param.put("orderNo", orderNo);//商户编号 |
|
|
|
Map map = generateMap("3c.pay.queryorder",param); |
|
|
|
log.info("jieshunv2 getCarStopFee :" + JSON.toJSONString(map)); |
|
|
|
return ProcBussiness(QUERY_ORDER, vp.getString("cid"), map, token); |
|
|
|
Map<String,Object> param = new HashMap<String,Object>(); |
|
|
|
param.put("carNum", carNumber);//商户编号 |
|
|
|
log.info("dahua getCarStopFee :" + JSON.toJSONString(param)); |
|
|
|
return ProcBussiness(QUERY_FEE, vp.getString("clientId"), param, token); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 打折登陆验证 |
|
|
|
* 领取优惠券 |
|
|
|
*/ |
|
|
|
public String verifyuser(WxPark wxPark,String token) { |
|
|
|
public String getCoupon(WxPark wxPark,String carNumber,String couponNo,String token) { |
|
|
|
try { |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
Map param = new HashMap(); |
|
|
|
param.put("userCode", vp.get("loginUser"));//商户编号 |
|
|
|
|
|
|
|
MessageDigest md5Tool = MessageDigest.getInstance("MD5"); |
|
|
|
byte[] md5Data = md5Tool.digest((vp.getString("loginPassword")).getBytes("UTF-8")); |
|
|
|
String sn = toHexString(md5Data); |
|
|
|
param.put("password", sn.toLowerCase());//优惠券编号 |
|
|
|
Map map = generateMap("3c.discount.verifyuser",param); |
|
|
|
log.info("jieshunv2 verifyuser :" + JSON.toJSONString(map)); |
|
|
|
return ProcBussiness(VERIFY_USER, vp.getString("cid"), map, token); |
|
|
|
} catch (NoSuchAlgorithmException e) { |
|
|
|
log.error("jieshunv2 verifyuser error.park:"+wxPark.getId(),e); |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"jieshunv2 verifyuser error.park:"+wxPark.getId()+".error"+e.getMessage()); |
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
log.error("jieshunv2 verifyuser error.park:"+wxPark.getId(),e); |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"jieshunv2 verifyuser error.park:"+wxPark.getId()+".error"+e.getMessage()); |
|
|
|
Map<String,Object> param = new HashMap<String,Object>(); |
|
|
|
param.put("carNum", carNumber);//商户编号 |
|
|
|
param.put("batchNumber", couponNo);//优惠券批次号 |
|
|
|
log.info("dahua getCoupon :" + JSON.toJSONString(param)); |
|
|
|
return ProcBussiness(GET_COUPON, vp.getString("clientId"), param, token); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("dahua getCoupon error.park:"+wxPark.getId(),e); |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"dahua getCoupon error.park:"+wxPark.getId()+".error"+e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询门店打折方案 |
|
|
|
* 下发使用优惠券 |
|
|
|
*/ |
|
|
|
public String querySalePlan(WxPark wxPark,String token,String userId) { |
|
|
|
public String issueCoupon(WxPark wxPark,String id,String token) { |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
Map param = new HashMap(); |
|
|
|
param.put("userId", userId);//商户编号 |
|
|
|
Map map = generateMap("3c.discount.querysaleplan",param); |
|
|
|
log.info("jieshunv2 querySalePlan :" + JSON.toJSONString(map)); |
|
|
|
return ProcBussiness(QUERY_PLAN, vp.getString("cid"), map, token); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 使用打折方案 |
|
|
|
*/ |
|
|
|
public String executediscount(WxPark wxPark,String planId,String userId,String carNumber,String token) { |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
Map param = new HashMap(); |
|
|
|
param.put("planId", planId);//商户编号 |
|
|
|
param.put("userId", userId);//优惠券编号 |
|
|
|
param.put("carOrCardNo", handleCarNumber(carNumber));//优惠券编号 |
|
|
|
Map map = generateMap("3c.discount.executediscount",param); |
|
|
|
log.info("jieshunv2 executediscount :" + JSON.toJSONString(map)); |
|
|
|
return ProcBussiness(PLAN_EXECUTE, vp.getString("cid"), map, token); |
|
|
|
Map<String,Object> param = new HashMap<String,Object>(); |
|
|
|
param.put("couponId", id);//券id |
|
|
|
log.info("dahua issueCoupon :" + JSON.toJSONString(param)); |
|
|
|
return ProcBussiness(COUPON_USE, vp.getString("clientId"), param, token); |
|
|
|
} |
|
|
|
|
|
|
|
/*token认证登陆**/ |
|
|
|
@@ -213,41 +147,10 @@ public class DaHuaUtil { |
|
|
|
return Proc(url,content_type_token,null,null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 优惠券使用完毕,0元停车费需调用次接口结清订单 |
|
|
|
* @param wxPark |
|
|
|
* @param planId |
|
|
|
* @param userId |
|
|
|
* @param carNumber |
|
|
|
* @param token |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String notifyOrderResult(WxPark wxPark,String orderNo,String token) { |
|
|
|
String vendroParams = wxPark.getVendorParams(); |
|
|
|
JSONObject vp = JSON.parseObject(vendroParams); |
|
|
|
Map param = new HashMap(); |
|
|
|
param.put("orderNo", orderNo);//商户编号 |
|
|
|
param.put("tradeStatus", 0);//优惠券编号 |
|
|
|
param.put("isCallBack", 0);//优惠券编号 |
|
|
|
Map map = generateMap("3c.pay.notifyorderresult",param); |
|
|
|
log.info("jieshunv2 notifyOrderResult :" + JSON.toJSONString(map)); |
|
|
|
return ProcBussiness(PLAN_EXECUTE, vp.getString("cid"), map, token); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String ProcBussiness(String url,String cid,Map<String,Object> param,String token) { |
|
|
|
try { |
|
|
|
// MessageDigest md5Tool = MessageDigest.getInstance("MD5"); |
|
|
|
// String p = JSON.toJSONString(param); |
|
|
|
// byte[] md5Data = md5Tool.digest((p+signKey).getBytes("UTF-8")); |
|
|
|
// String sn = toHexString(md5Data); |
|
|
|
// if (url.contains("?")) { |
|
|
|
// url = url + "&"; |
|
|
|
// }else { |
|
|
|
// url = url + "?"; |
|
|
|
// } |
|
|
|
// |
|
|
|
// url = url+"cid="+cid+"&tn="+token+"&sn="+sn+"&v="+version+"&p="+URLEncoder.encode(p, "UTF-8"); |
|
|
|
// |
|
|
|
return Proc(url,content_type_request,param,token); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("dahua request error.",e); |
|
|
|
@@ -255,14 +158,6 @@ public class DaHuaUtil { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private static String toHexString(byte[] bytes) { |
|
|
|
StringBuffer buffer = new StringBuffer(); |
|
|
|
for (int i = 0; i < bytes.length; i++) { |
|
|
|
buffer.append(String.format("%02X", bytes[i])); |
|
|
|
} |
|
|
|
return buffer.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
private static String content_type_token = "application/x-www-form-urlencoded"; |
|
|
|
private static String content_type_request = "application/json"; |
|
|
|
|
|
|
|
|