|
|
@ -14,6 +14,7 @@ import com.shop.cereshop.business.pay.weixin.skd.WXPayUtil; |
|
|
|
import com.shop.cereshop.business.pay.weixin.skd.WXPayV3Util; |
|
|
|
import com.shop.cereshop.business.service.bwxpay.CereBusinessWxpayService; |
|
|
|
import com.shop.cereshop.commons.constant.WxPayEnum; |
|
|
|
import com.shop.cereshop.commons.domain.bwxpay.CereBusinessWxpay; |
|
|
|
import com.shop.cereshop.commons.exception.CoBusinessException; |
|
|
|
import com.shop.cereshop.commons.utils.RandomStringUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
@ -32,32 +33,32 @@ public class WxPayServiceImpl implements WxPayService { |
|
|
|
/** |
|
|
|
* 支付小程序appid |
|
|
|
*/ |
|
|
|
@Value("${weixin.appid}") |
|
|
|
private String appid; |
|
|
|
// @Value("${weixin.appid}") |
|
|
|
// private String appid; |
|
|
|
|
|
|
|
/** |
|
|
|
* 支付APP端的appid |
|
|
|
*/ |
|
|
|
@Value("${weixin.app_appid}") |
|
|
|
private String app_appid; |
|
|
|
// @Value("${weixin.app_appid}") |
|
|
|
// private String app_appid; |
|
|
|
|
|
|
|
/** |
|
|
|
* 支付小程序秘钥 |
|
|
|
*/ |
|
|
|
@Value("${weixin.secret}") |
|
|
|
private String secret; |
|
|
|
// @Value("${weixin.secret}") |
|
|
|
// private String secret; |
|
|
|
|
|
|
|
/** |
|
|
|
* 商户号 |
|
|
|
*/ |
|
|
|
@Value("${weixin.mchid}") |
|
|
|
private String mch_id; |
|
|
|
// @Value("${weixin.mchid}") |
|
|
|
// private String mch_id; |
|
|
|
|
|
|
|
/** |
|
|
|
* 证书路径 |
|
|
|
*/ |
|
|
|
@Value("${weixin.certurl}") |
|
|
|
private String cert_url; |
|
|
|
// @Value("${weixin.certurl}") |
|
|
|
// private String cert_url; |
|
|
|
|
|
|
|
/** |
|
|
|
* pc回调地址 |
|
|
@ -89,8 +90,8 @@ public class WxPayServiceImpl implements WxPayService { |
|
|
|
/** |
|
|
|
* 商户秘钥 |
|
|
|
*/ |
|
|
|
@Value("${weixin.key}") |
|
|
|
private String key; |
|
|
|
// @Value("${weixin.key}") |
|
|
|
// private String key; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WXPayV3Util wxPayV3Util; |
|
|
@ -102,20 +103,20 @@ public class WxPayServiceImpl implements WxPayService { |
|
|
|
public Map<String, String> refund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund, Long afterId) throws CoBusinessException, Exception { |
|
|
|
//APPV3版本的退款,以APPV3开头 |
|
|
|
if (outRefundNo.startsWith("APPV3")) { |
|
|
|
return refundWithV3(transactionId, outRefundNo, total, refund); |
|
|
|
return refundWithV3(project, transactionId, outRefundNo, total, refund); |
|
|
|
} else { |
|
|
|
return refundWithNormal(transactionId, outRefundNo, total, refund); |
|
|
|
return refundWithNormal(project, transactionId, outRefundNo, total, refund); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String, String> refundWithV3(String transactionId, String outRefundNo, |
|
|
|
private Map<String, String> refundWithV3(String project, String transactionId, String outRefundNo, |
|
|
|
BigDecimal total, BigDecimal refund) throws Exception { |
|
|
|
log.info(" orderRefund refundWithV3 {}, {}, {}, {}", transactionId, outRefundNo, |
|
|
|
total, refund); |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("transaction_id", transactionId); |
|
|
|
params.put("out_refund_no", outRefundNo); |
|
|
|
params.put("notify_url", appV3NotifyUrl); |
|
|
|
params.put("notify_url", appV3NotifyUrl + "/" + project); |
|
|
|
params.put("amount", new HashMap<String, Object>(){ |
|
|
|
{ |
|
|
|
put("refund", refund.multiply(new BigDecimal(100)).intValue()); |
|
|
@ -137,18 +138,19 @@ public class WxPayServiceImpl implements WxPayService { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String, String> refundWithNormal(String transactionId, String outRefundNo, |
|
|
|
private Map<String, String> refundWithNormal(String project, String transactionId, String outRefundNo, |
|
|
|
BigDecimal total, BigDecimal refund) throws Exception { |
|
|
|
CereBusinessWxpay businessWxpay = cereBusinessWxpayService.getByBusinessId(Long.valueOf(project)); |
|
|
|
//退款资金来源-可用余额退款 |
|
|
|
String refundAccount="REFUND_SOURCE_RECHARGE_FUNDS"; |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
if(outRefundNo.contains("APP")){ |
|
|
|
//APP微信退款 |
|
|
|
params.put("appid", app_appid); |
|
|
|
params.put("appid", businessWxpay.getAppAppId()); |
|
|
|
} else { |
|
|
|
params.put("appid", appid); |
|
|
|
params.put("appid", businessWxpay.getAppId()); |
|
|
|
} |
|
|
|
params.put("mch_id",mch_id); |
|
|
|
params.put("mch_id",businessWxpay.getMchId()); |
|
|
|
params.put("nonce_str", System.currentTimeMillis() / 1000 + ""); |
|
|
|
//商户订单号和微信订单号二选一 |
|
|
|
// params.put("out_trade_no", wxPayLog.getOutTradeNo()); |
|
|
@ -160,27 +162,28 @@ public class WxPayServiceImpl implements WxPayService { |
|
|
|
// 退款原因,若商户传入,会在下发给用户的退款消息中体现退款原因 |
|
|
|
params.put("refund_desc","退款"); |
|
|
|
//退款回调 |
|
|
|
params.put("notify_url", pc_refund_notify_url); |
|
|
|
params.put("notify_url", pc_refund_notify_url + "/" + project); |
|
|
|
//签名算法 |
|
|
|
String sign = WXPayUtil.generateSignature(params,key); |
|
|
|
String sign = WXPayUtil.generateSignature(params,businessWxpay.getMchKey()); |
|
|
|
params.put("sign", sign); |
|
|
|
String xml = PaymentKit.toXml(params); |
|
|
|
log.info(xml); |
|
|
|
String xmlStr = WXPayUtil.doRefund("https://api.mch.weixin.qq.com/secapi/pay/refund", xml, cert_url, mch_id); |
|
|
|
String xmlStr = WXPayUtil.doRefund("https://api.mch.weixin.qq.com/secapi/pay/refund", xml, businessWxpay.getCertUrl(), businessWxpay.getMchId()); |
|
|
|
log.info(xmlStr); |
|
|
|
//加入微信支付日志 |
|
|
|
return PaymentKit.xmlToMap(xmlStr); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getCollectionCode(String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException,Exception { |
|
|
|
public String getCollectionCode(Long businessId, String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException,Exception { |
|
|
|
CereBusinessWxpay businessWxpay = cereBusinessWxpayService.getByBusinessId(businessId); |
|
|
|
Map<String, String> reqParams = new HashMap<>(); |
|
|
|
//生成一个新的订单支付编号 |
|
|
|
String outTradeNo=orderFormid+"-"+ RandomStringUtil.getRandomCode(3,0); |
|
|
|
//微信分配的小程序ID |
|
|
|
reqParams.put("appid",appid); |
|
|
|
reqParams.put("appid",businessWxpay.getAppId()); |
|
|
|
//微信支付分配的商户号 |
|
|
|
reqParams.put("mch_id",mch_id); |
|
|
|
reqParams.put("mch_id",businessWxpay.getMchId()); |
|
|
|
//随机字符串 |
|
|
|
reqParams.put("nonce_str", System.currentTimeMillis() / 1000 + ""); |
|
|
|
//签名类型 |
|
|
@ -196,13 +199,13 @@ public class WxPayServiceImpl implements WxPayService { |
|
|
|
// reqParams.put("spbill_create_ip", "127.0.0.1"); |
|
|
|
reqParams.put("spbill_create_ip", ip); |
|
|
|
//支付回调地址 |
|
|
|
reqParams.put("notify_url", pc_notify_url); |
|
|
|
reqParams.put("notify_url", pc_notify_url + "/" + businessId); |
|
|
|
//交易类型 |
|
|
|
reqParams.put("trade_type", tradeType); |
|
|
|
//用户标识 |
|
|
|
// reqParams.put("openid", openid); |
|
|
|
//签名 |
|
|
|
String sign = WXPayUtil.generateSignature(reqParams,key); |
|
|
|
String sign = WXPayUtil.generateSignature(reqParams, businessWxpay.getMchKey()); |
|
|
|
reqParams.put("sign", sign); |
|
|
|
/* |
|
|
|
调用支付定义下单API,返回预付单信息 prepay_id |
|
|
@ -215,7 +218,12 @@ public class WxPayServiceImpl implements WxPayService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, String> orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { |
|
|
|
return null; |
|
|
|
public Map<String, String> orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { |
|
|
|
//APPV3版本的退款,以APPV3开头 |
|
|
|
if (outRefundNo.startsWith("APPV3")) { |
|
|
|
return refundWithV3(project, transactionId, outRefundNo, total, refund); |
|
|
|
} else { |
|
|
|
return refundWithNormal(project, transactionId, outRefundNo, total, refund); |
|
|
|
} |
|
|
|
} |
|
|
|
} |