|
|
@@ -1,5 +1,7 @@
|
|
|
package com.izouma.jiashanxia.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
|
|
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
|
|
@@ -7,14 +9,15 @@ import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import com.izouma.jiashanxia.domain.OrderInfo;
|
|
|
import com.izouma.jiashanxia.domain.User;
|
|
|
+import com.izouma.jiashanxia.domain.WxFee;
|
|
|
import com.izouma.jiashanxia.exception.BusinessException;
|
|
|
import com.izouma.jiashanxia.repo.OrderInfoRepo;
|
|
|
import com.izouma.jiashanxia.repo.UserRepo;
|
|
|
+import com.izouma.jiashanxia.repo.WxFeeRepo;
|
|
|
import com.izouma.jiashanxia.utils.JsonUtils;
|
|
|
import com.izouma.jiashanxia.utils.SnowflakeIdWorker;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -23,18 +26,14 @@ import java.util.Arrays;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
+@AllArgsConstructor
|
|
|
public class ConsumptionService {
|
|
|
- @Autowired
|
|
|
- private UserRepo userRepo;
|
|
|
- @Autowired
|
|
|
- private OrderInfoRepo orderInfoRepo;
|
|
|
- @Value("${wx.pay.notifyUrl}")
|
|
|
- private String wxNotifyUrl;
|
|
|
- @Autowired
|
|
|
- private Environment environment;
|
|
|
- @Autowired
|
|
|
- private WxPayService wxPayService;
|
|
|
-
|
|
|
+ private UserRepo userRepo;
|
|
|
+ private OrderInfoRepo orderInfoRepo;
|
|
|
+ private Environment environment;
|
|
|
+ private WxPayService wxPayService;
|
|
|
+ private WxFeeRepo wxFeeRepo;
|
|
|
+ private OrderInfoService orderInfoService;
|
|
|
|
|
|
/*
|
|
|
微信支付
|
|
|
@@ -54,17 +53,16 @@ public class ConsumptionService {
|
|
|
request.setTotalFee(1);
|
|
|
}
|
|
|
request.setOpenid(user.getOpenId());
|
|
|
- request.setNotifyUrl(wxNotifyUrl);
|
|
|
+ request.setNotifyUrl(environment.getProperty("wx.pay.notifyUrl"));
|
|
|
request.setSpbillCreateIp("180.102.110.170");
|
|
|
request.setTradeType(WxPayConstants.TradeType.JSAPI);
|
|
|
request.setSignType("MD5");
|
|
|
request.setAttach(new JsonUtils.Builder()
|
|
|
- .add("type", "member")
|
|
|
+ .add("type", "consumption")
|
|
|
.add("orderId", orderId)
|
|
|
.add("userId", userId)
|
|
|
.add("amount", orders.getPrice())
|
|
|
.build());
|
|
|
-
|
|
|
try {
|
|
|
return wxPayService.createOrder(request);
|
|
|
} catch (WxPayException e) {
|
|
|
@@ -73,5 +71,27 @@ public class ConsumptionService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ 回调
|
|
|
+ */
|
|
|
+ public void handleConsumptionNotify(WxPayOrderNotifyResult notifyResult) {
|
|
|
+ JSONObject attach = JSONObject.parseObject(notifyResult.getAttach());
|
|
|
+ Long orderId = attach.getLong("orderId");
|
|
|
+ Long userId = attach.getLong("userId");
|
|
|
+ String type = attach.getString("type");
|
|
|
+ BigDecimal amount = attach.getBigDecimal("amount");
|
|
|
+ String transactionId = notifyResult.getTransactionId();
|
|
|
+
|
|
|
+ wxFeeRepo.save(WxFee.builder()
|
|
|
+ .amount(amount)
|
|
|
+ .isRefund(false)
|
|
|
+ .transactionId(transactionId)
|
|
|
+ .type(type)
|
|
|
+ .userId(userId)
|
|
|
+ .orderId(orderId)
|
|
|
+ .build());
|
|
|
+ orderInfoService.completed(orderId, transactionId);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|