|
@@ -19,6 +19,7 @@ import com.fs.company.domain.CompanyUser;
|
|
import com.fs.company.service.ICompanyService;
|
|
import com.fs.company.service.ICompanyService;
|
|
import com.fs.company.service.ICompanyUserService;
|
|
import com.fs.company.service.ICompanyUserService;
|
|
import com.fs.course.config.RedPacketConfig;
|
|
import com.fs.course.config.RedPacketConfig;
|
|
|
|
+import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
import com.fs.pay.pay.config.PayConfig;
|
|
import com.fs.pay.pay.config.PayConfig;
|
|
import com.fs.pay.pay.domain.CreateWxOrderResult;
|
|
import com.fs.pay.pay.domain.CreateWxOrderResult;
|
|
import com.fs.pay.pay.dto.WxJspayDTO;
|
|
import com.fs.pay.pay.dto.WxJspayDTO;
|
|
@@ -38,14 +39,18 @@ import com.fs.pay.service.IPayService;
|
|
import com.fs.pay.service.dto.CreatePayDTO;
|
|
import com.fs.pay.service.dto.CreatePayDTO;
|
|
import com.fs.pay.service.dto.PayDTO;
|
|
import com.fs.pay.service.dto.PayDTO;
|
|
import com.fs.pay.service.dto.TradeOrder;
|
|
import com.fs.pay.service.dto.TradeOrder;
|
|
|
|
+import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
|
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayTransferBatchesNotifyV3Result;
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
-import com.github.binarywang.wxpay.bean.transfer.TransferBatchesRequest;
|
|
|
|
-import com.github.binarywang.wxpay.bean.transfer.TransferBatchesResult;
|
|
|
|
|
|
+import com.github.binarywang.wxpay.bean.transfer.*;
|
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
import com.github.binarywang.wxpay.service.TransferService;
|
|
import com.github.binarywang.wxpay.service.TransferService;
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -54,6 +59,8 @@ import com.fs.store.domain.FsStorePayment;
|
|
import com.fs.store.service.IFsStorePaymentService;
|
|
import com.fs.store.service.IFsStorePaymentService;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 支付明细Service业务层处理
|
|
* 支付明细Service业务层处理
|
|
*
|
|
*
|
|
@@ -63,7 +70,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
@Service
|
|
@Service
|
|
public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ Logger logger = LoggerFactory.getLogger(getClass());
|
|
@Autowired
|
|
@Autowired
|
|
private WxMaProperties properties;
|
|
private WxMaProperties properties;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -85,6 +92,9 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
PayService ybPayService;
|
|
PayService ybPayService;
|
|
@Autowired
|
|
@Autowired
|
|
private ISysConfigService configService;
|
|
private ISysConfigService configService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFsCourseRedPacketLogService redPacketLogService;
|
|
/**
|
|
/**
|
|
* 查询支付明细
|
|
* 查询支付明细
|
|
*
|
|
*
|
|
@@ -384,4 +394,134 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
return R.error("发送失败");
|
|
return R.error("发送失败");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String transferNotify(String notifyData, HttpServletRequest request) {
|
|
|
|
+ logger.info("zyp \n【收到转账回调】:{}",notifyData);
|
|
|
|
+ try {
|
|
|
|
+ String json = configService.selectConfigByKey("redPacket.config");
|
|
|
|
+ RedPacketConfig config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
|
+ //创建微信订单
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
+ BeanUtils.copyProperties(config,payConfig);
|
|
|
|
+ WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
|
+ SignatureHeader signatureHeader = new SignatureHeader();
|
|
|
|
+ signatureHeader.setTimeStamp(request.getHeader("Wechatpay-Timestamp"));
|
|
|
|
+ signatureHeader.setNonce(request.getHeader("Wechatpay-Nonce"));
|
|
|
|
+ signatureHeader.setSerial(request.getHeader("Wechatpay-Serial"));
|
|
|
|
+ signatureHeader.setSignature(request.getHeader("Wechatpay-Signature"));
|
|
|
|
+ WxPayTransferBatchesNotifyV3Result result = wxPayService.parseTransferBatchesNotifyV3Result(notifyData,signatureHeader);
|
|
|
|
+ logger.info("到零钱回调:{}",result.getResult());
|
|
|
|
+ if (result.getResult().getBatchStatus().equals("FINISHED")) {
|
|
|
|
+ R r = redPacketLogService.syncRedPacket(result.getResult().getOutBatchNo());
|
|
|
|
+ logger.info("result:{}",r);
|
|
|
|
+ if (r.get("code").equals(200)){
|
|
|
|
+ return WxPayNotifyResponse.success("处理成功");
|
|
|
|
+ }else {
|
|
|
|
+ return WxPayNotifyResponse.fail("");
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ return WxPayNotifyResponse.fail("");
|
|
|
|
+ }
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
+ logger.error("zyp \n【转账回调异常】:{}", e.getReturnMsg());
|
|
|
|
+ return WxPayNotifyResponse.fail(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R sendRedPacketV3(WxSendRedPacketParam param) {
|
|
|
|
+ String json = configService.selectConfigByKey("redPacket.config");
|
|
|
|
+ RedPacketConfig config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
|
+
|
|
|
|
+ //创建微信订单
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
+ BeanUtils.copyProperties(config,payConfig);
|
|
|
|
+ WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
|
+ TransferService transferService = wxPayService.getTransferService();
|
|
|
|
+
|
|
|
|
+ //商家转账请求
|
|
|
|
+ TransferBillsRequest request = new TransferBillsRequest();
|
|
|
|
+ request.setAppid(config.getAppId());
|
|
|
|
+ request.setOpenid(param.getOpenId());
|
|
|
|
+
|
|
|
|
+// String code = OrderCodeUtils.getH5RedPacketOrderSn();
|
|
|
|
+// if(StringUtils.isEmpty(code)){
|
|
|
|
+// return R.error("订单生成失败,请重试");
|
|
|
|
+// }
|
|
|
|
+ String code = String.valueOf(IdUtil.getSnowflake(0, 0).nextId());
|
|
|
|
+ request.setOutBillNo("fsCourse"+code);
|
|
|
|
+ //转账金额
|
|
|
|
+ Integer amount = WxPayUnifiedOrderRequest.yuanToFen(param.getAmount()!=null ? param.getAmount().toString() : "0.1");
|
|
|
|
+ request.setTransferAmount(amount);
|
|
|
|
+ request.setTransferRemark("活动奖励");
|
|
|
|
+ //用户感知
|
|
|
|
+ request.setUserRecvPerception("活动奖励");
|
|
|
|
+ request.setNotifyUrl(config.getNotifyUrl());
|
|
|
|
+ request.setTransferSceneId("1000");
|
|
|
|
+ List<TransferBillsRequest.TransferSceneReportInfo> transferSceneReportInfos = new ArrayList<>();
|
|
|
|
+ // 添加第一条数据
|
|
|
|
+ TransferBillsRequest.TransferSceneReportInfo info1 = new TransferBillsRequest.TransferSceneReportInfo();
|
|
|
|
+ info1.setInfoType("活动名称");
|
|
|
|
+ info1.setInfoContent("新会员有礼");
|
|
|
|
+ transferSceneReportInfos.add(info1);
|
|
|
|
+
|
|
|
|
+ // 添加第二条数据
|
|
|
|
+ TransferBillsRequest.TransferSceneReportInfo info2 = new TransferBillsRequest.TransferSceneReportInfo();
|
|
|
|
+ info2.setInfoType("奖励说明");
|
|
|
|
+ info2.setInfoContent("注册会员抽奖一等奖");
|
|
|
|
+ transferSceneReportInfos.add(info2);
|
|
|
|
+ request.setTransferSceneReportInfos(transferSceneReportInfos);
|
|
|
|
+
|
|
|
|
+ //发起商家转账API(新)
|
|
|
|
+ TransferBillsResult transferBillsResult=null;
|
|
|
|
+ try {
|
|
|
|
+ transferBillsResult = transferService.transferBills(request);
|
|
|
|
+ logger.info("商家转账支付完成:[msg:{}]",transferBillsResult);
|
|
|
|
+ return R.ok("发送红包成功").put("data",transferBillsResult);
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ logger.info("商家转账支付失败:[msg:{}]",e.getMessage());
|
|
|
|
+ return R.error("发送失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String v3TransferNotify(String notifyData, HttpServletRequest request) {
|
|
|
|
+ logger.info("zyp \n【收到转账回调】:{}",notifyData);
|
|
|
|
+ try {
|
|
|
|
+ String json = configService.selectConfigByKey("redPacket.config");
|
|
|
|
+ RedPacketConfig config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
|
+ //创建微信订单
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
+ BeanUtils.copyProperties(config,payConfig);
|
|
|
|
+ WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
|
+ SignatureHeader signatureHeader = new SignatureHeader();
|
|
|
|
+ signatureHeader.setTimeStamp(request.getHeader("Wechatpay-Timestamp"));
|
|
|
|
+ signatureHeader.setNonce(request.getHeader("Wechatpay-Nonce"));
|
|
|
|
+ signatureHeader.setSerial(request.getHeader("Wechatpay-Serial"));
|
|
|
|
+ signatureHeader.setSignature(request.getHeader("Wechatpay-Signature"));
|
|
|
|
+ TransferBillsNotifyResult result = wxPayService.parseTransferBillsNotifyV3Result(notifyData,signatureHeader);
|
|
|
|
+ logger.info("到零钱回调:{}",result.getResult());
|
|
|
|
+ if (result.getResult().getState().equals("SUCCESS")) {
|
|
|
|
+ R r = redPacketLogService.syncRedPacket(result.getResult().getOutBillNo());
|
|
|
|
+ logger.info("result:{}",r);
|
|
|
|
+ if (r.get("code").equals(200)){
|
|
|
|
+ return WxPayNotifyResponse.success("处理成功");
|
|
|
|
+ }else {
|
|
|
|
+ return WxPayNotifyResponse.fail("");
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ return WxPayNotifyResponse.fail("");
|
|
|
|
+ }
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
+ logger.error("zyp \n【转账回调异常】:{}", e.getReturnMsg());
|
|
|
|
+ return WxPayNotifyResponse.fail(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|