|
|
@@ -2,6 +2,7 @@ package com.izouma.nineth.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.alipay.api.AlipayClient;
|
|
|
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
|
|
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
@@ -11,9 +12,11 @@ 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.AdapayCommon;
|
|
|
import com.huifu.adapay.model.Payment;
|
|
|
import com.izouma.nineth.config.AdapayProperties;
|
|
|
import com.izouma.nineth.config.AlipayProperties;
|
|
|
+import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.config.WxPayProperties;
|
|
|
import com.izouma.nineth.domain.Asset;
|
|
|
import com.izouma.nineth.domain.GiftOrder;
|
|
|
@@ -27,8 +30,10 @@ import com.izouma.nineth.repo.GiftOrderRepo;
|
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
|
import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.EncoderException;
|
|
|
import org.apache.commons.codec.net.URLCodec;
|
|
|
+import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
@@ -47,6 +52,7 @@ import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class GiftOrderService {
|
|
|
|
|
|
private AssetRepo assetRepo;
|
|
|
@@ -60,6 +66,7 @@ public class GiftOrderService {
|
|
|
private Environment env;
|
|
|
private AssetService assetService;
|
|
|
private AdapayProperties adapayProperties;
|
|
|
+ private GeneralProperties generalProperties;
|
|
|
|
|
|
@Transactional
|
|
|
public GiftOrder gift(Long userId, Long assetId, Long toUserId) {
|
|
|
@@ -184,7 +191,13 @@ public class GiftOrderService {
|
|
|
}
|
|
|
|
|
|
public Object payAdapay(Long id, String payChannel, String openId) throws BaseAdaPayException {
|
|
|
+ List<String> aliChannels = Arrays.asList("alipay", "alipay_qr", "alipay_wap");
|
|
|
+ List<String> wxChannels = Arrays.asList("wx_pub", "wx_lite");
|
|
|
+ if (!aliChannels.contains(payChannel) && !wxChannels.contains(payChannel)) {
|
|
|
+ throw new BusinessException("不支持此渠道");
|
|
|
+ }
|
|
|
GiftOrder order = giftOrderRepo.findById(id).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ User invitor = null;
|
|
|
if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
throw new BusinessException("订单状态错误");
|
|
|
}
|
|
|
@@ -194,27 +207,48 @@ public class GiftOrderService {
|
|
|
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("goods_title","转赠GAS费");
|
|
|
+ paymentParams.put("goods_desc", "转赠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)) {
|
|
|
+ Map<String, Object> expend = new HashMap<>();
|
|
|
+ paymentParams.put("expend", expend);
|
|
|
+ if ("wx_pub".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;
|
|
|
+ Map<String, Object> response;
|
|
|
+ if ("wx_lite".equals(payChannel)) {
|
|
|
+ paymentParams.put("adapay_func_code", "wxpay.createOrder");
|
|
|
+ paymentParams.put("callback_url", generalProperties.getHost() + "/9th/orders");
|
|
|
+ response = AdapayCommon.requestAdapayUits(paymentParams);
|
|
|
+ log.info("createOrderResponse {}", JSON.toJSONString(response, SerializerFeature.PrettyFormat));
|
|
|
+ } else {
|
|
|
+ response = Payment.create(paymentParams);
|
|
|
+ log.info("createOrderResponse {}", JSON.toJSONString(response, SerializerFeature.PrettyFormat));
|
|
|
+ AdapayService.checkSuccess(response);
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (payChannel) {
|
|
|
+ case "alipay_wap":
|
|
|
+ case "alipay":
|
|
|
+ return MapUtils.getString(MapUtils.getMap(response, "expend"), "pay_info");
|
|
|
+ case "alipay_qr":
|
|
|
+ return MapUtils.getString(MapUtils.getMap(response, "expend"), "qrcode_url");
|
|
|
+ case "wx_pub":
|
|
|
+ JSONObject payParams = JSON.parseObject(MapUtils.getString(MapUtils.getMap(response, "expend"), "pay_info"));
|
|
|
+ payParams.put("timestamp", payParams.get("timeStamp"));
|
|
|
+ payParams.remove("timeStamp");
|
|
|
+ return payParams;
|
|
|
+ default:
|
|
|
+ return MapUtils.getMap(response, "expend");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Scheduled(fixedRate = 60000)
|