update huifu

This commit is contained in:
2023-05-16 16:24:26 +08:00
parent 87666032b2
commit eef6af1c6c
6 changed files with 150 additions and 35 deletions

View File

@@ -6,14 +6,12 @@ import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.ScenarioEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.pile.dto.GetPayModeDTO;
import com.jsowell.pile.dto.PayOrderDTO;
import com.jsowell.pile.dto.PaymentScenarioDTO;
import com.jsowell.pile.dto.WeixinPayDTO;
import com.jsowell.pile.vo.uniapp.PayModeVO;
import com.jsowell.service.MemberService;
@@ -71,15 +69,47 @@ public class PayController extends BaseController {
}
dto.setOpenId(openId);
// 充值余额 附加参数
PaymentScenarioDTO paymentScenarioDTO = new PaymentScenarioDTO();
paymentScenarioDTO.setType(ScenarioEnum.BALANCE.getValue());
paymentScenarioDTO.setMemberId(memberId);
dto.setAttach(JSONObject.toJSONString(paymentScenarioDTO));
dto.setDescription("会员充值余额");
Map<String, Object> weixinMap = orderService.weixinPayV3(dto);
Map<String, Object> weixinMap = memberService.rechargeBalance(dto);
response = new RestApiResponse<>(ImmutableMap.of("weixinMap", weixinMap));
} catch (Exception e) {
response = new RestApiResponse<>();
logger.error("会员充值余额 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_MEMBER_RECHARGE_BALANCE_ERROR);
}
return response;
}
/**
* 会员充值余额
* http://localhost:8080/uniapp/pay/rechargeBalance
* @param request
* @param dto
* @return
*/
@PostMapping("/rechargeBalance")
public RestApiResponse<?> rechargeBalance(HttpServletRequest request, @RequestBody WeixinPayDTO dto) {
logger.info("会员充值余额 param:{}", dto.toString());
RestApiResponse<?> response;
try {
if (StringUtils.isBlank(dto.getCode()) || StringUtils.isBlank(dto.getAmount())) {
return new RestApiResponse<>(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 鉴权
String memberId = getMemberIdByAuthorization(request);
if (StringUtils.isBlank(memberId)) {
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
}
dto.setMemberId(memberId);
String openId = memberService.getOpenIdByCode(dto.getCode());
if (StringUtils.isBlank(openId)) {
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
}
dto.setOpenId(openId);
// 充值余额 附加参数
Map<String, Object> weixinMap = memberService.rechargeBalanceWithAdapay(dto);
response = new RestApiResponse<>(ImmutableMap.of("weixinMap", weixinMap));
} catch (Exception e) {
logger.error("会员充值余额 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_MEMBER_RECHARGE_BALANCE_ERROR);
}
return response;
}

View File

@@ -1,7 +1,13 @@
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.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment;
import com.jsowell.adapay.common.CreateAdaPaymentParam;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.page.PageResponse;
@@ -9,7 +15,9 @@ import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.TitleTypeEnum;
import com.jsowell.common.enums.uniapp.BalanceChangesEnum;
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.JWTUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.id.IdUtils;
@@ -23,8 +31,10 @@ import com.jsowell.pile.dto.BindingCardDTO;
import com.jsowell.pile.dto.CreateInvoiceTitleDTO;
import com.jsowell.pile.dto.MemberRegisterAndLoginDTO;
import com.jsowell.pile.dto.MemberRegisterDTO;
import com.jsowell.pile.dto.PaymentScenarioDTO;
import com.jsowell.pile.dto.UniAppQueryMemberBalanceDTO;
import com.jsowell.pile.dto.WechatLoginDTO;
import com.jsowell.pile.dto.WeixinPayDTO;
import com.jsowell.pile.service.IMemberBasicInfoService;
import com.jsowell.pile.service.IMemberInvoiceTitleService;
import com.jsowell.pile.service.IMemberPlateNumberRelationService;
@@ -42,10 +52,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
@Service
@@ -76,6 +88,9 @@ public class MemberService {
@Autowired
private IMemberInvoiceTitleService memberInvoiceTitleService;
@Autowired
private OrderService orderService;
/**
* 校验短信验证码
* @param dto
@@ -381,4 +396,39 @@ public class MemberService {
int i = memberInvoiceTitleService.insertMemberInvoiceTitle(title);
log.info("新增{}条发票抬头", i);
}
public Map<String, Object> rechargeBalance(WeixinPayDTO dto) throws Exception {
PaymentScenarioDTO paymentScenarioDTO = new PaymentScenarioDTO();
paymentScenarioDTO.setType(ScenarioEnum.BALANCE.getValue());
paymentScenarioDTO.setMemberId(dto.getMemberId());
dto.setAttach(JSONObject.toJSONString(paymentScenarioDTO));
dto.setDescription("会员充值余额");
return orderService.weixinPayV3(dto);
}
public Map<String, Object> rechargeBalanceWithAdapay(WeixinPayDTO dto) throws Exception {
// 封装对象
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
createAdaPaymentParam.setOrder_no(IdUtils.fastSimpleUUID());
createAdaPaymentParam.setPay_amt(AdapayUtil.formatAmount(dto.getAmount()));
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", dto.getOpenId())));
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>>() {});
return resultMap;
}
} catch (BaseAdaPayException e) {
log.error("汇付-获取支付对象发生异常", e);
}
return null;
}
}

View File

@@ -29,6 +29,7 @@ import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.ScenarioEnum;
import com.jsowell.common.enums.ykc.StartTypeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.AdapayUtil;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.common.util.StringUtils;
@@ -92,7 +93,6 @@ 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;
@@ -291,7 +291,8 @@ public class OrderService {
// 封装对象
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
createAdaPaymentParam.setOrder_no(orderInfo.getOrderCode());
createAdaPaymentParam.setPay_amt(new DecimalFormat("#.00").format(dto.getPayAmount()));
// createAdaPaymentParam.setPay_amt(new DecimalFormat("#.00").format(dto.getPayAmount()));
createAdaPaymentParam.setPay_amt(AdapayUtil.formatAmount(dto.getPayAmount()));
createAdaPaymentParam.setApp_id("app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"); // todo 后面移动到配置文件中
createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求
createAdaPaymentParam.setGoods_title("充电费用1");

View File

@@ -37,7 +37,6 @@ import com.jsowell.pile.domain.WxpayCallbackRecord;
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;
@@ -228,29 +227,29 @@ public class SpringBootTestController {
System.out.println(pileAuthCard);
}
@Test
public void testLianLian(){
// 获取令牌
LianLianGetTokenDTO dto = new LianLianGetTokenDTO();
dto.setOperatorId("987654321");
dto.setOperatorSecret("1234567890abcdef");
String token = lianLianService.getToken(dto);
System.out.println("token:" + token);
LianLianPushStationInfoDTO dto1 = LianLianPushStationInfoDTO.builder()
.OperatorID("987654321")
.DataSecret("1234567890abcdef")
.DataSecretIV("1234567890abcdef")
.SigSecret("1234567890abcdef")
.token(token)
.stationId(2L)
.build();
lianLianService.pushStationInfo(dto1);
}
// @Test
// public void testLianLian(){
// // 获取令牌
// LianLianGetTokenDTO dto = new LianLianGetTokenDTO();
// dto.setOperatorId("987654321");
// dto.setOperatorSecret("1234567890abcdef");
// String token = lianLianService.getToken(dto);
// System.out.println("token:" + token);
//
//
// LianLianPushStationInfoDTO dto1 = LianLianPushStationInfoDTO.builder()
// .OperatorID("987654321")
// .DataSecret("1234567890abcdef")
// .DataSecretIV("1234567890abcdef")
// .SigSecret("1234567890abcdef")
// .token(token)
// .stationId(2L)
//
// .build();
// lianLianService.pushStationInfo(dto1);
//
//
// }
@Test

View File

@@ -94,6 +94,10 @@ public enum ReturnCodeEnum {
CODE_STATION_IS_NOT_OPEN("00100045", "该站点暂未营业"),
CODE_MEMBER_RECHARGE_BALANCE_ERROR("00100046", "会员充值余额失败"),
/* 个人桩 start */
CODE_PILE_HAS_BEEN_BINDING_ERROR("00400001", "此桩已被绑定,请联系管理员!"),
CODE_AUTHENTICATION_ERROR("00400002", "您的身份信息验证有误,请重试!"),
@@ -114,6 +118,8 @@ public enum ReturnCodeEnum {
CODE_GET_PERSONAL_PILE_CONNECTOR_INFO_ERROR("00400010", "获取个人桩枪口实时数据异常"),
/* 个人桩 end */
CODE_THIS_CARNO_HAS_BEEN_BINDING("00500001", "当前车牌号已经绑定,请检查!"),
CODE_USER_BINDING_CARNO_ERROR("00500002", "用户绑定车牌号异常"),

View File

@@ -0,0 +1,29 @@
package com.jsowell.common.util;
import java.math.BigDecimal;
import java.text.DecimalFormat;
public class AdapayUtil {
public static void main(String[] args) {
String amount = "1110.5309";
String s = formatAmount(amount);
System.out.println(s);
BigDecimal bigDecimal = new BigDecimal(amount);
String s2 = formatAmount(bigDecimal);
System.out.println(s2);
}
// 格式化数字 保留两位小数不足补0
public static String formatAmount(String amount) {
//保留2位小数
double score = new BigDecimal(amount).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//不足两位则补0
DecimalFormat decimalFormat = new DecimalFormat("0.00#");
return decimalFormat.format(score);
}
public static String formatAmount(BigDecimal amount) {
return formatAmount(amount.toString());
}
}