|
@@ -25,6 +25,7 @@ import com.ijpay.core.kit.WxPayKit;
|
|
|
import com.ijpay.wxpay.WxPayApi;
|
|
|
import com.ijpay.wxpay.model.ProfitSharingModel;
|
|
|
import com.ijpay.wxpay.model.ReceiverModel;
|
|
|
+import com.ijpay.wxpay.model.RefundModel;
|
|
|
import com.ijpay.wxpay.model.UnifiedOrderModel;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -34,6 +35,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -312,6 +314,71 @@ public class WxPayController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 微信退款
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/refund")
|
|
|
+ @ResponseBody
|
|
|
+ public MessageResult refund(String id){
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try{
|
|
|
+
|
|
|
+ ParkingPay parkingPay = parkingPayService.getById(id);
|
|
|
+
|
|
|
+
|
|
|
+ String totalFee = parkingPay.getPayAmount().multiply(new BigDecimal(100)).setScale(0).toString();
|
|
|
+ Map<String, String> params = RefundModel.builder()
|
|
|
+ .appid(wxPayProperties.getAppId())
|
|
|
+ .mch_id(wxPayProperties.getMchId())
|
|
|
+ .sub_mch_id(wxPayProperties.getSubMchId())
|
|
|
+ .nonce_str(WxPayKit.generateStr())
|
|
|
+ .transaction_id(parkingPay.getTransactionNo())
|
|
|
+ .out_trade_no(parkingPay.getOutOrderNo())
|
|
|
+ .out_refund_no(WxPayKit.generateStr())
|
|
|
+ .total_fee(totalFee)
|
|
|
+ .refund_fee(totalFee)
|
|
|
+ .notify_url(wxPayProperties.getRefundUrl())
|
|
|
+ .build()
|
|
|
+ .createSign(wxPayProperties.getMchKey(), SignType.HMACSHA256);
|
|
|
+ String result = WxPayApi.orderRefund(false, params, wxPayProperties.getCertPath(), wxPayProperties.getMchId());
|
|
|
+ Map<String, String> map = WxPayKit.xmlToMap(result);
|
|
|
+ String returnCode = map.get("return_code");
|
|
|
+ String resultCode = map.get("result_code");
|
|
|
+ if (WxPayKit.codeIsOk(returnCode) && WxPayKit.codeIsOk(resultCode)) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ return msgResult;
|
|
|
+ } else {
|
|
|
+ // 退款失败
|
|
|
+ throw new Exception("退款失败," + map.get("return_msg") + "," + map.get("err_code_des"));
|
|
|
+ }
|
|
|
+ }catch (Exception ex){
|
|
|
+ msgResult.setCode(400);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ msgResult.setResult(false);
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/wxJsapiRefundNotify", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
+ @ResponseBody
|
|
|
+ public MessageResult wxJsapiRefundNotify(HttpServletRequest request){
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ String xmlMsg = HttpKit.readData(request);
|
|
|
+ log.warn("微信退款回调:"+xmlMsg);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 添加分账接收方
|
|
|
*/
|
|
@@ -321,13 +388,20 @@ public class WxPayController {
|
|
|
|
|
|
ParkingMerchant parkingMerchant = parkingMerchantService.getById(merchantId);
|
|
|
|
|
|
- ReceiverModel receiver = ReceiverModel.builder()
|
|
|
+ /* ReceiverModel receiver = ReceiverModel.builder()
|
|
|
.type("MERCHANT_ID")
|
|
|
.account(wxPayProperties.getSubMchId())
|
|
|
.relation_type("SERVICE_PROVIDER")
|
|
|
+ .build();*/
|
|
|
+ ReceiverModel receiver = ReceiverModel.builder()
|
|
|
+ .type("PERSONAL_SUB_OPENID")
|
|
|
+ .account("oK9Wr59jOWutvzTctzx97oqpxnNI")
|
|
|
+ .relation_type("STAFF")
|
|
|
.build();
|
|
|
|
|
|
+
|
|
|
Map<String, String> params = ProfitSharingModel.builder()
|
|
|
+ .mch_id(wxPayProperties.getMchId())
|
|
|
.sub_mch_id(parkingMerchant.getSubMchId())
|
|
|
.appid(wxPayProperties.getAppId())
|
|
|
.sub_appid(wxPayProperties.getSubAppId())
|