|
|
@ -0,0 +1,298 @@ |
|
|
|
package com.shop.cereshop.business.pay.hnapay.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.shop.cereshop.business.dao.order.CereOrderProductDAO; |
|
|
|
import com.shop.cereshop.business.dao.order.CereShopOrderDAO; |
|
|
|
import com.shop.cereshop.business.dao.shop.CereShopBankDAO; |
|
|
|
import com.shop.cereshop.business.page.business.Business; |
|
|
|
import com.shop.cereshop.business.page.shop.ShopBankDetail; |
|
|
|
import com.shop.cereshop.business.pay.hnapay.HnaPayService; |
|
|
|
import com.shop.cereshop.business.pay.xs.domain.XsCallBackRequestVo; |
|
|
|
import com.shop.cereshop.business.pay.xs.utils.CommonUtils; |
|
|
|
import com.shop.cereshop.business.service.business.CerePlatformBusinessService; |
|
|
|
import com.shop.cereshop.business.service.shop.CerePlatformShopService; |
|
|
|
import com.shop.cereshop.commons.config.HnaPayConfig; |
|
|
|
import com.shop.cereshop.commons.constant.WxPayEnum; |
|
|
|
import com.shop.cereshop.commons.domain.business.CerePlatformBusiness; |
|
|
|
import com.shop.cereshop.commons.domain.order.CereOrderParent; |
|
|
|
import com.shop.cereshop.commons.domain.order.CereOrderProduct; |
|
|
|
import com.shop.cereshop.commons.domain.order.CereShopOrder; |
|
|
|
import com.shop.cereshop.commons.domain.shop.CerePlatformShop; |
|
|
|
import com.shop.cereshop.commons.exception.CoBusinessException; |
|
|
|
import com.shop.cereshop.commons.request.hnapay.form.T002TransForm; |
|
|
|
import com.shop.cereshop.commons.request.hnapay.form.T005TransForm; |
|
|
|
import com.shop.cereshop.commons.request.hnapay.init.InitForm; |
|
|
|
import com.shop.cereshop.commons.utils.EmptyUtils; |
|
|
|
import com.shop.cereshop.commons.utils.hnapay.HttpUtils; |
|
|
|
import com.shop.cereshop.commons.utils.hnapay.JsonUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.Base64; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 描述: |
|
|
|
* |
|
|
|
* @author stevenhu |
|
|
|
* @version 2025/02/18 9:29 |
|
|
|
*/ |
|
|
|
@Service(value = "HnaPayService") |
|
|
|
@Slf4j |
|
|
|
public class HnaPayServiceImpl implements HnaPayService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CereShopOrderDAO cereShopOrderDAO; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CereOrderProductDAO cereOrderProductDAO; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CerePlatformBusinessService cerePlatformBusinessService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CerePlatformShopService cerePlatformShopService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CereShopBankDAO cereShopBankDAO; |
|
|
|
|
|
|
|
@Override |
|
|
|
public XsCallBackRequestVo parseCallBackRequestVo(String msg) throws Exception { |
|
|
|
//base64 decode |
|
|
|
String msgStr = new String(Base64.getDecoder().decode(msg)); |
|
|
|
|
|
|
|
//LinkedHashMap json字符串转map时保持字段顺序不变 |
|
|
|
JSONObject headContentMap = JSONObject.parseObject(msgStr); |
|
|
|
|
|
|
|
String resSign = headContentMap.getString("sign"); |
|
|
|
headContentMap.remove("sign"); |
|
|
|
|
|
|
|
//headContentMap 转为json字符串时保留字段值为null的字段 |
|
|
|
SerializerFeature[] serializerFeatures = new SerializerFeature[]{SerializerFeature.WriteMapNullValue}; |
|
|
|
String headContentJson = JSONObject.toJSONString(headContentMap,serializerFeatures); |
|
|
|
CommonUtils.verifySignature(headContentJson, resSign); |
|
|
|
|
|
|
|
JSONObject head = headContentMap.getJSONObject("head"); |
|
|
|
JSONObject content = headContentMap.getJSONObject("content"); |
|
|
|
|
|
|
|
String responseCode = content.getString("responseCode"); |
|
|
|
if(StrUtil.isNotBlank(responseCode) && StrUtil.isNotBlank(responseCode) && !StrUtil.equals(responseCode, "0") |
|
|
|
&& !StrUtil.equals(responseCode, "0000") && !StrUtil.equals(responseCode, "0001")){ |
|
|
|
String errorMsg = content.getString("responseDesc"); |
|
|
|
throw new CoBusinessException(responseCode, errorMsg); |
|
|
|
} |
|
|
|
XsCallBackRequestVo xsCallBackRequestVo = new XsCallBackRequestVo(); |
|
|
|
xsCallBackRequestVo.setHead(head); |
|
|
|
xsCallBackRequestVo.setContent(content); |
|
|
|
return xsCallBackRequestVo; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> createEntAccount(Long entId, String userName, String mobile, String certNo, String certValidate, String cardNo, String bankCode, String province, String city, String branch) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> uploadEntFile(String userId, String certFileType, String base64) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> modifyEntAccount(String userId, String certNo, String userName, String mobile, String certValidate) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> changeEntCard(String userId, String bindCardAgrNo, String mobile, String cardNo, String bankCode, String province, String city, String branch) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, String> refund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund, Long afterId) throws CoBusinessException, Exception { |
|
|
|
List<CereShopOrder> orderList = null; |
|
|
|
String cereOrderFormId = orderFormId; |
|
|
|
String[] split = orderFormId.split("-"); |
|
|
|
if(!EmptyUtils.isEmpty(split)) { |
|
|
|
cereOrderFormId = split[0]; |
|
|
|
} |
|
|
|
//查询是否为父订单编号 |
|
|
|
CereOrderParent parent = cereShopOrderDAO.findByParentFormid(cereOrderFormId); |
|
|
|
if (parent != null) { |
|
|
|
//查询所有子订单数据 |
|
|
|
orderList = cereShopOrderDAO.findByParentId(parent.getParentId()); |
|
|
|
|
|
|
|
} else { |
|
|
|
//子订单支付回调 |
|
|
|
orderList = cereShopOrderDAO.findByFormid(cereOrderFormId); |
|
|
|
} |
|
|
|
//这里理论上只会有一个子订单,如果出现多个说明出错了 |
|
|
|
if(orderList.size() != 1){ |
|
|
|
throw new CoBusinessException("10000","订单查找出错", ""); |
|
|
|
} |
|
|
|
|
|
|
|
List<CereOrderProduct> cereOrderProductList = cereOrderProductDAO.findByOrderIds(orderList.stream().map(CereShopOrder::getOrderId).collect(Collectors.toList())); |
|
|
|
log.info("cereOrderProductList:" + new Gson().toJson(cereOrderProductList)); |
|
|
|
|
|
|
|
List<Long> shopIdList = orderList.stream().map(CereShopOrder::getShopId).distinct().collect(Collectors.toList()); |
|
|
|
List<CerePlatformShop> cerePlatformShopList = cerePlatformShopService.getByIdList(shopIdList); |
|
|
|
List<Long> businessIdList = cerePlatformShopList.stream().map(CerePlatformShop::getBusinessId).distinct().collect(Collectors.toList()); |
|
|
|
List<CerePlatformBusiness> cerePlatformBusinessList = cerePlatformBusinessService.getByIdList(businessIdList); |
|
|
|
|
|
|
|
String resultStr = ""; |
|
|
|
T005TransForm transForm = new T005TransForm(); |
|
|
|
transForm.setTranCode("T005"); |
|
|
|
transForm.initCommonParams("T005"); |
|
|
|
transForm.setMerOrderId(outRefundNo); |
|
|
|
transForm.setSubmitUrl(InitForm.T005_SUBMIT_URL); |
|
|
|
transForm.setSerialId("thee" + System.currentTimeMillis()); |
|
|
|
transForm.setOrgMerOrderId(outTradeNo); |
|
|
|
//transForm.setOrgSubmitTime(orderInfo.getPaySubmitTime()); |
|
|
|
transForm.setOrderAmount(String.valueOf(total)); |
|
|
|
transForm.setRefundSource("1"); |
|
|
|
transForm.setDestType("1"); |
|
|
|
//退款类型 1:全额退款 2:部分退款 |
|
|
|
transForm.setRefundType("1"); |
|
|
|
transForm.setRefundAmount(String.valueOf(refund)); |
|
|
|
transForm.setNotifyUrl(HnaPayConfig.REFUND_NOTICE_URL); |
|
|
|
transForm.setRemark("退款备注信息"); |
|
|
|
//transForm.setDivideRefundDtl(""); |
|
|
|
try { |
|
|
|
resultStr = HttpUtils.commonReq(transForm, false); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String,Object> responseMap = JsonUtils.jsonToMap(resultStr); |
|
|
|
String resultCode = String.valueOf(responseMap.get("resultCode")); |
|
|
|
if (resultCode.equals("0000")){ |
|
|
|
//成功 |
|
|
|
Map<String, String> result = new HashMap<>(); |
|
|
|
result.put("return_msg", WxPayEnum.REFUND_SUCCESS.getCode()); |
|
|
|
result.put("return_code", WxPayEnum.REFUND_OK.getCode()); |
|
|
|
return result; |
|
|
|
}else { |
|
|
|
//失败 |
|
|
|
String errorMsg = String.valueOf(responseMap.get("errorMsg")); |
|
|
|
throw new CoBusinessException(errorMsg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//获取保证金 |
|
|
|
@Override |
|
|
|
public String getCollectionCode(String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, String> orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { |
|
|
|
List<CereShopOrder> orderList = null; |
|
|
|
String cereOrderFormId = orderFormId; |
|
|
|
String[] split = orderFormId.split("-"); |
|
|
|
if(!EmptyUtils.isEmpty(split)) { |
|
|
|
cereOrderFormId = split[0]; |
|
|
|
} |
|
|
|
//查询是否为父订单编号 |
|
|
|
CereOrderParent parent = cereShopOrderDAO.findByParentFormid(cereOrderFormId); |
|
|
|
if (parent != null) { |
|
|
|
//查询所有子订单数据 |
|
|
|
orderList = cereShopOrderDAO.findByParentId(parent.getParentId()); |
|
|
|
|
|
|
|
} else { |
|
|
|
//子订单支付回调 |
|
|
|
orderList = cereShopOrderDAO.findByFormid(cereOrderFormId); |
|
|
|
} |
|
|
|
//这里理论上只会有一个子订单,如果出现多个说明出错了 |
|
|
|
if(orderList.size() != 1){ |
|
|
|
throw new CoBusinessException("10000","订单查找出错", ""); |
|
|
|
} |
|
|
|
|
|
|
|
List<CereOrderProduct> cereOrderProductList = cereOrderProductDAO.findByOrderIds(orderList.stream().map(CereShopOrder::getOrderId).collect(Collectors.toList())); |
|
|
|
log.info("cereOrderProductList:" + new Gson().toJson(cereOrderProductList)); |
|
|
|
|
|
|
|
List<Long> shopIdList = orderList.stream().map(CereShopOrder::getShopId).distinct().collect(Collectors.toList()); |
|
|
|
List<CerePlatformShop> cerePlatformShopList = cerePlatformShopService.getByIdList(shopIdList); |
|
|
|
List<Long> businessIdList = cerePlatformShopList.stream().map(CerePlatformShop::getBusinessId).distinct().collect(Collectors.toList()); |
|
|
|
List<CerePlatformBusiness> cerePlatformBusinessList = cerePlatformBusinessService.getByIdList(businessIdList); |
|
|
|
|
|
|
|
String resultStr = ""; |
|
|
|
T005TransForm transForm = new T005TransForm(); |
|
|
|
transForm.setTranCode("T005"); |
|
|
|
transForm.initCommonParams("T005"); |
|
|
|
transForm.setMerOrderId(outRefundNo); |
|
|
|
transForm.setSubmitUrl(InitForm.T005_SUBMIT_URL); |
|
|
|
transForm.setSerialId("thee" + System.currentTimeMillis()); |
|
|
|
transForm.setOrgMerOrderId(outTradeNo); |
|
|
|
//transForm.setOrgSubmitTime(orderInfo.getPaySubmitTime()); |
|
|
|
transForm.setOrderAmount(String.valueOf(total)); |
|
|
|
transForm.setRefundSource("1"); |
|
|
|
transForm.setDestType("1"); |
|
|
|
//退款类型 1:全额退款 2:部分退款 |
|
|
|
transForm.setRefundType("1"); |
|
|
|
transForm.setRefundAmount(String.valueOf(refund)); |
|
|
|
transForm.setNotifyUrl(HnaPayConfig.REFUND_NOTICE_URL); |
|
|
|
transForm.setRemark("退款备注信息"); |
|
|
|
//transForm.setDivideRefundDtl(""); |
|
|
|
try { |
|
|
|
resultStr = HttpUtils.commonReq(transForm, false); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String,Object> responseMap = JsonUtils.jsonToMap(resultStr); |
|
|
|
String resultCode = String.valueOf(responseMap.get("resultCode")); |
|
|
|
if (resultCode.equals("0000")){ |
|
|
|
//成功 |
|
|
|
Map<String, String> result = new HashMap<>(); |
|
|
|
result.put("return_msg", WxPayEnum.REFUND_SUCCESS.getCode()); |
|
|
|
result.put("return_code", WxPayEnum.REFUND_OK.getCode()); |
|
|
|
return result; |
|
|
|
}else { |
|
|
|
//失败 |
|
|
|
String errorMsg = String.valueOf(responseMap.get("errorMsg")); |
|
|
|
throw new CoBusinessException(errorMsg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getMoney(Long businessId, String orderFormid, String tradeType, BigDecimal money) throws CoBusinessException { |
|
|
|
Business business = cerePlatformBusinessService.getById(businessId); |
|
|
|
ShopBankDetail shopBankDetail = cereShopBankDAO.getByShopId(businessId); |
|
|
|
if(shopBankDetail == null){ |
|
|
|
throw new CoBusinessException("10000","查找不到绑定的银行卡信息", ""); |
|
|
|
} |
|
|
|
String resultStr = ""; |
|
|
|
T002TransForm transForm = new T002TransForm(); |
|
|
|
transForm.setTranCode("T002"); |
|
|
|
transForm.initCommonParams("T002"); |
|
|
|
transForm.setSubmitUrl(InitForm.T002_SUBMIT_URL); |
|
|
|
transForm.setTranAmount(String.valueOf(money)); |
|
|
|
transForm.setUserId(business.getXsPayId()); |
|
|
|
transForm.setBindCardAgrNo(shopBankDetail.getCardNumber()); |
|
|
|
transForm.setNotifyUrl(HnaPayConfig.GETMONEY_NOTICE_URL); |
|
|
|
transForm.setPaymentTerminalInfo(HnaPayConfig.IP); |
|
|
|
transForm.setDeviceInfo(HnaPayConfig.IP); |
|
|
|
try { |
|
|
|
resultStr = HttpUtils.commonReq(transForm, false); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
Map<String,Object> responseMap = JsonUtils.jsonToMap(resultStr); |
|
|
|
String resultCode = String.valueOf(responseMap.get("resultCode")); |
|
|
|
if (resultCode.equals("0000")){ |
|
|
|
//成功 |
|
|
|
return "success"; |
|
|
|
}else { |
|
|
|
//失败 |
|
|
|
String errorMsg = String.valueOf(responseMap.get("errorMsg")); |
|
|
|
throw new CoBusinessException(errorMsg); |
|
|
|
} |
|
|
|
} |
|
|
|
} |