|
|
@@ -1,515 +0,0 @@
|
|
|
-package com.xingxi.unifiedpay.service;
|
|
|
-
|
|
|
-import com.xingxi.unifiedpay.bean.*;
|
|
|
-import com.xingxi.unifiedpay.configuration.XingxiUnifiedpayProperties;
|
|
|
-import com.xingxi.unifiedpay.domain.XingxiUnifiedPaymentInfoDTO;
|
|
|
-import com.xingxi.unifiedpay.domain.XingxiUnifiedpayCallbackResultDTO;
|
|
|
-import com.xingxi.unifiedpay.domain.MercUnifiedpayDTO;
|
|
|
-import com.xingxi.unifiedpay.open.XingxiUnifiedpayCallbackServiceI;
|
|
|
-import com.github.binarywang.wxpay.bean.ecommerce.*;
|
|
|
-import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum;
|
|
|
-import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
-import com.github.binarywang.wxpay.service.EcommerceService;
|
|
|
-import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.util.StreamUtils;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.nio.charset.Charset;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-@Slf4j
|
|
|
-@XingxiUnifiedpay(name = "EcommerceWXPay", dependsOn = {"wxPayService"})
|
|
|
-@RequiredArgsConstructor
|
|
|
-class EcommerceWXPayUnifiedpayServiceImpl implements UnifiedpayServiceI {
|
|
|
- private final XingxiUnifiedpayCallbackServiceI biandanUnifiedpayCallbackServiceI;
|
|
|
- private final XingxiUnifiedpayProperties biandanUnifiedpayProperties;
|
|
|
- private final WxPayService wxPayService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayOrderResponse unifiedpay(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayOrderRequest request) throws Exception {
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
-
|
|
|
- PartnerTransactionsRequest partnerTransactionsRequest = requestToPartnerTransactionsRequest(mercUnifiedpayDTO, request);
|
|
|
- TransactionsResult transactionsResult = ecommerceService.partner(TradeTypeEnum.JSAPI, partnerTransactionsRequest);
|
|
|
-
|
|
|
- XingxiUnifiedPaymentInfoDTO biandanUnifiedPaymentInfoDTO = buildBiandanUnifiedPaymentInfoDTO(wxPayConfig, request, partnerTransactionsRequest, transactionsResult);
|
|
|
- biandanUnifiedPaymentInfoDTO.setCallUnifiedPayMercRole(mercUnifiedpayDTO.getCallUnifiedPayMercRole());
|
|
|
- biandanUnifiedPaymentInfoDTO.setCallUnifiedpayMercId(mercUnifiedpayDTO.getCallUnifiedpayMercId());
|
|
|
-
|
|
|
- Object payInfo = transactionsResult.getPayInfo(TradeTypeEnum.JSAPI, wxPayConfig.getAppId(), wxPayConfig.getMchId(), wxPayConfig.getPrivateKey());
|
|
|
- BiandanUnifiedpayOrderResponse response = new BiandanUnifiedpayOrderResponse();
|
|
|
- response.setPaySign(payInfo);
|
|
|
- response.setOriginalResponseObj(transactionsResult);
|
|
|
- response.setBiandanUnifiedPaymentInfoDTO(biandanUnifiedPaymentInfoDTO);
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayContinue2payResponse continue2pay(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayContinue2payRequest request) throws Exception {
|
|
|
-
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
- String prepayId = request.getPrepayId();
|
|
|
-
|
|
|
- TransactionsResult transactionsResult = new TransactionsResult();
|
|
|
- transactionsResult.setPrepayId(prepayId);
|
|
|
- Object payInfo = transactionsResult.getPayInfo(
|
|
|
- TradeTypeEnum.JSAPI,
|
|
|
- wxPayConfig.getAppId(),
|
|
|
- wxPayConfig.getMchId(),
|
|
|
- wxPayConfig.getPrivateKey()
|
|
|
- );
|
|
|
-
|
|
|
- BiandanUnifiedpayContinue2payResponse response = new BiandanUnifiedpayContinue2payResponse();
|
|
|
- response.setPaySign(payInfo);
|
|
|
- response.setOriginalResponseObj(transactionsResult);
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayCallbackResponse callback(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayCallbackRequest request) throws Exception{
|
|
|
-
|
|
|
- HttpServletRequest httpServletRequest = request.getHttpServletRequest();
|
|
|
- SignatureHeader signatureHeader = httpRequestToSignatureHeader(httpServletRequest);
|
|
|
- String s = StreamUtils.copyToString(httpServletRequest.getInputStream(), Charset.defaultCharset());
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- PartnerTransactionsNotifyResult partnerTransactionsNotifyResult = ecommerceService.parsePartnerNotifyResult(s, signatureHeader);
|
|
|
- PartnerTransactionsResult partnerTransactionsResult = partnerTransactionsNotifyResult.getResult();
|
|
|
-
|
|
|
- XingxiUnifiedpayCallbackResultDTO biandanUnifiedpayCallbackResultDTO = partnerTransactionsResultToBiandanUnifiedpayCallbackResultDTO(partnerTransactionsResult);
|
|
|
- biandanUnifiedpayCallbackServiceI.callbackFollowUpProcessing(biandanUnifiedpayCallbackResultDTO);
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayAddProfitsharingReceiversResponse addProfitsharingReceivers(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayAddProfitsharingReceiversRequest request) throws Exception{
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
- String appId = wxPayConfig.getAppId();
|
|
|
-
|
|
|
- String account = request.getAccount();
|
|
|
-
|
|
|
- ProfitSharingReceiverRequest receiverRequest = new ProfitSharingReceiverRequest();
|
|
|
- receiverRequest.setAppid(appId);
|
|
|
- receiverRequest.setAccount(account);
|
|
|
- receiverRequest.setType("PERSONAL_OPENID");
|
|
|
- receiverRequest.setRelationType("OTHERS");
|
|
|
- ProfitSharingReceiverResult profitSharingReceiverResult = ecommerceService.addReceivers(receiverRequest);
|
|
|
-
|
|
|
- BiandanUnifiedpayAddProfitsharingReceiversResponse response = new BiandanUnifiedpayAddProfitsharingReceiversResponse();
|
|
|
- response.setType(profitSharingReceiverResult.getType());
|
|
|
- response.setOriginalResponseObj(profitSharingReceiverResult);
|
|
|
-
|
|
|
- return response;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayDelProfitsharingReceiversResponse delProfitsharingReceivers(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayDelProfitsharingReceiversRequest request) throws Exception {
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
- String appId = wxPayConfig.getAppId();
|
|
|
- String account = request.getAccount();
|
|
|
-
|
|
|
- ProfitSharingReceiverRequest receiverRequest = new ProfitSharingReceiverRequest();
|
|
|
- receiverRequest.setAppid(appId);
|
|
|
- receiverRequest.setAccount(account);
|
|
|
- receiverRequest.setType("PERSONAL_OPENID");
|
|
|
- ProfitSharingReceiverResult profitSharingReceiverResult = ecommerceService.deleteReceivers(receiverRequest);
|
|
|
-
|
|
|
- BiandanUnifiedpayDelProfitsharingReceiversResponse response = new BiandanUnifiedpayDelProfitsharingReceiversResponse();
|
|
|
- response.setType(profitSharingReceiverResult.getType());
|
|
|
- response.setOriginalResponseObj(profitSharingReceiverResult);
|
|
|
- return response;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private XingxiUnifiedpayCallbackResultDTO partnerTransactionsResultToBiandanUnifiedpayCallbackResultDTO(PartnerTransactionsResult partnerTransactionsResult){
|
|
|
-
|
|
|
- String tradeState = partnerTransactionsResult.getTradeState();
|
|
|
- String outTradeNo = partnerTransactionsResult.getOutTradeNo();
|
|
|
- String successTimeString = partnerTransactionsResult.getSuccessTime();
|
|
|
- String tradeType = partnerTransactionsResult.getTradeType();
|
|
|
- String bankType = partnerTransactionsResult.getBankType();
|
|
|
- String attach = partnerTransactionsResult.getAttach();
|
|
|
- String transactionId = partnerTransactionsResult.getTransactionId();
|
|
|
-
|
|
|
- XingxiUnifiedpayCallbackResultDTO biandanUnifiedpayCallbackResultDTO = new XingxiUnifiedpayCallbackResultDTO();
|
|
|
- biandanUnifiedpayCallbackResultDTO.setTradeState(tradeState);
|
|
|
- biandanUnifiedpayCallbackResultDTO.setOutTradeNo(outTradeNo);
|
|
|
- biandanUnifiedpayCallbackResultDTO.setSuccessTimeString(successTimeString);
|
|
|
- biandanUnifiedpayCallbackResultDTO.setTradeType(tradeType);
|
|
|
- biandanUnifiedpayCallbackResultDTO.setBankType(bankType);
|
|
|
- biandanUnifiedpayCallbackResultDTO.setAttach(attach);
|
|
|
- biandanUnifiedpayCallbackResultDTO.setTransactionId(transactionId);
|
|
|
- biandanUnifiedpayCallbackResultDTO.setCallUnifiedpayComponent("EcommerceWXPayCallback");
|
|
|
-
|
|
|
- biandanUnifiedpayCallbackResultDTO.setOriginalObj(partnerTransactionsResult);
|
|
|
- return biandanUnifiedpayCallbackResultDTO;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayRefundResponse refund(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayRefundRequest request) throws Exception {
|
|
|
-
|
|
|
- String subMchid = mercUnifiedpayDTO.getSubMchid();
|
|
|
- String outRefundNo = request.getOutRefundNo();
|
|
|
- String transactionId = request.getTransactionId();
|
|
|
- String currency = request.getCurrency();
|
|
|
- Integer refundAmt = request.getRefundAmt();
|
|
|
- Integer orderOriginalTotalAmt = request.getOrderOriginalTotalAmt();
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig config = wxPayService.getConfig();
|
|
|
-
|
|
|
- RefundsRequest refundsRequest = new RefundsRequest();
|
|
|
- refundsRequest.setTransactionId(transactionId);
|
|
|
- refundsRequest.setOutRefundNo(outRefundNo);
|
|
|
- refundsRequest.setSubMchid(subMchid);
|
|
|
- refundsRequest.setSpAppid(config.getAppId());
|
|
|
-
|
|
|
- RefundsRequest.Amount amount = RefundsRequest.Amount.builder().build();
|
|
|
- amount.setCurrency(currency);
|
|
|
- amount.setRefund(refundAmt);
|
|
|
- amount.setTotal(orderOriginalTotalAmt);
|
|
|
- refundsRequest.setAmount(amount);
|
|
|
- RefundsResult refundsResult = ecommerceService.refunds(refundsRequest);
|
|
|
-
|
|
|
- BiandanUnifiedpayRefundResponse response = new BiandanUnifiedpayRefundResponse();
|
|
|
- response.setRefundId(refundsResult.getRefundId());
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayQueryProfitSharingResponse queryProfitSharing(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayQueryProfitSharingRequest request) throws Exception {
|
|
|
-
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
-
|
|
|
- ProfitSharingQueryRequest profitSharingQueryRequest = new ProfitSharingQueryRequest();
|
|
|
- profitSharingQueryRequest.setOutOrderNo(request.getOutOrderNo());
|
|
|
- profitSharingQueryRequest.setTransactionId(request.getTransactionId());
|
|
|
- profitSharingQueryRequest.setSubMchid(mercUnifiedpayDTO.getSubMchid());
|
|
|
- ProfitSharingResult profitSharingResult = ecommerceService.queryProfitSharing(profitSharingQueryRequest);
|
|
|
-
|
|
|
- List<ProfitSharingResult.Receiver> receivers = profitSharingResult.getReceivers();
|
|
|
-
|
|
|
- BiandanUnifiedpayQueryProfitSharingResponse response = new BiandanUnifiedpayQueryProfitSharingResponse();
|
|
|
- response.setOrderId(profitSharingResult.getOrderId());
|
|
|
- response.setProfitSharingStatus(profitSharingResult.getStatus());
|
|
|
- response.setReceivers(receivers.stream().map(this::toReceiver).collect(Collectors.toList()));
|
|
|
- response.setOriginalResponseObj(profitSharingResult);
|
|
|
-
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private BiandanUnifiedpayQueryProfitSharingResponse.Receiver toReceiver(ProfitSharingResult.Receiver receiver){
|
|
|
- BiandanUnifiedpayQueryProfitSharingResponse.Receiver receivers = new BiandanUnifiedpayQueryProfitSharingResponse.Receiver();
|
|
|
- BeanUtils.copyProperties(receiver, receivers);
|
|
|
- return receivers;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayCreateSubMchApplyResponse createSubMchApply(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayCreateSubMchApplyRequest request) throws Exception {
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- ApplymentsRequest applymentsRequest = new ApplymentsRequest();
|
|
|
- BeanUtils.copyProperties(request, applymentsRequest);
|
|
|
- ApplymentsResult applymentsResult = ecommerceService.createApply(applymentsRequest);
|
|
|
- BiandanUnifiedpayCreateSubMchApplyResponse response = new BiandanUnifiedpayCreateSubMchApplyResponse();
|
|
|
- response.setApplymentId(applymentsResult.getApplymentId());
|
|
|
- response.setOriginalResponseObj(applymentsResult);
|
|
|
-
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayQueryApplyStatusResponse queryApplyStatusByApplymentId(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayQueryApplyStatusRequest request) throws Exception {
|
|
|
-
|
|
|
- String applymentId = request.getApplymentId();
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- ApplymentsStatusResult applymentsStatusResult = ecommerceService.queryApplyStatusByApplymentId(applymentId);
|
|
|
-
|
|
|
- BiandanUnifiedpayQueryApplyStatusResponse response = new BiandanUnifiedpayQueryApplyStatusResponse();
|
|
|
- BeanUtils.copyProperties(applymentsStatusResult, response);
|
|
|
- response.setOriginalResponseObj(applymentsStatusResult);
|
|
|
-
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayQueryRefundResponse queryRefund(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayQueryRefundRequest request) throws Exception {
|
|
|
-
|
|
|
- String subMchid = mercUnifiedpayDTO.getSubMchid();
|
|
|
- String outRefundNo = request.getOutRefundNo();
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- RefundQueryResult refundQueryResult = ecommerceService.queryRefundByOutRefundNo(subMchid, outRefundNo);
|
|
|
-
|
|
|
- String refundId = refundQueryResult.getRefundId();
|
|
|
- String status = refundQueryResult.getStatus();
|
|
|
-
|
|
|
- BiandanUnifiedpayQueryRefundResponse response = new BiandanUnifiedpayQueryRefundResponse();
|
|
|
- response.setRefundId(refundId);
|
|
|
- response.setRefundStatus(status);
|
|
|
- response.setOriginalResponseObj(refundQueryResult);
|
|
|
-
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayQuerySubMchCurrBalanceResponse querySubMchCurrBalance(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayQuerySubMchCurrBalanceRequest request) throws Exception {
|
|
|
-
|
|
|
- String subMchid = request.getSubMchid();
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
-
|
|
|
- FundBalanceResult fundBalanceResult = ecommerceService.subNowBalance(subMchid);
|
|
|
- BiandanUnifiedpayQuerySubMchCurrBalanceResponse response = new BiandanUnifiedpayQuerySubMchCurrBalanceResponse();
|
|
|
- response.setOriginalResponseObj(fundBalanceResult);
|
|
|
- response.setAvailableAmount(fundBalanceResult.getAvailableAmount());
|
|
|
- response.setPendingAmount(fundBalanceResult.getPendingAmount());
|
|
|
-
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayQuerySubWithdrawResponse querySubWithdraw(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayQuerySubWithdrawRequest request) throws Exception {
|
|
|
-
|
|
|
- String subMchid = request.getSubMchid();
|
|
|
- String outRequestNo = request.getOutRequestNo();
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
-
|
|
|
- SubWithdrawStatusResult subWithdrawStatusResult = ecommerceService.querySubWithdrawByOutRequestNo(subMchid, outRequestNo);
|
|
|
- String status = subWithdrawStatusResult.getStatus();
|
|
|
-
|
|
|
- BiandanUnifiedpayQuerySubWithdrawResponse response = new BiandanUnifiedpayQuerySubWithdrawResponse();
|
|
|
- response.setOriginalResponseObj(subWithdrawStatusResult);
|
|
|
- response.setStatus(status);
|
|
|
-
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayProfitSharingOrdersUnSplitAmountResponse queryProfitSharingOrdersUnsplitAmount(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayProfitSharingOrdersUnSplitAmountRequest request) throws Exception {
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
-
|
|
|
- ProfitSharingOrdersUnSplitAmountRequest profitSharingOrdersUnSplitAmountRequest = new ProfitSharingOrdersUnSplitAmountRequest();
|
|
|
- profitSharingOrdersUnSplitAmountRequest.setTransactionId(request.getTransactionId());
|
|
|
- ProfitSharingOrdersUnSplitAmountResult profitSharingOrdersUnSplitAmountResult = ecommerceService.queryProfitSharingOrdersUnsplitAmount(profitSharingOrdersUnSplitAmountRequest);
|
|
|
-
|
|
|
- BiandanUnifiedpayProfitSharingOrdersUnSplitAmountResponse response = new BiandanUnifiedpayProfitSharingOrdersUnSplitAmountResponse();
|
|
|
- response.setUnsplitAmount(response.getUnsplitAmount());
|
|
|
- response.setOriginalResponseObj(profitSharingOrdersUnSplitAmountResult);
|
|
|
-
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpaySubWithdrawResponse subWithdraw(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpaySubWithdrawRequest request) throws Exception {
|
|
|
-
|
|
|
- String subMchid = request.getSubMchid();
|
|
|
- String outRequestNo = request.getOutRequestNo();
|
|
|
- Integer txAmt = request.getTxAmt();
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
-
|
|
|
- SubWithdrawRequest subWithdrawRequest = new SubWithdrawRequest();
|
|
|
- subWithdrawRequest.setSubMchid(subMchid);
|
|
|
- subWithdrawRequest.setAmount(txAmt);
|
|
|
- subWithdrawRequest.setOutRequestNo(outRequestNo);
|
|
|
-
|
|
|
- SubWithdrawResult subWithdrawResult = ecommerceService.subWithdraw(subWithdrawRequest);
|
|
|
- String withdrawId = subWithdrawResult.getWithdrawId();
|
|
|
-
|
|
|
- BiandanUnifiedpaySubWithdrawResponse response = new BiandanUnifiedpaySubWithdrawResponse();
|
|
|
- response.setSubMchid(subMchid);
|
|
|
- response.setOutRequestNo(outRequestNo);
|
|
|
- response.setWithdrawId(withdrawId);
|
|
|
- response.setOriginalResponseObj(subWithdrawResult);
|
|
|
-
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayFinishProfitSharingResponse finishProfitSharing(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayFinishProfitSharingRequest request) throws Exception {
|
|
|
-
|
|
|
- String description = request.getDescription();
|
|
|
- String transactionId = request.getTransactionId();
|
|
|
- String outOrderNo = request.getOutOrderNo();
|
|
|
- String subMchid = request.getSubMchid();
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
-
|
|
|
- FinishOrderRequest finishOrderRequest = FinishOrderRequest.builder().build();
|
|
|
- finishOrderRequest.setSubMchid(subMchid);
|
|
|
- finishOrderRequest.setTransactionId(transactionId);
|
|
|
- finishOrderRequest.setOutOrderNo(outOrderNo);
|
|
|
- finishOrderRequest.setDescription(description);
|
|
|
-
|
|
|
- ProfitSharingResult profitSharingResult = ecommerceService.finishOrder(finishOrderRequest);
|
|
|
- String orderId = profitSharingResult.getOrderId();
|
|
|
-
|
|
|
- BiandanUnifiedpayFinishProfitSharingResponse response = new BiandanUnifiedpayFinishProfitSharingResponse();
|
|
|
- response.setOrderId(orderId);
|
|
|
- response.setOriginalResponseObj(profitSharingResult);
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BiandanUnifiedpayProfitSharingResponse profitSharing(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayProfitSharingRequest request) throws Exception {
|
|
|
-
|
|
|
- String subMchid = mercUnifiedpayDTO.getSubMchid();
|
|
|
- String transactionId = request.getTransactionId();
|
|
|
- String outOrderNo = request.getOutOrderNo();
|
|
|
- List<BiandanUnifiedpayProfitSharingRequest.ProfitSharingReceiversDTO> profitSharingReceivers = request.getProfitSharingReceivers();
|
|
|
-
|
|
|
- EcommerceService ecommerceService = wxPayService.getEcommerceService();
|
|
|
- WxPayConfig wxPayConfig = wxPayService.getConfig();
|
|
|
- String appId = wxPayConfig.getAppId();
|
|
|
-
|
|
|
- List<ProfitSharingRequest.Receiver> receivers = new ArrayList<>();
|
|
|
- for (BiandanUnifiedpayProfitSharingRequest.ProfitSharingReceiversDTO profitSharingReceiver : profitSharingReceivers) {
|
|
|
- Integer amount = profitSharingReceiver.getAmount();
|
|
|
- String description = profitSharingReceiver.getDescription();
|
|
|
- String receiverAccount = profitSharingReceiver.getReceiverAccount();
|
|
|
- ProfitSharingRequest.Receiver receiver = new ProfitSharingRequest.Receiver();
|
|
|
- receiver.setType("PERSONAL_OPENID");
|
|
|
- receiver.setAmount(amount);
|
|
|
- receiver.setReceiverAccount(receiverAccount);
|
|
|
- receiver.setDescription(description);
|
|
|
- receivers.add(receiver);
|
|
|
- }
|
|
|
-
|
|
|
- ProfitSharingRequest profitSharingRequest = new ProfitSharingRequest();
|
|
|
- profitSharingRequest.setAppid(appId);
|
|
|
- profitSharingRequest.setSubMchid(subMchid);
|
|
|
- profitSharingRequest.setOutOrderNo(outOrderNo);
|
|
|
- profitSharingRequest.setTransactionId(transactionId);
|
|
|
- profitSharingRequest.setReceivers(receivers);
|
|
|
-
|
|
|
- ProfitSharingResult profitSharingResult = ecommerceService.profitSharing(profitSharingRequest);
|
|
|
- String orderId = profitSharingResult.getOrderId();
|
|
|
- String status = profitSharingResult.getStatus();
|
|
|
-
|
|
|
- BiandanUnifiedpayProfitSharingResponse response = new BiandanUnifiedpayProfitSharingResponse();
|
|
|
- response.setOrderId(orderId);
|
|
|
- response.setProfitSharingStatus(status);
|
|
|
- response.setOriginalResponseObj(profitSharingResult);
|
|
|
-
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- private XingxiUnifiedPaymentInfoDTO buildBiandanUnifiedPaymentInfoDTO(WxPayConfig wxPayConfig, BiandanUnifiedpayOrderRequest biandanUnifiedpayOrderRequest, PartnerTransactionsRequest request, TransactionsResult result) {
|
|
|
-
|
|
|
- Long sellerId = biandanUnifiedpayOrderRequest.getSellerId();
|
|
|
- Long orderId = biandanUnifiedpayOrderRequest.getOrderId();
|
|
|
- String orderNo = biandanUnifiedpayOrderRequest.getOrderNo();
|
|
|
- String orderStatus = biandanUnifiedpayOrderRequest.getOrderStatus();
|
|
|
- Integer txAmt = biandanUnifiedpayOrderRequest.getTxAmt();
|
|
|
- String openid = request.getPayer().getSpOpenid();
|
|
|
- String appId = wxPayConfig.getAppId();
|
|
|
- String mchId = wxPayConfig.getMchId();
|
|
|
-
|
|
|
- XingxiUnifiedPaymentInfoDTO paymentInfo = new XingxiUnifiedPaymentInfoDTO();
|
|
|
- paymentInfo.setProfitSharing("1");
|
|
|
- paymentInfo.setSubCurrency("CNY");
|
|
|
- paymentInfo.setPayKind("EcommerceWXPay");
|
|
|
- paymentInfo.setSellerId(sellerId);
|
|
|
- paymentInfo.setCombineAppid(appId);
|
|
|
- paymentInfo.setCombineMchid(mchId);
|
|
|
- paymentInfo.setMchid(mchId);
|
|
|
- paymentInfo.setSubMchid(request.getSubMchid());
|
|
|
- paymentInfo.setNotifyUrl(request.getNotifyUrl());
|
|
|
- paymentInfo.setWxOpenId(openid);
|
|
|
- paymentInfo.setOrderId(orderId);
|
|
|
- paymentInfo.setOrderStatus(orderStatus);
|
|
|
- paymentInfo.setOrderNo(orderNo);
|
|
|
- paymentInfo.setOutTradeNo(request.getOutTradeNo());
|
|
|
- paymentInfo.setPayAmount(txAmt);
|
|
|
- paymentInfo.setTimeStart(LocalDateTime.now());
|
|
|
- paymentInfo.setTimeExpire(parseTimeExpire(request.getTimeExpire()));
|
|
|
- paymentInfo.setPrepayId(result.getPrepayId());
|
|
|
-
|
|
|
- return paymentInfo;
|
|
|
- }
|
|
|
-
|
|
|
- private PartnerTransactionsRequest requestToPartnerTransactionsRequest(MercUnifiedpayDTO mercUnifiedpayDTO, BiandanUnifiedpayOrderRequest request){
|
|
|
-
|
|
|
- String unifiedpayCallbackUrl = biandanUnifiedpayProperties.getUnifiedpayCallbackUrl();
|
|
|
- if (!StringUtils.hasLength(unifiedpayCallbackUrl)){
|
|
|
- log.debug("支付回调地址不能为空,格式列如[https://xxx.com/wxpay/%s/callback],域名自行替换");
|
|
|
- throw new RuntimeException("支付回调地址不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- String subMchid = mercUnifiedpayDTO.getSubMchid();
|
|
|
- String unifiedpayOutTradeNo = request.getUnifiedpayOutTradeNo();
|
|
|
- String payerOpenid = request.getPayerOpenid();
|
|
|
- Integer txAmt = request.getTxAmt();
|
|
|
- Long sellerId = request.getSellerId();
|
|
|
- WxPayConfig config = wxPayService.getConfig();
|
|
|
- log.debug("微信支付配置:" + config.toString());
|
|
|
- PartnerTransactionsRequest partnerTransactionsRequest = new PartnerTransactionsRequest();
|
|
|
- partnerTransactionsRequest.setDescription("恩瑞斯购物");
|
|
|
- partnerTransactionsRequest.setSpAppid(config.getAppId());
|
|
|
- partnerTransactionsRequest.setSpMchid(config.getMchId());
|
|
|
- partnerTransactionsRequest.setSubMchid(subMchid);
|
|
|
- partnerTransactionsRequest.setOutTradeNo(unifiedpayOutTradeNo);
|
|
|
-
|
|
|
- PartnerTransactionsRequest.Payer payer = new PartnerTransactionsRequest.Payer();
|
|
|
- payer.setSpOpenid(payerOpenid);
|
|
|
- partnerTransactionsRequest.setPayer(payer);
|
|
|
-
|
|
|
- PartnerTransactionsRequest.SettleInfo settleInfo = new PartnerTransactionsRequest.SettleInfo();
|
|
|
- settleInfo.setProfitSharing(true);
|
|
|
- partnerTransactionsRequest.setSettleInfo(settleInfo);
|
|
|
-
|
|
|
- PartnerTransactionsRequest.Amount amount = new PartnerTransactionsRequest.Amount();
|
|
|
- amount.setCurrency("CNY");
|
|
|
- amount.setTotal(txAmt);
|
|
|
- partnerTransactionsRequest.setAmount(amount);
|
|
|
- partnerTransactionsRequest.setTimeExpire(timeExpire());
|
|
|
- partnerTransactionsRequest.setNotifyUrl(String.format(unifiedpayCallbackUrl, sellerId));
|
|
|
-
|
|
|
- return partnerTransactionsRequest;
|
|
|
- }
|
|
|
-
|
|
|
- private SignatureHeader httpRequestToSignatureHeader(HttpServletRequest request){
|
|
|
- String serial = request.getHeader("Wechatpay-Serial");
|
|
|
- String signature = request.getHeader("Wechatpay-Signature");
|
|
|
- String timestamp = request.getHeader("Wechatpay-Timestamp");
|
|
|
- String nonceStr = request.getHeader("Wechatpay-Nonce");
|
|
|
- SignatureHeader signatureHeader = new SignatureHeader();
|
|
|
- signatureHeader.setSerialNo(serial);
|
|
|
- signatureHeader.setSigned(signature);
|
|
|
- signatureHeader.setNonce(nonceStr);
|
|
|
- signatureHeader.setTimeStamp(timestamp);
|
|
|
- return signatureHeader;
|
|
|
- }
|
|
|
-
|
|
|
-}
|