update 汇付

This commit is contained in:
2023-05-13 17:09:11 +08:00
parent 162e6c1d3b
commit 65429a44f0
2 changed files with 105 additions and 8 deletions

View File

@@ -1,11 +1,16 @@
package com.jsowell.service;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment;
import com.jsowell.adapay.common.CreateAdaPaymentParam;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
@@ -81,10 +86,12 @@ import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.util.ArrayList;
@@ -190,6 +197,7 @@ public class OrderService {
// 微信支付
dto.setOrderBasicInfo(orderInfo);
Map<String, Object> weixinMap = wechatPayOrder(dto);
// Map<String, Object> weixinMap = adapayPayOrder(dto);
// 返回微信支付参数
resultMap.put("weixinMap", weixinMap);
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // 支付宝支付
@@ -218,6 +226,61 @@ public class OrderService {
payOrderSuccessCallback(callbackDTO);
}
/**
* 使用汇付支付
* @param dto
* @return
*/
private Map<String, Object> adapayPayOrder(PayOrderDTO dto) {
log.info("===============使用汇付支付");
// 相同参数重复请求,返回同一个支付对象
String redisKey = "ADAPAY_ORDER_PARAM:" + dto.getOrderCode();
Map<String, Object> cacheObject = redisCache.getCacheObject(redisKey);
if (cacheObject != null) {
return cacheObject;
}
OrderBasicInfo orderInfo = dto.getOrderBasicInfo();
if (orderInfo == null) {
// 订单为空重新查询
orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode());
}
// 获取openId
String openId = memberService.getOpenIdByCode(dto.getCode());
if (StringUtils.isBlank(openId)) {
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
}
// 封装对象
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
createAdaPaymentParam.setOrder_no(orderInfo.getOrderCode());
createAdaPaymentParam.setPay_amt(new DecimalFormat("#.00").format(dto.getPayAmount()));
createAdaPaymentParam.setApp_id("app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"); // todo 后面移动到配置文件中
createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求
createAdaPaymentParam.setGoods_title("充电费用1");
createAdaPaymentParam.setGoods_desc("充电费用2");
createAdaPaymentParam.setDescription("充电费用3");
createAdaPaymentParam.setExpend(JSONObject.toJSONString( ImmutableMap.of("open_id", openId)));
try {
log.info("创建汇付支付参数:{}", JSONObject.toJSONString(createAdaPaymentParam));
Map<String, Object> response = Payment.create(BeanMap.create(createAdaPaymentParam));
if (response != null && !response.isEmpty()) {
JSONObject jsonObject = JSONObject.parseObject(response.get("expend").toString());
JSONObject pay_info = jsonObject.getJSONObject("pay_info");
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {
});
if (resultMap != null) {
// 表示已经获取到支付参数了,后续再有支付请求就拒绝
redisCache.setCacheObject(redisKey, resultMap, 15, TimeUnit.MINUTES);
}
return resultMap;
}
} catch (BaseAdaPayException e) {
log.error("汇付-获取支付对象发生异常", e);
}
return null;
}
/**
* 微信支付订单逻辑 获取支付参数
* @param dto
@@ -225,6 +288,7 @@ public class OrderService {
* @throws Exception
*/
private Map<String, Object> wechatPayOrder(PayOrderDTO dto) throws Exception {
// 相同参数重复请求,返回同一个支付对象
String redisKey = "WECHAT_PAY_ORDER_PARAM:" + dto.getOrderCode();
Map<String, Object> cacheObject = redisCache.getCacheObject(redisKey);
if (cacheObject != null) {

View File

@@ -5,6 +5,7 @@ import com.google.common.collect.Maps;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment;
import com.jsowell.JsowellApplication;
import com.jsowell.adapay.common.CreateAdaPaymentParam;
import com.jsowell.adapay.service.AdapayService;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
@@ -13,12 +14,15 @@ import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.common.util.http.HttpUtils;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.DictUtils;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.common.util.id.SnUtils;
import com.jsowell.common.util.id.SnowflakeIdWorker;
import com.jsowell.common.util.ip.AddressUtils;
import com.jsowell.common.util.lianlian.LianLianUtils;
import com.jsowell.netty.command.ykc.IssueQRCodeCommand;
import com.jsowell.netty.command.ykc.ProofreadTimeCommand;
import com.jsowell.netty.handler.HeartbeatRequestHandler;
@@ -30,7 +34,15 @@ import com.jsowell.pile.domain.PileBillingDetail;
import com.jsowell.pile.domain.PileBillingTemplate;
import com.jsowell.pile.domain.PileStationInfo;
import com.jsowell.pile.domain.WxpayCallbackRecord;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.dto.BasicPileDTO;
import com.jsowell.pile.dto.BatchCreatePileDTO;
import com.jsowell.pile.dto.ImportBillingTemplateDTO;
import com.jsowell.pile.dto.LianLianGetTokenDTO;
import com.jsowell.pile.dto.QueryOrderDTO;
import com.jsowell.pile.dto.QueryPileDTO;
import com.jsowell.pile.dto.QueryStationDTO;
import com.jsowell.pile.dto.RefundableWxPayOrderData;
import com.jsowell.pile.dto.WeixinPayDTO;
import com.jsowell.pile.mapper.MemberBasicInfoMapper;
import com.jsowell.pile.mapper.PileBillingTemplateMapper;
import com.jsowell.pile.service.IOrderBasicInfoService;
@@ -49,7 +61,6 @@ import com.jsowell.service.MemberService;
import com.jsowell.service.OrderService;
import com.jsowell.service.PileRemoteService;
import com.jsowell.service.PileService;
import com.jsowell.thirdparty.domain.StationInfo;
import com.jsowell.thirdparty.service.LianLianService;
import com.jsowell.wxpay.common.WeChatPayParameter;
import com.jsowell.wxpay.dto.AppletTemplateMessageSendDTO;
@@ -62,6 +73,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StopWatch;
@@ -69,7 +81,13 @@ import org.springframework.util.StopWatch;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ActiveProfiles("dev")
@SpringBootTest(classes = JsowellApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@@ -168,15 +186,30 @@ public class SpringBootTestController {
Map<String, Object> paymentParams = Maps.newHashMap();
paymentParams.put("order_no", "fasdftawefawefawsdcaseg");
paymentParams.put("pay_amt", "0.05");
paymentParams.put("app_id", "api_test_a6ac1931-11d6-4d76-8e73-086f8219c9e7");
paymentParams.put("app_id", "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa");
paymentParams.put("pay_channel", "wx_lite");
paymentParams.put("goods_title", "Your goods_title");
paymentParams.put("goods_desc", "Your goods_desc");
paymentParams.put("description", "payment Discription");
Map<String, Object> expendMap = Maps.newHashMap();
expendMap.put("open_id", "o4REX5PYTXvwl_YXs_aGrVAqCh_c");
paymentParams.put("expend", expendMap);
// paymentParams.put("div_members", [{"amount":"0.05", "fee_flag":"Y", "member_id":"member_id_test"}]);
// 调用创建方法,获取 Payment对象_
// 封装对象
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
createAdaPaymentParam.setOrder_no("fasdftawefawefawsdcaseg123");
createAdaPaymentParam.setPay_amt("0.05");
createAdaPaymentParam.setApp_id("app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"); // todo 后面移动到配置文件中
createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求
createAdaPaymentParam.setGoods_title("充电费用1");
createAdaPaymentParam.setGoods_desc("充电费用2");
createAdaPaymentParam.setDescription("充电费用3");
createAdaPaymentParam.setExpend(JSONObject.toJSONString( ImmutableMap.of("open_id", "o4REX5PYTXvwl_YXs_aGrVAqCh_c")));
try {
Map<String, Object> response = Payment.create(paymentParams);
// Map<String, Object> response = Payment.create(paymentParams);
Map<String, Object> response = Payment.create(BeanMap.create(createAdaPaymentParam));
System.out.println(response);
} catch (BaseAdaPayException e) {
e.printStackTrace();