|
@@ -1,44 +1,97 @@
|
|
|
package com.miaxis.app.controller.film;
|
|
|
|
|
|
|
|
|
+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.film.domain.FilmOrder;
|
|
|
import com.miaxis.film.dto.FilmWxpayDTO;
|
|
|
+import com.miaxis.film.service.IFilmOrderService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
+import lombok.Data;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
import java.security.GeneralSecurityException;
|
|
|
+import java.sql.Date;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
+import java.util.Locale;
|
|
|
|
|
|
@RestController
|
|
|
@RequiredArgsConstructor
|
|
|
@RequestMapping(Constants.OPEN_PREFIX+"/film/notify")
|
|
|
@Api(tags = {"【小程序-回调】"})
|
|
|
+@Slf4j
|
|
|
public class NotifyController {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private WxpayConfig wxpayConfig;
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFilmOrderService filmOrderService;
|
|
|
+
|
|
|
/**
|
|
|
* 微信支付回调接口
|
|
|
*/
|
|
|
@PostMapping(value = "/wxpay")
|
|
|
@ApiOperation("微信支付回调")
|
|
|
- public Response<FilmOrder> wxpayNotify(@RequestBody FilmWxpayDTO filmWxpayDTO,HttpServletRequest request) throws GeneralSecurityException, IOException {
|
|
|
+ public WxNotifyReturnDTO wxpayNotify(@RequestBody FilmWxpayDTO filmWxpayDTO,HttpServletRequest request) throws GeneralSecurityException, IOException {
|
|
|
AesUtil aesUtil = new AesUtil(wxpayConfig.getV3key().getBytes());
|
|
|
FilmWxpayDTO.WxpaySource wxpaySource = filmWxpayDTO.getResource();
|
|
|
String resourceString = aesUtil.decryptToString(wxpaySource.getAssociated_data().getBytes(), wxpaySource.getNonce().getBytes(), wxpaySource.getCiphertext());
|
|
|
- System.out.println(resourceString);
|
|
|
- return Response.success();
|
|
|
+ log.info(resourceString);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(resourceString);
|
|
|
+ //将回调数据写入数据库
|
|
|
+ writeNotifyDataToDb(jsonObject);
|
|
|
+ WxNotifyReturnDTO wxNotifyReturnDTO = new WxNotifyReturnDTO();
|
|
|
+ wxNotifyReturnDTO.setCode("SUCCESS");
|
|
|
+ wxNotifyReturnDTO.setMessage("成功");
|
|
|
+ return wxNotifyReturnDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void writeNotifyDataToDb(JSONObject jsonObject) {
|
|
|
+ String outTradeNo = jsonObject.getString("out_trade_no");
|
|
|
+ FilmOrder filmOrder = filmOrderService.getByOutTradeNo(outTradeNo);
|
|
|
+ if (filmOrder == null) {
|
|
|
+ throw new CustomException("该订单不存在");
|
|
|
+ }
|
|
|
+ filmOrder.setTransactionId(jsonObject.getString("transaction_id"));
|
|
|
+ JSONObject amount = jsonObject.getJSONObject("amount");
|
|
|
+ filmOrder.setPayerTotal(jsonObject.getInteger("payer_total"));
|
|
|
+ filmOrder.setTotal(jsonObject.getInteger("total"));
|
|
|
+ filmOrder.setCurrency(jsonObject.getString("currency"));
|
|
|
+ filmOrder.setPayerCurrency(jsonObject.getString("payer_currency"));
|
|
|
+ filmOrder.setTradeState(jsonObject.getString("SUCCESS"));
|
|
|
+ filmOrder.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"));
|
|
|
+ JSONObject sceneInfo = jsonObject.getJSONObject("scene_info");
|
|
|
+ if (sceneInfo != null){
|
|
|
+ filmOrder.setDeviceId(jsonObject.getString("device_id"));
|
|
|
+ }
|
|
|
+ filmOrderService.updateById(filmOrder);
|
|
|
+
|
|
|
+ }
|
|
|
+ @Data
|
|
|
+ public class WxNotifyReturnDTO {
|
|
|
+ String code;
|
|
|
+ String message;
|
|
|
}
|
|
|
|
|
|
}
|