diff --git a/hai-service/src/main/java/com/hai/config/ShellGroupService.java b/hai-service/src/main/java/com/hai/config/ShellGroupService.java index bef50f4e..89db01b9 100644 --- a/hai-service/src/main/java/com/hai/config/ShellGroupService.java +++ b/hai-service/src/main/java/com/hai/config/ShellGroupService.java @@ -1,56 +1,140 @@ package com.hai.config; - import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.sdk.WXPayConstants; +import com.hai.common.utils.DateUtil; import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.MD5Util; -import org.apache.commons.lang3.StringUtils; +import org.apache.http.NameValuePair; +import org.apache.http.message.BasicNameValuePair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.math.BigDecimal; +import java.util.*; /** * 壳牌接口服务 */ public class ShellGroupService { + private static Logger log = LoggerFactory.getLogger(ShellGroupService.class); + /** * 查询全量加油站 * @param pageNum 当前页码 * @param pageSize 每页数据量。最大值50 * @return */ - public static JSONObject gasPageQueryAllStation(Integer pageNum,Integer pageSize) { + public static JSONObject gasPageQueryAllStation(Integer pageNum,Integer pageSize) throws Exception { + Map param = new HashMap<>(); + param.put("platMerchantId", CommonSysConst.getSysConfig().getShellPlatMerchantId()); + param.put("pageNo", pageNum); + param.put("pageSize", pageSize); + return request("gasPageQueryAllStation", param); + } + + /** + * 查询单个油站全量信息 + * @param stationCode 油站编码 + * @return + */ + public static JSONObject gasStationQueryDetail(String stationCode) { try { Map param = new HashMap<>(); - param.put("merchantOrderNo", System.currentTimeMillis()); - param.put("partnerId", CommonSysConst.getSysConfig().getShellGroupPartnerId()); - param.put("service", "gasPageQueryAllStation"); - param.put("version", "1.0.0"); - param.put("signType", "MD5"); param.put("platMerchantId", CommonSysConst.getSysConfig().getShellPlatMerchantId()); - param.put("pageNo", pageNum); - param.put("pageSize", pageSize); - param.put("sign", MD5Util.encode(generateSignature(param, CommonSysConst.getSysConfig().getShellPlatMerchantKey()).getBytes())); + param.put("stationCode", stationCode); + return request("gasPageQueryAllStation", param); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + /** + * 【同步】油站付款 + * @param stationCode 油站编码 + * @return + */ + public static JSONObject gasSyncPayment(String stationCode, + Date finishTime, + BigDecimal amount, + String code, + String oilGun, + BigDecimal channelSettlementAmount) { + try { + + + Map param = new HashMap<>(); + param.put("platMerchantId", CommonSysConst.getSysConfig().getShellPlatMerchantId()); + param.put("stationCode", stationCode); + param.put("orderType", "OIL"); + param.put("finishTime", DateUtil.date2String(finishTime, "yyyy-MM-dd HH:mm:ss")); + Map tradeOilOrder = new HashMap<>(); + tradeOilOrder.put("amount", amount); + tradeOilOrder.put("code", code); + tradeOilOrder.put("oilGun", oilGun); + tradeOilOrder.put("channelSettlementAmount", channelSettlementAmount); + param.put("tradeOilOrder", tradeOilOrder); + return request("gas_sync_payment_notify", param); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 【同步】油站退款 + * @param finishTime 业务完成时间 + * @param tradeNo 交易流水号 + * @return + */ + public static JSONObject gasSyncRefund(Date finishTime,String tradeNo) { + try { + Map param = new HashMap<>(); + param.put("platMerchantId", CommonSysConst.getSysConfig().getShellPlatMerchantId()); + param.put("finishTime", DateUtil.date2String(finishTime, "yyyy-MM-dd HH:mm:ss")); + param.put("tradeNo", tradeNo); + param.put("sign", MD5Util.encode(generateSignature(param, CommonSysConst.getSysConfig().getShellPlatMerchantKey()).getBytes())); // 请求接口 - JSONObject object = HttpsUtils.doPost(CommonSysConst.getSysConfig().getShellGroupUrl(), param); - if (object == null || !object.getString("status").equals("SUCCESS")) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object == null?"请求失败":object.getString("message")); - } - return object; + return request("gas_sync_refund_notify", param); } catch (Exception e) { e.printStackTrace(); } return null; } + /** + * 接口请求 + * @param map + * @return + * @throws Exception + */ + private static JSONObject request(String service,Map map) throws Exception { + Map param = new HashMap<>(); + param.put("merchantOrderNo", System.currentTimeMillis()); + param.put("partnerId", CommonSysConst.getSysConfig().getShellGroupPartnerId()); + param.put("service", service); + param.put("version", "1.0.0"); + param.put("signType", "MD5"); + + for (Map.Entry entry : map.entrySet()) { + param.put(entry.getKey(), entry.getValue()); + } + param.put("sign", MD5Util.encode(generateSignature(param, CommonSysConst.getSysConfig().getShellPlatMerchantKey()).getBytes())); + + // 请求接口 + JSONObject object = HttpsUtils.doPost(CommonSysConst.getSysConfig().getShellGroupUrl(), param); + if (object == null || !object.getString("status").equals("SUCCESS")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object == null?"请求失败":object.getString("message")); + } + return object; + } /** * 生成签名