|
|
|
@ -7,6 +7,7 @@ import com.hai.common.utils.HttpsUtils; |
|
|
|
|
import com.hai.common.utils.MD5Util; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -15,39 +16,73 @@ import java.util.*; |
|
|
|
|
*/ |
|
|
|
|
public class UnionPayConfig { |
|
|
|
|
|
|
|
|
|
public static JSONObject apppayacc() throws Exception { |
|
|
|
|
/** |
|
|
|
|
* APP控件支付 |
|
|
|
|
* 文档地址: https://doc.eycard.cn/web/#/42?page_id=1516
|
|
|
|
|
* @param orderNo 订单号 |
|
|
|
|
* @param payPrice 支付金额 【单位:分】 |
|
|
|
|
* @param orderDesc 订单描述 或 商品描述;例如:购买中石化加油券300元。 |
|
|
|
|
* @return 响应信息 |
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
public static JSONObject upPreOrder(String orderNo, Long payPrice, String orderDesc) throws Exception { |
|
|
|
|
Map<String,Object> paramMap = new HashMap<>(); |
|
|
|
|
/* paramMap.put("channelid", "D01X66666666761"); |
|
|
|
|
paramMap.put("merid", "531000012972390"); |
|
|
|
|
paramMap.put("termid", "W1489519"); |
|
|
|
|
paramMap.put("tradetrace", System.currentTimeMillis()); |
|
|
|
|
paramMap.put("opt", "dirBankPay"); |
|
|
|
|
paramMap.put("tradetype", "APP"); |
|
|
|
|
paramMap.put("tradeamt", "1"); |
|
|
|
|
paramMap.put("body", "test"); |
|
|
|
|
paramMap.put("notifyurl", "notifyurl"); |
|
|
|
|
paramMap.put("returnurl", "returnurl");*/ |
|
|
|
|
|
|
|
|
|
paramMap.put("channelid", "D01X66666666761"); |
|
|
|
|
paramMap.put("merid", "531000012972390"); |
|
|
|
|
paramMap.put("termid", "W1489519"); |
|
|
|
|
paramMap.put("tradetrace", System.currentTimeMillis()); |
|
|
|
|
paramMap.put("channelid", CommonSysConst.getSysConfig().getUnionPayChannelid()); |
|
|
|
|
paramMap.put("merid", CommonSysConst.getSysConfig().getUnionPayMerid()); |
|
|
|
|
paramMap.put("termid", CommonSysConst.getSysConfig().getUnionPayTermid()); |
|
|
|
|
paramMap.put("tradetrace", orderNo); |
|
|
|
|
paramMap.put("opt", "upPreOrder"); |
|
|
|
|
paramMap.put("tradetype", "APP"); |
|
|
|
|
paramMap.put("tradeamt", "1"); |
|
|
|
|
paramMap.put("body", "test"); |
|
|
|
|
paramMap.put("tradeamt", payPrice); |
|
|
|
|
paramMap.put("body", orderDesc); |
|
|
|
|
paramMap.put("notifyurl", "notifyurl"); |
|
|
|
|
return HttpsUtils.doPostForm(CommonSysConst.getSysConfig().getUnionPayUrl(), generateRequestParam(paramMap), new HashMap<>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 交易查询 |
|
|
|
|
* @param paySerialNo 第三方支付流水 |
|
|
|
|
* @return |
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
public static JSONObject tradeQuery(String paySerialNo) throws Exception { |
|
|
|
|
Map<String,Object> paramMap = new HashMap<>(); |
|
|
|
|
paramMap.put("channelid", CommonSysConst.getSysConfig().getUnionPayChannelid()); |
|
|
|
|
paramMap.put("merid", CommonSysConst.getSysConfig().getUnionPayMerid()); |
|
|
|
|
paramMap.put("termid", CommonSysConst.getSysConfig().getUnionPayTermid()); |
|
|
|
|
paramMap.put("tradetrace", paySerialNo); |
|
|
|
|
paramMap.put("opt", "tradeQuery"); |
|
|
|
|
paramMap.put("tradetype", "samecardQuery"); |
|
|
|
|
return HttpsUtils.doPostForm(CommonSysConst.getSysConfig().getUnionPayUrl(), generateRequestParam(paramMap), new HashMap<>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String reqStr = generateSignature(paramMap, null); |
|
|
|
|
paramMap.put("sign", MD5Util.encode(generateSignature(paramMap,"sa72ivadl84273dlj2kdaia2idiadik5").getBytes()).toLowerCase()); |
|
|
|
|
reqStr += "&sign=" + MD5Util.encode(generateSignature(paramMap,"sa72ivadl84273dlj2kdaia2idiadik5").getBytes()).toUpperCase(); |
|
|
|
|
Map<String,Object> body = new LinkedHashMap<>(); |
|
|
|
|
body.put("from", reqStr); |
|
|
|
|
return HttpsUtils.doSmsPost("https://notify-test.eycard.cn:7443/WorthTech_Access_AppPaySystemV2/apppayacc", body, new HashMap<>()); |
|
|
|
|
/** |
|
|
|
|
* 交易退货 |
|
|
|
|
* @param orderNo 订单号 |
|
|
|
|
* @param paySerialNo 第三方订单号 |
|
|
|
|
* @param refundPrice 退款金额 |
|
|
|
|
* @return |
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
public static JSONObject zwrefund(String orderNo,String paySerialNo,Long refundPrice) throws Exception { |
|
|
|
|
Map<String,Object> paramMap = new HashMap<>(); |
|
|
|
|
paramMap.put("channelid", CommonSysConst.getSysConfig().getUnionPayChannelid()); |
|
|
|
|
paramMap.put("merid", CommonSysConst.getSysConfig().getUnionPayMerid()); |
|
|
|
|
paramMap.put("termid", CommonSysConst.getSysConfig().getUnionPayTermid()); |
|
|
|
|
paramMap.put("tradetrace", orderNo); |
|
|
|
|
paramMap.put("oritradetrace", paySerialNo); |
|
|
|
|
paramMap.put("tradeamt", refundPrice); |
|
|
|
|
paramMap.put("opt", "zwrefund"); |
|
|
|
|
return HttpsUtils.doPostForm(CommonSysConst.getSysConfig().getUnionPayUrl(), generateRequestParam(paramMap), new HashMap<>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static String generateSignature(final Map<String, Object> data, String key){ |
|
|
|
|
Set<String> keySet = data.keySet(); |
|
|
|
|
/** |
|
|
|
|
* 参数排序 |
|
|
|
|
* @param param |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private static String paramSort(final Map<String, Object> param) { |
|
|
|
|
Set<String> keySet = param.keySet(); |
|
|
|
|
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
|
|
|
|
Arrays.sort(keyArray); |
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
@ -56,15 +91,31 @@ public class UnionPayConfig { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isBlank(sb.toString())) { |
|
|
|
|
sb.append(k).append("=").append(data.get(k)); |
|
|
|
|
sb.append(k).append("=").append(param.get(k)); |
|
|
|
|
} else { |
|
|
|
|
sb.append("&").append(k).append("=").append(data.get(k)); |
|
|
|
|
sb.append("&").append(k).append("=").append(param.get(k)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isNotBlank(key)) { |
|
|
|
|
sb.append("&key=").append(key); |
|
|
|
|
} |
|
|
|
|
return sb.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 生成请求参数 |
|
|
|
|
* @param data |
|
|
|
|
* @return |
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
private static String generateRequestParam(final Map<String, Object> data) throws Exception{ |
|
|
|
|
String paramSort = paramSort(data); |
|
|
|
|
|
|
|
|
|
// 生产签名参数
|
|
|
|
|
String signParam = paramSort; |
|
|
|
|
// 签名参数拼接签名秘钥
|
|
|
|
|
signParam += "&key=" + CommonSysConst.getSysConfig().getUnionPaySignKey(); |
|
|
|
|
|
|
|
|
|
// 请求参数拼接签名
|
|
|
|
|
paramSort += "&sign=" + MD5Util.encode(signParam.getBytes()); |
|
|
|
|
return paramSort; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|