提交代码

dev-discount
胡锐 2 years ago
parent f7167bf25d
commit 4a81bfeab2
  1. 124
      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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String,Object> map) throws Exception {
Map<String, Object> 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<String, Object> 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;
}
/**
* 生成签名

Loading…
Cancel
Save