| @@ -6,9 +6,7 @@ import java.security.NoSuchAlgorithmException; | |||
| import java.util.*; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.douyin.pay.orderQuery.QueryMerchantResult; | |||
| import com.iformall.douyin.pay.orderQuery.QueryRefundResult; | |||
| import com.iformall.douyin.pay.orderQuery.QuerySettleResult; | |||
| import com.iformall.douyin.pay.orderQuery.*; | |||
| import com.iformall.douyin.pay.preOrder.*; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| @@ -16,7 +14,6 @@ import com.iformall.utils.sign.SignUtils; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.douyin.pay.orderQuery.OrderQueryResult; | |||
| import com.iformall.utils.HttpUtil; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| @@ -352,8 +349,9 @@ public class DouYinPayHelper { | |||
| } | |||
| } | |||
| //可分账余额查询 | |||
| //https://developer.toutiao.com/api/apps/ecpay/v1/unsettle_amount | |||
| public static void unsettleAmount(String appId,String salt,String outOrderId,String thirdParytyId) { | |||
| public static QueryUnsettleAmount unsettleAmount(String appId, String salt, String outOrderId, String thirdParytyId) { | |||
| Map map = new HashMap(); | |||
| map.put("app_id",appId); | |||
| map.put("salt",salt); | |||
| @@ -363,19 +361,24 @@ public class DouYinPayHelper { | |||
| String response = doPost("https://developer.toutiao.com/api/apps/ecpay/v1/unsettle_amount", map); | |||
| log.info("查询待分账金额 request:"+map.toString()+" response:"+response); | |||
| JSONObject jsonObject = JSON.parseObject(response); | |||
| // Integer code = jsonObject.getInteger("err_no"); | |||
| // if (null != code && code.intValue() == 0 ) { | |||
| // JSONObject info = jsonObject.getJSONObject("settle_info"); | |||
| // QuerySettleResult result = new QuerySettleResult(); | |||
| // result.setSettleNo(info.getString("settle_no")); | |||
| // result.setSettleAmount(info.getInteger("settle_amount")); | |||
| // result.setSettleStatus(info.getString("settle_status")); | |||
| // result.setMsg(jsonObject.getString("err_tips")); | |||
| // return result; | |||
| // }else { | |||
| // log.error("settleQuery reponse error. request: "+JSON.toJSONString(map)+" response:"+response); | |||
| //// return null; | |||
| // } | |||
| Integer code = jsonObject.getInteger("err_no"); | |||
| if (null != code && code.intValue() == 0 ) { | |||
| JSONObject data = jsonObject.getJSONObject("data"); | |||
| QueryUnsettleAmount result = new QueryUnsettleAmount(); | |||
| result.setOutOrderNo(data.getString("out_order_no")); | |||
| result.setUnsettleAmount(data.getInteger("unsettle_amount")); | |||
| JSONObject detail = data.getJSONObject("detail"); | |||
| JSONObject payInfo = detail.getJSONObject("pay_info"); | |||
| result.setOutPayNo(payInfo.getString("out_order_no")); | |||
| result.setAmount(payInfo.getInteger("amount")); | |||
| result.setPaymentRake(detail.getInteger("payment_rake")); | |||
| result.setLifeRake(detail.getInteger("life_rake")); | |||
| result.setCommission(detail.getInteger("commission")); | |||
| return result; | |||
| }else { | |||
| log.error("unsettleAmount reponse error. request: "+JSON.toJSONString(map)+" response:"+response); | |||
| return null; | |||
| } | |||
| } | |||
| public static void main(String[] args) { | |||
| @@ -0,0 +1,18 @@ | |||
| package com.iformall.douyin.pay.orderQuery; | |||
| import lombok.Data; | |||
| @Data | |||
| public class QueryUnsettleAmount { | |||
| private String outOrderNo;//商户侧的订单号 | |||
| private Integer unsettleAmount;//剩余待结算金额 | |||
| private String outPayNo;//外部支付单单号 | |||
| private Integer amount;//支付单总金额 | |||
| private Integer paymentRake;//平台支付手续费金额,单位为分 | |||
| private Integer lifeRake;//平台行业抽佣金额,单位为分 | |||
| private Integer commission;//平台达人分佣金额,单位为分 | |||
| } | |||
| @@ -126,7 +126,7 @@ public class DaHuaParkService extends BaseParkService implements ParkAdapterServ | |||
| @Override | |||
| public String bindCar(Map<String, String> paramMap, WxPark park, WxCUserBasicInfo member) throws Exception{ | |||
| return "jieshunV2"; | |||
| return "dahua"; | |||
| } | |||
| @@ -147,29 +147,29 @@ public class DaHuaParkService extends BaseParkService implements ParkAdapterServ | |||
| //下订单; | |||
| String retCode = dahua.getCarStopFee(park, carNumber, getCacheToken(park)); | |||
| if (StringUtils.isBlank(retCode)) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "dahua createOrder error. has no result"); | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "dahua getCarStopFee error. has no result"); | |||
| } | |||
| JSONObject result = JSON.parseObject(retCode); | |||
| if (!result.getBoolean("success") ) { | |||
| String message = result.getString("errMsg"); | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "dahua createOrder error."+message); | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "dahua getCarStopFee error."+message); | |||
| } | |||
| JSONObject attribute = result.getJSONObject("data"); | |||
| if (null == attribute ) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "dahua createOrder error. no order result"+carNumber); | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "dahua getCarStopFee error. no order result"+carNumber); | |||
| } | |||
| Double totalFee = attribute.getDouble("totalFee"); | |||
| String appId = "wxe01cc0f34a5c70dc"; | |||
| String parkOrderId = attribute.getString("orderNo"); | |||
| String parkOrderId = null; | |||
| //String parkOrderId = attribute.getString("orderNo"); | |||
| Integer freeMinute = (Integer)park.getVendorParamsByKey("freeMinute"); | |||
| String createTime = attribute.getString("startTime");//计费时间,格式为“yyyy-MM-dd HH:mi:ss” | |||
| String endTime = attribute.getString("endTime");//离场时间,格式为“yyyy-MM-dd HH:mi:ss” | |||
| String payPath = "pages/parkingPay/parkingPay?orderNo="+parkOrderId+"&freeMinute="+freeMinute; | |||
| //String payPath = "pages/thirdPayOrder/payOrder?carNo="+jieshun.handleCarNumber(carNumber)+"&parkCode="+park.getParkingId(); | |||
| return new ParkStopFee(parkOrderId,dahua.utcToLocal(createTime),dahua.utcToLocal(endTime), | |||
| //String endTime = attribute.getString("endTime");//离场时间,格式为“yyyy-MM-dd HH:mi:ss” | |||
| String payPath = "pages/parkingOrder/parkingOrder?carNum="+carNumber+"&isFromPay=1&filterRoadsideInParking=0"; | |||
| return new ParkStopFee(parkOrderId,dahua.utcToLocal(createTime),new Date(), | |||
| String.valueOf(totalFee),appId,payPath,null,null,"请支付后"+freeMinute+"分钟内离场"); | |||
| } | |||
| @@ -198,60 +198,32 @@ public class DaHuaParkService extends BaseParkService implements ParkAdapterServ | |||
| } | |||
| //String ret = jieshun.getCoupon(park, planNo,userCar.getCUserPhone(), getCacheToken(park)); | |||
| //打折登陆验证 | |||
| String ret = dahua.verifyuser(park, getCacheToken(park)); | |||
| logger.info("jieshun verifyuser result:"+ret); | |||
| String ret = dahua.getCoupon(park,carNumber,planNo, getCacheToken(park)); | |||
| logger.info("dahua getCoupon result:"+ret); | |||
| JSONObject retObj = JSON.parseObject(ret); | |||
| if (retObj.getIntValue("resultCode") == 0){ | |||
| JSONArray verfyArrays = retObj.getJSONArray("dataItems"); | |||
| if (null != verfyArrays && verfyArrays.size() > 0 ) { | |||
| JSONObject verfy = verfyArrays.getJSONObject(0).getJSONObject("attributes"); | |||
| String userId = verfy.getString("userId"); | |||
| if (retObj.getBoolean("success")){ | |||
| JSONObject getCoupon = retObj.getJSONObject("data"); | |||
| if (null != getCoupon) { | |||
| String id = getCoupon.getString("id"); | |||
| //查询门店下打折方案 | |||
| String queryPlanRet = dahua.querySalePlan(park, getCacheToken(park), userId); | |||
| logger.info("jieshun querySalePlan result:"+queryPlanRet); | |||
| JSONObject queryPlantRetObj = JSON.parseObject(queryPlanRet); | |||
| if (queryPlantRetObj.getIntValue("resultCode") == 0){ | |||
| JSONArray planArrays = queryPlantRetObj.getJSONArray("dataItems"); | |||
| if (null != planArrays && planArrays.size() > 0 ) { | |||
| boolean hasPlan = false; | |||
| for (int i = 0 ; i < planArrays.size(); i++) { | |||
| JSONObject plan = planArrays.getJSONObject(i); | |||
| String planId = plan.getJSONObject("attributes").getString("planId"); | |||
| if (planNo.equals(planId)) { | |||
| hasPlan = true; | |||
| break; | |||
| } | |||
| } | |||
| if (!hasPlan) { | |||
| return new ResultData(ErrorCode.CYF_STOP_FEE_FAIL.getCode(),"当前优惠券配置的捷顺编号无效,请联系管理员。"+coupon.getTitle()); | |||
| } | |||
| //使用打折方案 | |||
| String executeRet = dahua.executediscount(park, planNo, userId, carNumber, getCacheToken(park)); | |||
| logger.info("jieshun executediscount result:"+executeRet); | |||
| JSONObject executeRetObj = JSON.parseObject(executeRet); | |||
| if (executeRetObj.getIntValue("resultCode") == 0){ | |||
| return new ResultData(); | |||
| }else { | |||
| return new ResultData(executeRetObj.getIntValue("resultCode"),"当前用户使用捷顺停打折方案失败。"+executeRetObj.getString("message")); | |||
| } | |||
| }else { | |||
| return new ResultData(ErrorCode.CYF_STOP_FEE_FAIL.getCode(),"捷顺查询门店未查询到打折信息,请联系管理员。"+userCar.getcUserId()); | |||
| } | |||
| String issueCoupon = dahua.issueCoupon(park,id, getCacheToken(park)); | |||
| logger.info("dahua issueCoupon result:"+issueCoupon); | |||
| JSONObject queryPlantRetObj = JSON.parseObject(issueCoupon); | |||
| if (queryPlantRetObj.getBoolean("success")){ | |||
| return new ResultData(); | |||
| }else { | |||
| logger.error("jieshun querySalePlan error. paramMap: {} . jieshunResult: {}",JSON.toJSONString(paramMap),queryPlanRet); | |||
| String msg = queryPlantRetObj.getString("message"); | |||
| return new ResultData(queryPlantRetObj.getIntValue("resultCode"), "捷顺查询门店打折方案失败:"+msg); | |||
| logger.error("dahua issueCoupon error. paramMap: {} . dahuaResult: {}",JSON.toJSONString(paramMap),issueCoupon); | |||
| String msg = queryPlantRetObj.getString("errMsg"); | |||
| return new ResultData(ErrorCode.CYF_STOP_FEE_FAIL.getCode(), "大华下发优惠券失败:"+msg); | |||
| } | |||
| }else { | |||
| return new ResultData(ErrorCode.CYF_STOP_FEE_FAIL.getCode(),"捷顺门店账号登陆失败,请联系管理员。"+userCar.getcUserId()); | |||
| return new ResultData(ErrorCode.CYF_STOP_FEE_FAIL.getCode(),"当前用户领用大华停车券失败, 未返回数据"+userCar.getcUserId()); | |||
| } | |||
| }else { | |||
| logger.error("jieshun verifyuser error. paramMap: {} . jieshunResult: {}",JSON.toJSONString(paramMap),ret); | |||
| String msg = retObj.getString("message"); | |||
| return new ResultData(retObj.getIntValue("resultCode"), "当前用户领用到捷顺停车券失败:"+msg); | |||
| logger.error("dahua getCoupon error. paramMap: {} . dahuaResult: {}",JSON.toJSONString(paramMap),ret); | |||
| String msg = retObj.getString("errMsg"); | |||
| return new ResultData(ErrorCode.CYF_STOP_FEE_FAIL.getCode(), "当前用户领用大华停车券失败:"+msg); | |||
| } | |||
| } | |||
| @@ -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"; | |||