|
|
@ -10,19 +10,33 @@ import com.github.pagehelper.PageInfo; |
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
|
|
|
|
import com.hai.common.pay.util.XmlUtil; |
|
|
|
|
|
|
|
import com.hai.common.pay.util.sdk.WXPayConstants; |
|
|
|
import com.hai.common.security.UserCenter; |
|
|
|
import com.hai.common.security.UserCenter; |
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
import com.hai.common.utils.IDGenerator; |
|
|
|
import com.hai.common.utils.IDGenerator; |
|
|
|
import com.hai.common.utils.ResponseMsgUtil; |
|
|
|
import com.hai.common.utils.ResponseMsgUtil; |
|
|
|
|
|
|
|
import com.hai.common.utils.WxUtils; |
|
|
|
import com.hai.entity.OutRechargeOrder; |
|
|
|
import com.hai.entity.OutRechargeOrder; |
|
|
|
|
|
|
|
<<<<<<< HEAD |
|
|
|
import com.hai.model.HighOrderModel; |
|
|
|
import com.hai.model.HighOrderModel; |
|
|
|
import com.hai.model.OutRechargeOrderModel; |
|
|
|
import com.hai.model.OutRechargeOrderModel; |
|
|
|
|
|
|
|
======= |
|
|
|
|
|
|
|
import com.hai.model.OrderRefundModel; |
|
|
|
|
|
|
|
>>>>>>> 4d1958377a2ed60952b3280c17eec28e48b6b0c6 |
|
|
|
import com.hai.model.ResponseData; |
|
|
|
import com.hai.model.ResponseData; |
|
|
|
import com.hai.service.OutRechargeOrderService; |
|
|
|
import com.hai.service.OutRechargeOrderService; |
|
|
|
import com.hai.service.TelApiService; |
|
|
|
import com.hai.service.TelApiService; |
|
|
|
|
|
|
|
import com.hai.service.pay.impl.GoodsOrderServiceImpl; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
import org.apache.http.HttpEntity; |
|
|
|
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
|
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
|
|
|
|
import org.apache.http.entity.StringEntity; |
|
|
|
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
|
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -31,6 +45,7 @@ import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -42,14 +57,12 @@ import java.util.Map; |
|
|
|
public class OutRechargeOrderController { |
|
|
|
public class OutRechargeOrderController { |
|
|
|
private static Logger log = LoggerFactory.getLogger(HighMerchantStoreController.class); |
|
|
|
private static Logger log = LoggerFactory.getLogger(HighMerchantStoreController.class); |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private UserCenter userCenter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private OutRechargeOrderService outRechargeOrderService; |
|
|
|
private OutRechargeOrderService outRechargeOrderService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private TelApiService telApiService; |
|
|
|
private GoodsOrderServiceImpl goodsOrderService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getOrderById", method = RequestMethod.GET) |
|
|
|
@RequestMapping(value = "/getOrderById", method = RequestMethod.GET) |
|
|
@ -126,7 +139,6 @@ public class OutRechargeOrderController { |
|
|
|
HttpServletRequest request) { |
|
|
|
HttpServletRequest request) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String,String> map = new HashMap<>(); |
|
|
|
Map<String,String> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
if (status != null) { |
|
|
|
if (status != null) { |
|
|
@ -170,6 +182,7 @@ public class OutRechargeOrderController { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/exportOrderList", method = RequestMethod.GET) |
|
|
|
@RequestMapping(value = "/exportOrderList", method = RequestMethod.GET) |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
@ -189,4 +202,87 @@ public class OutRechargeOrderController { |
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
======= |
|
|
|
|
|
|
|
@RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) |
|
|
|
|
|
|
|
@ResponseBody |
|
|
|
|
|
|
|
@ApiOperation(value = "订单退款") |
|
|
|
|
|
|
|
public ResponseData orderToRefund(@RequestParam(name = "orderId", required = false) Long orderId, |
|
|
|
|
|
|
|
HttpServletRequest request) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); |
|
|
|
|
|
|
|
if (order == null) { |
|
|
|
|
|
|
|
log.error("orderToPay error!", "未找到充值订单"); |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到充值订单"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款
|
|
|
|
|
|
|
|
if (order.getStatus() != 2) { |
|
|
|
|
|
|
|
log.error("orderToPay error!", "无法退款,订单不处于已支付状态"); |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String,String> param = new HashMap<>(); |
|
|
|
|
|
|
|
param.put("appid", "wx637bd6f7314daa46"); |
|
|
|
|
|
|
|
param.put("mch_id", "1289663601"); |
|
|
|
|
|
|
|
param.put("sub_mch_id" , "1609882817"); |
|
|
|
|
|
|
|
param.put("nonce_str", WxUtils.makeNonStr()); |
|
|
|
|
|
|
|
param.put("transaction_id", order.getPaySerialNo()); |
|
|
|
|
|
|
|
param.put("out_refund_no", "HFR"+new Date().getTime()); |
|
|
|
|
|
|
|
param.put("total_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); |
|
|
|
|
|
|
|
param.put("refund_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); |
|
|
|
|
|
|
|
param.put("sign_type", "HMAC-SHA256"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); |
|
|
|
|
|
|
|
param.put("sign", signStr); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String resultXmL = doRefundRequest(param.get("mch_id"), null, WxUtils.mapToXml(param)); |
|
|
|
|
|
|
|
OrderRefundModel orderRefundModel = XmlUtil.getObjectFromXML(resultXmL, OrderRefundModel.class); |
|
|
|
|
|
|
|
if(orderRefundModel.getResult_code().equals("SUCCESS")) { |
|
|
|
|
|
|
|
order.setStatus(5); |
|
|
|
|
|
|
|
order.setRefundTime(new Date()); |
|
|
|
|
|
|
|
order.setOutRefundNo(orderRefundModel.getOut_refund_no()); |
|
|
|
|
|
|
|
order.setRefundId(orderRefundModel.getRefund_id()); |
|
|
|
|
|
|
|
order.setRefundFee(new BigDecimal(orderRefundModel.getRefund_fee()).divide(new BigDecimal("100"))); |
|
|
|
|
|
|
|
outRechargeOrderService.updateOrder(order); |
|
|
|
|
|
|
|
return ResponseMsgUtil.success("退款成功"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ResponseMsgUtil.success("退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("HighOrderController --> getUserOrderList() error!", e); |
|
|
|
|
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String doRefundRequest(String mchId, String url, String data) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//小程序退款需要调用双向证书的认证
|
|
|
|
|
|
|
|
CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund"); // 设置响应头信息
|
|
|
|
|
|
|
|
httpost.addHeader("Connection", "keep-alive"); |
|
|
|
|
|
|
|
httpost.addHeader("Accept", "*/*"); |
|
|
|
|
|
|
|
httpost.addHeader("Content-Type", "text/xml"); |
|
|
|
|
|
|
|
httpost.addHeader("Host", "api.mch.weixin.qq.com"); |
|
|
|
|
|
|
|
httpost.addHeader("X-Requested-With", "XMLHttpRequest"); |
|
|
|
|
|
|
|
httpost.addHeader("Cache-Control", "max-age=0"); |
|
|
|
|
|
|
|
httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); |
|
|
|
|
|
|
|
httpost.setEntity(new StringEntity(data, "UTF-8")); |
|
|
|
|
|
|
|
CloseableHttpResponse response = httpClient.execute(httpost); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
|
|
|
|
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); |
|
|
|
|
|
|
|
EntityUtils.consume(entity); |
|
|
|
|
|
|
|
return jsonStr; |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
response.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e){ |
|
|
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
httpClient.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
>>>>>>> 4d1958377a2ed60952b3280c17eec28e48b6b0c6 |
|
|
|
} |
|
|
|
} |
|
|
|