...
|
...
|
@@ -6,11 +6,15 @@ import com.google.common.base.Splitter; |
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.OrderInfo;
|
|
|
import com.yohobuy.ufo.model.order.common.Payment;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.common.utils.HttpClient;
|
|
|
import com.yohoufo.common.utils.MD5Utils;
|
|
|
import com.yohoufo.common.utils.RSAUtils;
|
|
|
import com.yohoufo.common.utils.WXUtil;
|
|
|
import com.yohoufo.dal.order.OrdersPayHbfqMapper;
|
|
|
import com.yohoufo.dal.order.model.OrdersPayHbfq;
|
|
|
import com.yohoufo.order.common.HbfqEnum;
|
|
|
import com.yohoufo.order.config.AlipayConfig;
|
|
|
import com.yohoufo.order.constants.RefundContant;
|
|
|
import com.yohoufo.order.model.*;
|
...
|
...
|
@@ -59,6 +63,10 @@ public abstract class AlipayServiceAbstract extends AbstractPayService { |
|
|
}
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private OrdersPayHbfqMapper ordersPayHbfqDao;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${alipay.notifyurl}")
|
|
|
private String notifyURL;
|
...
|
...
|
@@ -124,7 +132,8 @@ public abstract class AlipayServiceAbstract extends AbstractPayService { |
|
|
public JSONObject prepayRequest(OrderInfo orderInfo) {
|
|
|
|
|
|
String orderCode = String.valueOf(orderInfo.getOrderCode());
|
|
|
Map<String, String> queryParams = buildOpenApiPayParams(orderCode, orderInfo.getAmount(), orderInfo.getPayExpireTime());
|
|
|
Map<String, String> queryParams = buildOpenApiPayParams(orderCode, orderInfo.getAmount(),
|
|
|
orderInfo.getPayExpireTime(),orderInfo.getPayment(), orderInfo.getHbfqNums(), orderInfo.getUid());
|
|
|
StringBuilder res = new StringBuilder();
|
|
|
for (String key : queryParams.keySet()){
|
|
|
res.append(key);
|
...
|
...
|
@@ -414,7 +423,8 @@ public abstract class AlipayServiceAbstract extends AbstractPayService { |
|
|
* @param payExpireTime
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<String, String> buildOpenApiPayParams(String tradeNo, BigDecimal amount, int payExpireTime) {
|
|
|
private Map<String, String> buildOpenApiPayParams(String tradeNo, BigDecimal amount, int payExpireTime,
|
|
|
int payment, int hbfqNums, int uid) {
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
params.put("app_id", getAppId());
|
|
|
params.put("method", "alipay.trade.app.pay");
|
...
|
...
|
@@ -424,6 +434,27 @@ public abstract class AlipayServiceAbstract extends AbstractPayService { |
|
|
params.put("version", "1.0");
|
|
|
params.put("notify_url", notifyURL);
|
|
|
|
|
|
if (Payment.isHB(payment)){
|
|
|
params.put("specified_channel", "pcredit"); // 花呗单渠道
|
|
|
|
|
|
}else if(Payment.isHBFQ(payment)){
|
|
|
|
|
|
params.put("specified_channel", "pcreditpayInstallment"); // 花呗分期
|
|
|
|
|
|
HbfqEnum hbfqEnum = HbfqEnum.getByfqTerms(hbfqNums);
|
|
|
if(hbfqEnum == null) {
|
|
|
logger.warn("fqNums from req invalid, fqNums: {}, orderCode: {}", hbfqNums, tradeNo);
|
|
|
throw new ServiceException(ServiceError.ORDER_FQNUM_INVALID);
|
|
|
}
|
|
|
|
|
|
String outTradeNo = tradeNo + hbfqEnum.getTradeNoPostfix();
|
|
|
params.put("out_trade_no", outTradeNo);
|
|
|
params.put("extend_params", getHbfqParam(hbfqEnum.getFqTerms()).toJSONString());
|
|
|
|
|
|
// 记录分期
|
|
|
recordOrdersPayHbfq(outTradeNo, tradeNo, uid);
|
|
|
}
|
|
|
|
|
|
|
|
|
JSONObject bizJson = new JSONObject(true);
|
|
|
bizJson.put("timeout_express", payExpireTime+"m"); //该订单允许的最晚付款时间
|
...
|
...
|
@@ -451,6 +482,37 @@ public abstract class AlipayServiceAbstract extends AbstractPayService { |
|
|
|
|
|
|
|
|
/**
|
|
|
* 花呗分期payOrderCode记录
|
|
|
* @param hbfqRecord
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean recordOrdersPayHbfq(String outTradeNo, String tradeNo, int uid) {
|
|
|
logger.info("recordOrdersPayHbfq outTradeNo: {}, tradeNo: {}, uid: {}", outTradeNo, tradeNo, uid);
|
|
|
|
|
|
OrdersPayHbfq record = new OrdersPayHbfq();
|
|
|
record.setFqTradeNo(outTradeNo);
|
|
|
record.setPayOrderCode(tradeNo);
|
|
|
record.setUid(uid);
|
|
|
try {
|
|
|
|
|
|
ordersPayHbfqDao.insertOnDuplicateUpdate(record);
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
|
logger.warn("recordOrdersPayHbfq failed, req: {}, ex: ", record, e);
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
private JSONObject getHbfqParam(int fqNums) {
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("hb_fq_num", String.valueOf(fqNums));
|
|
|
json.put("hb_fq_seller_percent", "0"); //用户承担手续费
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取openapi支付宝待签名字符串
|
|
|
* @param paramsMap
|
|
|
* @return
|
...
|
...
|
@@ -475,12 +537,17 @@ public abstract class AlipayServiceAbstract extends AbstractPayService { |
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PaymentData getPaymentData(Map<String, String> params) {
|
|
|
PaymentData payData = new PaymentData();
|
|
|
try {
|
|
|
String outTradeNo = params.get("out_trade_no");
|
|
|
|
|
|
// 花呗分期,获取订单号
|
|
|
OrdersPayHbfq hbfqRecord = ordersPayHbfqDao.selectByPrimaryKey(outTradeNo);
|
|
|
if(hbfqRecord != null) {
|
|
|
outTradeNo = hbfqRecord.getPayOrderCode();
|
|
|
}
|
|
|
|
|
|
payData.setOrderCode(outTradeNo);
|
|
|
payData.setTotalFee(Double.parseDouble(params.get("total_fee") != null ? params.get("total_fee") : params.get("total_amount")));
|
|
|
payData.setBankCode("");
|
...
|
...
|
|