|
@@ -2,46 +2,81 @@ package com.ym.mec.thirdparty.yqpay;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
-import java.util.LinkedHashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
public class YqPayUtil {
|
|
public class YqPayUtil {
|
|
|
|
|
|
- private String merNo = "0021677";
|
|
|
|
|
|
+ private static final String merNo = "0021677"; //商户号
|
|
private static final String version = "1.1";
|
|
private static final String version = "1.1";
|
|
- private String notifyUrl;
|
|
|
|
- private String timestamp;
|
|
|
|
- private String apiContent;
|
|
|
|
private static final String signType = "CFCA";
|
|
private static final String signType = "CFCA";
|
|
- private String sign;
|
|
|
|
- private Map<String, Object> resultMap;
|
|
|
|
- private Map<String, Object> requestMap;
|
|
|
|
-
|
|
|
|
- public YqPayUtil(String notifyUrl, Map<String, Object> resultMap) throws Exception {
|
|
|
|
- Map<String, Object> rqMap = new LinkedHashMap<String, Object>();
|
|
|
|
- rqMap.put("merNo", this.merNo);
|
|
|
|
- rqMap.put("version", this.version);
|
|
|
|
|
|
+ private static final String payUrl = "https://qyfapi.95epay.com/api/api/hPay/toPayHtml";//支付提交地址
|
|
|
|
+ private static final String payChannels = "{\"weChatPay\":true,\"weChatPayMobile\":false,\"aliPay\":true,\"fastpayXy\":true,\"aliPayMobile\":false,\"balancePay\":false}";//支付方式配置
|
|
|
|
+
|
|
|
|
+ private static Map<String, Object> getRequestMap(String notifyUrl, Map<String, Object> resultMap) throws Exception {
|
|
|
|
+ Map<String, Object> rqMap = new LinkedHashMap<>();
|
|
|
|
+ rqMap.put("merNo", merNo);
|
|
|
|
+ rqMap.put("version", version);
|
|
rqMap.put("notifyUrl", notifyUrl);
|
|
rqMap.put("notifyUrl", notifyUrl);
|
|
rqMap.put("timestamp", DateUtils.getDateTime());
|
|
rqMap.put("timestamp", DateUtils.getDateTime());
|
|
rqMap.put("apiContent", JSON.toJSONString(resultMap));
|
|
rqMap.put("apiContent", JSON.toJSONString(resultMap));
|
|
rqMap.put("signType", signType);
|
|
rqMap.put("signType", signType);
|
|
String beforeSignedData = CFCARAUtil.joinMapValue(rqMap, '&');
|
|
String beforeSignedData = CFCARAUtil.joinMapValue(rqMap, '&');
|
|
- this.sign = CFCARAUtil.signMessageByP1(beforeSignedData, "config/certificate/yqpay.pfx","aaa123123");
|
|
|
|
- rqMap.put("sign", this.sign);
|
|
|
|
- this.requestMap = rqMap;
|
|
|
|
|
|
+ String sign = CFCARAUtil.signMessageByP1(beforeSignedData, "config/certificate/yqpay.pfx", "aaa123123");
|
|
|
|
+ rqMap.put("sign", sign);
|
|
|
|
+ return rqMap;
|
|
}
|
|
}
|
|
|
|
|
|
- public Map<String, Object> getRequestMap() {
|
|
|
|
- return this.requestMap;
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取支付Map
|
|
|
|
+ *
|
|
|
|
+ * @param amount
|
|
|
|
+ * @param orderNo
|
|
|
|
+ * @param notifyUrl
|
|
|
|
+ * @param returnUrl
|
|
|
|
+ * @param orderSubject
|
|
|
|
+ * @param orderBody
|
|
|
|
+ * @param routingMerNo
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public static Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String routingMerNo) throws Exception {
|
|
|
|
+ List<Map> tempRoutingList = new ArrayList();
|
|
|
|
+ Map<String, Object> routingList = new HashMap<>();
|
|
|
|
+ routingList.put("routingMerNo", routingMerNo);//分佣账户
|
|
|
|
+ routingList.put("routingFee", amount.subtract((amount.multiply(new BigDecimal(0.28)).divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_UP))); //分佣金额
|
|
|
|
+ tempRoutingList.add(routingList);
|
|
|
|
+
|
|
|
|
+ Map<String, Object> contentMap = new LinkedHashMap<>();
|
|
|
|
+ contentMap.put("sellerNo", merNo); //收款商户号
|
|
|
|
+ contentMap.put("payChannels", payChannels); //支付方式
|
|
|
|
+ contentMap.put("orderBody", orderBody); //订单信息
|
|
|
|
+ contentMap.put("payAmount", amount); //支付金额
|
|
|
|
+ contentMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
|
|
|
|
+ contentMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
|
|
|
|
+ contentMap.put("merMerOrderNo", orderNo); //商户订单号
|
|
|
|
+ contentMap.put("orderSubject", orderSubject); //订单标题
|
|
|
|
+ contentMap.put("returnUrl", returnUrl); //前台页面地址
|
|
|
|
+ if (routingMerNo != null && !routingMerNo.isEmpty()) {
|
|
|
|
+ contentMap.put("tempRoutingList", JSON.toJSONString(tempRoutingList));//分账设置
|
|
|
|
+ }
|
|
|
|
+ Map<String, Object> payMap = getRequestMap(notifyUrl, contentMap);
|
|
|
|
+ payMap.put("host", payUrl);
|
|
|
|
+ return payMap;
|
|
}
|
|
}
|
|
|
|
|
|
- //验签
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 验签
|
|
|
|
+ *
|
|
|
|
+ * @param rsMap
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
public static boolean verify(Map<String, Object> rsMap) {
|
|
public static boolean verify(Map<String, Object> rsMap) {
|
|
String sign = (String) rsMap.get("sign");
|
|
String sign = (String) rsMap.get("sign");
|
|
rsMap.remove("sign");
|
|
rsMap.remove("sign");
|
|
String beforeSignedData = CFCARAUtil.joinMapValue(rsMap, '&');
|
|
String beforeSignedData = CFCARAUtil.joinMapValue(rsMap, '&');
|
|
try {
|
|
try {
|
|
- return CFCARAUtil.verifyMessageByP1(beforeSignedData, sign, "certificate/sq_formal_sign.cer");
|
|
|
|
|
|
+ return CFCARAUtil.verifyMessageByP1(beforeSignedData, sign, "/config/certificate/sq_formal_sign.cer");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|