|
|
@@ -10,6 +10,9 @@ import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
+import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
+import com.huifu.adapay.model.Payment;
|
|
|
+import com.izouma.nineth.config.AdapayProperties;
|
|
|
import com.izouma.nineth.config.AlipayProperties;
|
|
|
import com.izouma.nineth.config.WxPayProperties;
|
|
|
import com.izouma.nineth.domain.Asset;
|
|
|
@@ -19,12 +22,14 @@ import com.izouma.nineth.enums.AssetStatus;
|
|
|
import com.izouma.nineth.enums.OrderStatus;
|
|
|
import com.izouma.nineth.enums.PayMethod;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
-import com.izouma.nineth.repo.*;
|
|
|
+import com.izouma.nineth.repo.AssetRepo;
|
|
|
+import com.izouma.nineth.repo.GiftOrderRepo;
|
|
|
+import com.izouma.nineth.repo.UserRepo;
|
|
|
import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.codec.EncoderException;
|
|
|
import org.apache.commons.codec.net.URLCodec;
|
|
|
-import org.springframework.context.ApplicationContext;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -32,9 +37,13 @@ import org.springframework.ui.Model;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@@ -42,20 +51,15 @@ public class GiftOrderService {
|
|
|
|
|
|
private AssetRepo assetRepo;
|
|
|
private UserRepo userRepo;
|
|
|
- private NFTService nftService;
|
|
|
- private CollectionRepo collectionRepo;
|
|
|
- private ApplicationContext applicationContext;
|
|
|
- private OrderRepo orderRepo;
|
|
|
private SysConfigService sysConfigService;
|
|
|
private GiftOrderRepo giftOrderRepo;
|
|
|
- private TokenHistoryRepo tokenHistoryRepo;
|
|
|
private AlipayProperties alipayProperties;
|
|
|
private AlipayClient alipayClient;
|
|
|
private WxPayProperties wxPayProperties;
|
|
|
private WxPayService wxPayService;
|
|
|
private Environment env;
|
|
|
- private AssetMintService assetMintService;
|
|
|
private AssetService assetService;
|
|
|
+ private AdapayProperties adapayProperties;
|
|
|
|
|
|
@Transactional
|
|
|
public GiftOrder gift(Long userId, Long assetId, Long toUserId) {
|
|
|
@@ -173,6 +177,40 @@ public class GiftOrderService {
|
|
|
throw new BusinessException("不支持此付款方式");
|
|
|
}
|
|
|
|
|
|
+ public Object payAdapay(Long id, String payChannel, String openId) throws BaseAdaPayException {
|
|
|
+ GiftOrder order = giftOrderRepo.findById(id).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> paymentParams = new HashMap<>();
|
|
|
+ paymentParams.put("order_no", String.valueOf(new SnowflakeIdWorker(0, 0).nextId()));
|
|
|
+ paymentParams.put("pay_amt", order.getGasPrice().setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
|
+ paymentParams.put("app_id", adapayProperties.getAppId());
|
|
|
+ paymentParams.put("pay_channel", payChannel);
|
|
|
+ paymentParams.put("goods_title", "转赠GAS费");
|
|
|
+ paymentParams.put("time_expire", DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
|
|
|
+ .format(LocalDateTime.now().plusMinutes(5)));
|
|
|
+ paymentParams.put("notify_url", adapayProperties.getNotifyUrl() + "/giftOrder/" + order.getId());
|
|
|
+
|
|
|
+
|
|
|
+ if ("wx_pub".equals(payChannel) || "wx_lite".equals(payChannel)) {
|
|
|
+ if (StringUtils.isBlank(openId)) {
|
|
|
+ throw new BusinessException("缺少openId");
|
|
|
+ }
|
|
|
+ Map<String, Object> expend = new HashMap<>();
|
|
|
+ expend.put("open_id", openId);
|
|
|
+ expend.put("limit_pay", "1");
|
|
|
+ if ("wx_lite".equals(payChannel)) {
|
|
|
+ expend.put("wx_app_id", adapayProperties.getWxAppId());
|
|
|
+ }
|
|
|
+ paymentParams.put("expend", expend);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> response = Payment.create(paymentParams);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
@Scheduled(fixedRate = 60000)
|
|
|
public void batchCancel() {
|
|
|
List<GiftOrder> orders = giftOrderRepo.findByStatusAndCreatedAtBeforeAndDelFalse(OrderStatus.NOT_PAID,
|