mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
支付占桩订单
This commit is contained in:
@@ -2,10 +2,13 @@ package com.jsowell.adapay.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||
import com.huifu.adapay.model.*;
|
||||
import com.jsowell.adapay.common.CreateAdaPaymentParam;
|
||||
import com.jsowell.adapay.common.DivMember;
|
||||
import com.jsowell.adapay.config.AbstractAdapayConfig;
|
||||
import com.jsowell.adapay.dto.SettleAccountDTO;
|
||||
@@ -17,10 +20,13 @@ import com.jsowell.adapay.vo.AdapayAccountBalanceVO;
|
||||
import com.jsowell.adapay.vo.AdapayCorpMemberVO;
|
||||
import com.jsowell.adapay.vo.AdapayMemberInfoVO;
|
||||
import com.jsowell.adapay.vo.AdapaySettleAccountVO;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
import com.jsowell.common.enums.DelFlagEnum;
|
||||
import com.jsowell.common.enums.adapay.AdapayStatusEnum;
|
||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||
import com.jsowell.common.enums.ykc.ScenarioEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.AdapayUtil;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
@@ -29,14 +35,17 @@ import com.jsowell.common.util.id.IdUtils;
|
||||
import com.jsowell.pile.domain.AdapayMemberAccount;
|
||||
import com.jsowell.pile.domain.ClearingBillInfo;
|
||||
import com.jsowell.pile.domain.ClearingWithdrawInfo;
|
||||
import com.jsowell.pile.dto.PayOrderDTO;
|
||||
import com.jsowell.pile.service.ClearingBillInfoService;
|
||||
import com.jsowell.pile.service.ClearingWithdrawInfoService;
|
||||
import com.jsowell.pile.service.IAdapayMemberAccountService;
|
||||
import com.jsowell.pile.service.IPileMerchantInfoService;
|
||||
import com.jsowell.wxpay.service.WxAppletRemoteService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cglib.beans.BeanMap;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -46,11 +55,15 @@ import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AdapayMemberService {
|
||||
public class AdapayService {
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Value("${adapay.jsowell.appId}")
|
||||
private String ADAPAY_APP_ID;
|
||||
@@ -70,6 +83,75 @@ public class AdapayMemberService {
|
||||
@Autowired
|
||||
private IPileMerchantInfoService pileMerchantInfoService;
|
||||
|
||||
@Autowired
|
||||
private WxAppletRemoteService wxAppletRemoteService;
|
||||
|
||||
/**
|
||||
* 获取支付参数
|
||||
*/
|
||||
public Map<String, Object> createPayment(PayOrderDTO dto) {
|
||||
log.info("===============使用汇付支付-获取支付参数");
|
||||
// 相同参数重复请求,返回同一个支付对象
|
||||
String redisKey = CacheConstants.ADAPAY_ORDER_PARAM + dto.getOrderCode();
|
||||
Map<String, Object> cacheObject = redisCache.getCacheObject(redisKey);
|
||||
if (cacheObject != null) {
|
||||
// 表示已经获取到支付参数了,后续再有支付请求就拒绝
|
||||
return cacheObject;
|
||||
}
|
||||
|
||||
// 获取支付配置
|
||||
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId());
|
||||
if (config == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
|
||||
}
|
||||
|
||||
// 获取openId
|
||||
String openId = wxAppletRemoteService.getOpenIdByCode(dto.getCode());
|
||||
if (StringUtils.isBlank(openId)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
||||
}
|
||||
|
||||
// 封装对象
|
||||
String amount = AdapayUtil.formatAmount(dto.getPayAmount()); // 用户支付金额
|
||||
String payMode = Constants.ADAPAY_PAY_MODE_DELAY; // 汇付延时分账
|
||||
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
|
||||
createAdaPaymentParam.setOrder_no(dto.getOrderCode());
|
||||
createAdaPaymentParam.setPay_amt(amount);
|
||||
createAdaPaymentParam.setApp_id(config.getAdapayAppId());
|
||||
createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求
|
||||
createAdaPaymentParam.setGoods_title(dto.getGoodsTitle());
|
||||
createAdaPaymentParam.setGoods_desc(dto.getGoodsDesc()); // 这个字段是微信支付凭证的商品名
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("type", ScenarioEnum.ORDER.getValue());
|
||||
map.put("orderCode", dto.getOrderCode());
|
||||
map.put("payMode", payMode);
|
||||
map.put("memberId", dto.getMemberId());
|
||||
createAdaPaymentParam.setDescription(JSON.toJSONString(map));
|
||||
// 异步通知地址,url为http/https路径,服务器POST回调,URL 上请勿附带参数
|
||||
createAdaPaymentParam.setNotify_url(ADAPAY_CALLBACK_URL);
|
||||
createAdaPaymentParam.setExpend(JSONObject.toJSONString(ImmutableMap.of("open_id", openId)));
|
||||
|
||||
// 延时分账
|
||||
createAdaPaymentParam.setPay_mode(payMode);
|
||||
try {
|
||||
log.info("创建汇付支付参数:{}", JSONObject.toJSONString(createAdaPaymentParam));
|
||||
Map<String, Object> response = Payment.create(BeanMap.create(createAdaPaymentParam), config.getWechatAppId());
|
||||
if (response != null && !response.isEmpty()) {
|
||||
JSONObject expend = JSONObject.parseObject(response.get("expend").toString());
|
||||
JSONObject pay_info = expend.getJSONObject("pay_info");
|
||||
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {});
|
||||
if (resultMap != null) {
|
||||
// 请求参数放入缓存,15分钟以内返回同一个支付参数
|
||||
redisCache.setCacheObject(redisKey, resultMap, 15, TimeUnit.MINUTES);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
} catch (BaseAdaPayException e) {
|
||||
log.error("汇付-获取支付对象发生异常", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建结算账户
|
||||
*
|
||||
Reference in New Issue
Block a user