|
@@ -1,22 +1,20 @@
|
|
|
-package com.miaxis.app.controller.film;
|
|
|
+package com.miaxis.app.controller.wx;
|
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.miaxis.common.config.WxpayConfig;
|
|
|
import com.miaxis.common.constant.Constants;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.AesUtil;
|
|
|
-import com.miaxis.common.utils.uuid.CommonUtils;
|
|
|
import com.miaxis.feign.dto.FilmDTO;
|
|
|
import com.miaxis.feign.dto.FilmMcpData;
|
|
|
import com.miaxis.feign.dto.FilmXdResult;
|
|
|
-import com.miaxis.film.domain.FilmOrder;
|
|
|
-import com.miaxis.film.domain.RefundRecord;
|
|
|
-import com.miaxis.film.dto.*;
|
|
|
-import com.miaxis.film.service.IFilmOrderService;
|
|
|
-import com.miaxis.film.service.IRefundRecordService;
|
|
|
+import com.miaxis.wx.domain.RefundRecord;
|
|
|
+import com.miaxis.wx.domain.WxOrder;
|
|
|
+import com.miaxis.wx.dto.*;
|
|
|
+import com.miaxis.wx.service.IRefundRecordService;
|
|
|
+import com.miaxis.wx.service.IWxOrderService;
|
|
|
import com.wechat.pay.contrib.apache.httpclient.auth.AutoUpdateCertificatesVerifier;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -26,7 +24,6 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Base64Utils;
|
|
@@ -37,21 +34,19 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.BufferedReader;
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.*;
|
|
|
import java.security.cert.X509Certificate;
|
|
|
-import java.util.Base64;
|
|
|
|
|
|
import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
|
|
|
|
|
|
@RestController
|
|
|
@RequiredArgsConstructor
|
|
|
-@RequestMapping(Constants.OPEN_PREFIX+"/film/notify")
|
|
|
-@Api(tags = {"【小程序-回调】"})
|
|
|
+@RequestMapping(Constants.OPEN_PREFIX+"/wx/notify")
|
|
|
+@Api(tags = {"【小程序-微信回调】"})
|
|
|
@Slf4j
|
|
|
-public class NotifyController {
|
|
|
+public class WxNotifyController {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
@@ -59,7 +54,7 @@ public class NotifyController {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
- private IFilmOrderService filmOrderService;
|
|
|
+ private IWxOrderService wxOrderService;
|
|
|
|
|
|
@Autowired
|
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
@@ -82,7 +77,6 @@ public class NotifyController {
|
|
|
public WxNotifyReturnDTO wxpayNotify(@RequestBody FilmWxpayDTO filmWxpayDTO, HttpServletRequest request) throws GeneralSecurityException, IOException {
|
|
|
|
|
|
String bodyString = getBodyString(request);
|
|
|
- System.out.println(bodyString);
|
|
|
Boolean pass = validate(request,bodyString);
|
|
|
if (!pass){
|
|
|
throw new CustomException("签名失败");
|
|
@@ -162,7 +156,7 @@ public class NotifyController {
|
|
|
*/
|
|
|
@PostMapping(value = "/refund")
|
|
|
@ApiOperation("微信退款回调")
|
|
|
- public WxNotifyReturnDTO refundNotify(@RequestBody FilmWxpayDTO filmWxpayDTO, HttpServletRequest request) throws GeneralSecurityException, IOException {
|
|
|
+ public WxNotifyReturnDTO refundNotify(@RequestBody FilmWxpayDTO filmWxpayDTO) throws GeneralSecurityException, IOException {
|
|
|
String resourceString = getSourString(filmWxpayDTO);
|
|
|
log.info(resourceString);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(resourceString);
|
|
@@ -190,92 +184,37 @@ public class NotifyController {
|
|
|
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 电影回调接口
|
|
|
- */
|
|
|
- @PostMapping(value = "/filmOrder")
|
|
|
- @ApiOperation("电影订单回调")
|
|
|
- public FilmNotifyReturnDTO filmOrderNotify(FilmOrderNotifyDTO filmOrderNotifyDTO ,String sign, String appKey) {
|
|
|
- FilmOrder filmOrder = filmOrderService.getByOutTradeNo(filmOrderNotifyDTO.getThirdOrderId());
|
|
|
- //todo 检查sign
|
|
|
- String orderDataJson = filmOrder.getOrderDataJson();
|
|
|
- FilmOrderJsonData filmOrderJsonData = JSONObject.parseObject(orderDataJson, FilmOrderJsonData.class);
|
|
|
- FilmOrderNotifyDTO dbFilmOrderNotifyDTO= filmOrderJsonData.getFilmOrderNotifyDTO();
|
|
|
- if (dbFilmOrderNotifyDTO == null){
|
|
|
- dbFilmOrderNotifyDTO = filmOrderNotifyDTO;
|
|
|
- }else{
|
|
|
- dbFilmOrderNotifyDTO.setEventName(filmOrderNotifyDTO.getEventName());
|
|
|
- if (filmOrderNotifyDTO.getOrderPrice()!= null)
|
|
|
- dbFilmOrderNotifyDTO.setOrderPrice(filmOrderNotifyDTO.getOrderPrice());
|
|
|
- if (filmOrderNotifyDTO.getCloseCause()!= null)
|
|
|
- dbFilmOrderNotifyDTO.setCloseCause(filmOrderNotifyDTO.getCloseCause());
|
|
|
- if (filmOrderNotifyDTO.getRealSeat()!= null)
|
|
|
- dbFilmOrderNotifyDTO.setRealSeat(filmOrderNotifyDTO.getRealSeat());
|
|
|
- if (filmOrderNotifyDTO.getTicketCode()!= null)
|
|
|
- dbFilmOrderNotifyDTO.setTicketCode(filmOrderNotifyDTO.getTicketCode());
|
|
|
- if (filmOrderNotifyDTO.getTicketImage()!= null)
|
|
|
- dbFilmOrderNotifyDTO.setTicketImage(filmOrderNotifyDTO.getTicketImage());
|
|
|
- }
|
|
|
- filmOrderJsonData.setFilmOrderNotifyDTO(dbFilmOrderNotifyDTO);
|
|
|
- filmOrder.setOrderDataJson(JSONObject.toJSONString(filmOrderJsonData));
|
|
|
- //UserInfo student = SecurityUtils.getLoginUser().getStudent();
|
|
|
- //如果回调回来的订单关闭,则调用退款
|
|
|
- if ("ORDER_CLOSE".equals(filmOrderNotifyDTO.getEventName())){
|
|
|
- String refundCode = getOrderCode(null);
|
|
|
- filmOrder.setOutRefundNo(refundCode);
|
|
|
- threadPoolTaskExecutor.execute(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
-
|
|
|
- refundRecordService.refund(filmOrder,refundCode);
|
|
|
- } catch (Exception e) {
|
|
|
- log.info(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- filmOrderService.updateById(filmOrder);
|
|
|
-
|
|
|
- FilmNotifyReturnDTO filmNotifyReturnDTO = new FilmNotifyReturnDTO();
|
|
|
- filmNotifyReturnDTO.setCode("200");
|
|
|
- filmNotifyReturnDTO.setMessage("请求成功");
|
|
|
- filmNotifyReturnDTO.setSuccess(true);
|
|
|
- return filmNotifyReturnDTO;
|
|
|
- }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 电影下单测试
|
|
|
*/
|
|
|
- @PostMapping(value = "/filmOrder-test")
|
|
|
+ @PostMapping(value = "/wxOrder-test")
|
|
|
@ApiOperation("电影订单下单测试")
|
|
|
- public Response<String> filmOrderNotifytest(String outTradeNo) throws GeneralSecurityException, IOException {
|
|
|
+ public Response<String> wxOrderNotifytest(String outTradeNo) throws GeneralSecurityException, IOException {
|
|
|
String s = "";
|
|
|
- FilmOrder filmOrder1 = filmOrderService.getByOutTradeNo(outTradeNo);
|
|
|
+ WxOrder wxOrder1 = wxOrderService.getByOutTradeNo(outTradeNo);
|
|
|
FilmDTO filmDTO = new FilmDTO();
|
|
|
filmDTO.setUrl("api/order/create");
|
|
|
StringBuffer paramData = new StringBuffer();
|
|
|
- FilmOrderJsonData filmOrderJsonData = JSONObject.parseObject(filmOrder1.getOrderDataJson(), FilmOrderJsonData.class);
|
|
|
- FilmOrderCreateDTO filmOrder = filmOrderJsonData.getFilmOrderCreateDTO();
|
|
|
- paramData.append("showId="+filmOrder.getShowId()+"&");
|
|
|
- paramData.append("seat="+filmOrder.getSeat()+"&");
|
|
|
- if (filmOrder.getReservedPhone() != null){
|
|
|
- paramData.append("reservedPhone="+filmOrder.getReservedPhone()+"&");
|
|
|
+ WxOrderJsonData wxOrderJsonData = JSONObject.parseObject(wxOrder1.getOrderDataJson(), WxOrderJsonData.class);
|
|
|
+ WxOrderCreateDTO wxOrder = wxOrderJsonData.getWxOrderCreateDTO();
|
|
|
+ paramData.append("showId="+wxOrder.getShowId()+"&");
|
|
|
+ paramData.append("seat="+wxOrder.getSeat()+"&");
|
|
|
+ if (wxOrder.getReservedPhone() != null){
|
|
|
+ paramData.append("reservedPhone="+wxOrder.getReservedPhone()+"&");
|
|
|
}
|
|
|
- paramData.append("thirdOrderId="+filmOrder.getThirdOrderId()+"&");
|
|
|
+ paramData.append("thirdOrderId="+wxOrder.getThirdOrderId()+"&");
|
|
|
paramData.append("notifyUrl="+notifyUrl+"&");
|
|
|
- if (filmOrder.getSeatId() != null){
|
|
|
- paramData.append("seatId="+filmOrder.getSeatId()+"&");
|
|
|
+ if (wxOrder.getSeatId() != null){
|
|
|
+ paramData.append("seatId="+wxOrder.getSeatId()+"&");
|
|
|
}
|
|
|
- if (filmOrder.getSeatNo() != null){
|
|
|
- paramData.append("seatNo="+filmOrder.getSeatNo()+"&");
|
|
|
+ if (wxOrder.getSeatNo() != null){
|
|
|
+ paramData.append("seatNo="+wxOrder.getSeatNo()+"&");
|
|
|
}
|
|
|
- paramData.append("acceptChangeSeat="+filmOrder.getAcceptChangeSeat());
|
|
|
+ paramData.append("acceptChangeSeat="+wxOrder.getAcceptChangeSeat());
|
|
|
filmDTO.setParamData(paramData.toString());
|
|
|
- s = filmOrderService.excuteFilmApi(filmDTO);
|
|
|
+ s = wxOrderService.excuteFilmApi(filmDTO);
|
|
|
log.info("电影下单返回值:"+s);
|
|
|
return Response.success(s);
|
|
|
}
|
|
@@ -286,82 +225,82 @@ public class NotifyController {
|
|
|
@Transactional
|
|
|
public void writeNotifyDataToDb(JSONObject jsonObject) {
|
|
|
String outTradeNo = jsonObject.getString("out_trade_no");
|
|
|
- FilmOrder filmOrder = filmOrderService.getByOutTradeNo(outTradeNo);
|
|
|
- if (filmOrder == null) {
|
|
|
+ WxOrder wxOrder = wxOrderService.getByOutTradeNo(outTradeNo);
|
|
|
+ if (wxOrder == null) {
|
|
|
throw new CustomException("该订单不存在");
|
|
|
}
|
|
|
- filmOrder.setTransactionId(jsonObject.getString("transaction_id"));
|
|
|
+ wxOrder.setTransactionId(jsonObject.getString("transaction_id"));
|
|
|
JSONObject amount = jsonObject.getJSONObject("amount");
|
|
|
- filmOrder.setPayerTotal(amount.getInteger("payer_total"));
|
|
|
- filmOrder.setTotal(amount.getInteger("total"));
|
|
|
- filmOrder.setCurrency(amount.getString("currency"));
|
|
|
- filmOrder.setPayerCurrency(amount.getString("payer_currency"));
|
|
|
- filmOrder.setTradeState(jsonObject.getString("trade_state"));
|
|
|
- filmOrder.setBankType(jsonObject.getString("bank_type"));
|
|
|
+ wxOrder.setPayerTotal(amount.getInteger("payer_total"));
|
|
|
+ wxOrder.setTotal(amount.getInteger("total"));
|
|
|
+ wxOrder.setCurrency(amount.getString("currency"));
|
|
|
+ wxOrder.setPayerCurrency(amount.getString("payer_currency"));
|
|
|
+ wxOrder.setTradeState(jsonObject.getString("trade_state"));
|
|
|
+ wxOrder.setBankType(jsonObject.getString("bank_type"));
|
|
|
DateTime dateTime = new DateTime(jsonObject.getString("success_time"));
|
|
|
- filmOrder.setSuccessTime(dateTime.toDate());
|
|
|
- filmOrder.setTradeStateDesc(jsonObject.getString("trade_state_desc"));
|
|
|
- filmOrder.setTradeType(jsonObject.getString("trade_type"));
|
|
|
- filmOrder.setAttach(jsonObject.getString("attach"));
|
|
|
+ wxOrder.setSuccessTime(dateTime.toDate());
|
|
|
+ wxOrder.setTradeStateDesc(jsonObject.getString("trade_state_desc"));
|
|
|
+ wxOrder.setTradeType(jsonObject.getString("trade_type"));
|
|
|
+ wxOrder.setAttach(jsonObject.getString("attach"));
|
|
|
JSONObject sceneInfo = jsonObject.getJSONObject("scene_info");
|
|
|
if (sceneInfo != null){
|
|
|
- filmOrder.setDeviceId(sceneInfo.getString("device_id"));
|
|
|
+ wxOrder.setDeviceId(sceneInfo.getString("device_id"));
|
|
|
}
|
|
|
//如果订单还未下过电影票订单,则异步调用电影下单api
|
|
|
- String orderDataJson= filmOrder.getOrderDataJson();
|
|
|
- FilmOrderJsonData filmOrderJsonData = JSONObject.parseObject(orderDataJson, FilmOrderJsonData.class);
|
|
|
- if (filmOrderJsonData != null && filmOrderJsonData.getFilmOrderNotifyDTO() == null){
|
|
|
+ String orderDataJson= wxOrder.getOrderDataJson();
|
|
|
+ WxOrderJsonData wxOrderJsonData = JSONObject.parseObject(orderDataJson, WxOrderJsonData.class);
|
|
|
+ if (wxOrderJsonData != null && wxOrderJsonData.getWxOrderNotifyDTO() == null){
|
|
|
threadPoolTaskExecutor.execute(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- FilmOrderCreateDTO filmOrderCreateDTO = filmOrderJsonData.getFilmOrderCreateDTO();
|
|
|
+ WxOrderCreateDTO wxOrderCreateDTO = wxOrderJsonData.getWxOrderCreateDTO();
|
|
|
FilmDTO filmDTO = new FilmDTO();
|
|
|
- if (filmOrderCreateDTO.getTicketType() ==1){
|
|
|
+ if (wxOrderCreateDTO.getTicketType() ==1){
|
|
|
filmDTO.setUrl("api/order/create");
|
|
|
- }else if (filmOrderCreateDTO.getTicketType() ==2){
|
|
|
+ }else if (wxOrderCreateDTO.getTicketType() ==2){
|
|
|
filmDTO.setUrl("api/order/create-soon-order");
|
|
|
}
|
|
|
|
|
|
StringBuffer paramData = new StringBuffer();
|
|
|
- paramData.append("showId="+filmOrderCreateDTO.getShowId()+"&");
|
|
|
- paramData.append("seat="+filmOrderCreateDTO.getSeat()+"&");
|
|
|
- if (filmOrderCreateDTO.getReservedPhone() != null){
|
|
|
- paramData.append("reservedPhone="+filmOrderCreateDTO.getReservedPhone()+"&");
|
|
|
+ paramData.append("showId="+wxOrderCreateDTO.getShowId()+"&");
|
|
|
+ paramData.append("seat="+wxOrderCreateDTO.getSeat()+"&");
|
|
|
+ if (wxOrderCreateDTO.getReservedPhone() != null){
|
|
|
+ paramData.append("reservedPhone="+wxOrderCreateDTO.getReservedPhone()+"&");
|
|
|
}
|
|
|
- paramData.append("thirdOrderId="+filmOrderCreateDTO.getThirdOrderId()+"&");
|
|
|
+ paramData.append("thirdOrderId="+wxOrderCreateDTO.getThirdOrderId()+"&");
|
|
|
paramData.append("notifyUrl="+notifyUrl+"&");
|
|
|
- if (filmOrderCreateDTO.getSeatId() != null){
|
|
|
- paramData.append("seatId="+filmOrderCreateDTO.getSeatId()+"&");
|
|
|
+ if (wxOrderCreateDTO.getSeatId() != null){
|
|
|
+ paramData.append("seatId="+wxOrderCreateDTO.getSeatId()+"&");
|
|
|
}
|
|
|
- if (filmOrderCreateDTO.getSeatNo() != null){
|
|
|
- paramData.append("seatNo="+filmOrderCreateDTO.getSeatNo()+"&");
|
|
|
+ if (wxOrderCreateDTO.getSeatNo() != null){
|
|
|
+ paramData.append("seatNo="+wxOrderCreateDTO.getSeatNo()+"&");
|
|
|
}
|
|
|
- paramData.append("acceptChangeSeat="+filmOrderCreateDTO.getAcceptChangeSeat());
|
|
|
+ paramData.append("acceptChangeSeat="+wxOrderCreateDTO.getAcceptChangeSeat());
|
|
|
filmDTO.setParamData(paramData.toString());
|
|
|
|
|
|
- String s = filmOrderService.excuteFilmApi(filmDTO);
|
|
|
+ String s = wxOrderService.excuteFilmApi(filmDTO);
|
|
|
log.info("电影下单返回值:"+s);
|
|
|
FilmXdResult filmXdResult = JSONObject.parseObject(s, FilmXdResult.class);
|
|
|
//如果返回值不是200 ,则调用退款流程
|
|
|
if (filmXdResult.getCode()!=200){
|
|
|
String refundCode = getOrderCode(null);
|
|
|
- filmOrder.setOutRefundNo(refundCode);
|
|
|
+ wxOrder.setOutRefundNo(refundCode);
|
|
|
try {
|
|
|
- refundRecordService.refund(filmOrder,refundCode);
|
|
|
+ refundRecordService.refund(wxOrder,refundCode);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}else {
|
|
|
if (filmXdResult.getData()!= null){
|
|
|
FilmMcpData filmMcpData = filmXdResult.getData();
|
|
|
- filmOrderJsonData.setFilmMcpData(filmMcpData);
|
|
|
- filmOrder.setOrderDataJson(JSONObject.toJSONString(filmOrderJsonData));
|
|
|
+ wxOrderJsonData.setFilmMcpData(filmMcpData);
|
|
|
+ wxOrder.setOrderDataJson(JSONObject.toJSONString(wxOrderJsonData));
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- filmOrderService.updateById(filmOrder);
|
|
|
+ wxOrderService.updateById(wxOrder);
|
|
|
|
|
|
}
|
|
|
});
|