|
@@ -6,6 +6,8 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -23,6 +25,8 @@ import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.core.utils.OrderCodeUtils;
|
|
|
import com.fs.course.config.RedPacketConfig;
|
|
|
+import com.fs.course.domain.FsCourseRedPacketLog;
|
|
|
+import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
|
import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
|
import com.fs.pay.pay.config.PayConfig;
|
|
|
import com.fs.pay.pay.domain.CreateWxOrderResult;
|
|
@@ -32,6 +36,7 @@ import com.fs.store.param.FsStoreStatisticsParam;
|
|
|
import com.fs.his.param.WxSendRedPacketParam;
|
|
|
import com.fs.store.vo.FsStorePaymentStatisticsVO;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
+import com.fs.wx.miniapp.config.WxMaConfiguration;
|
|
|
import com.fs.wx.miniapp.config.WxMaProperties;
|
|
|
import com.fs.wx.pay.config.WxPayProperties;
|
|
|
import com.fs.store.domain.FsUser;
|
|
@@ -53,6 +58,7 @@ import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.github.binarywang.wxpay.service.TransferService;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -377,7 +383,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
}
|
|
|
//H5的用公众号的appid发,小程序的用小程序的appid来发
|
|
|
if (param.getSource()==2){
|
|
|
- config.setAppId(config.getMiniappId());
|
|
|
+ config.setAppId(param.getAppId());
|
|
|
}
|
|
|
//组合返回参数
|
|
|
R result = new R();
|
|
@@ -471,7 +477,23 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
|
|
|
ArrayList<TransferBatchesRequest.TransferDetail> transferDetailList = new ArrayList<>();
|
|
|
TransferBatchesRequest.TransferDetail transferDetail = new TransferBatchesRequest.TransferDetail();
|
|
|
- transferDetail.setOpenid(param.getOpenId());
|
|
|
+// transferDetail.setOpenid(param.getOpenId());
|
|
|
+
|
|
|
+ String openId;
|
|
|
+ //临时方法,有code的时候获取一下客户的openId
|
|
|
+ if (StringUtils.isNotEmpty(param.getCode())){
|
|
|
+ WxMaService wxService = WxMaConfiguration.getMaService(param.getAppId());
|
|
|
+ try {
|
|
|
+ WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(param.getCode());
|
|
|
+ openId = session.getOpenid();
|
|
|
+ } catch (WxErrorException e){
|
|
|
+ return R.error("openId获取失败," + e.getMessage());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ openId = param.getOpenId();
|
|
|
+ }
|
|
|
+
|
|
|
+ transferDetail.setOpenid(openId);
|
|
|
String code1 = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
transferDetail.setOutDetailNo("fsCourse" + code1);
|
|
|
transferDetail.setTransferAmount(amount);
|
|
@@ -481,7 +503,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
|
|
|
try {
|
|
|
TransferBatchesResult transferBatchesResult = transferService.transferBatches(request);
|
|
|
- return R.ok("发送红包成功").put("orderCode", transferBatchesResult.getOutBatchNo());
|
|
|
+ return R.ok("发送红包成功").put("orderCode", transferBatchesResult.getOutBatchNo()).put("batchId", transferBatchesResult.getBatchId());
|
|
|
} catch (WxPayException e) {
|
|
|
e.printStackTrace();
|
|
|
return R.error("发送失败");
|
|
@@ -499,19 +521,18 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
|
|
|
param.setSource(2);
|
|
|
-// param.setOpenId("ooXAA1Fw5ekSqCT-WLKpoA0cDVDo");
|
|
|
- param.setAmount(new BigDecimal(0.1));
|
|
|
+ param.setAmount(param.getAmount());
|
|
|
|
|
|
|
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
|
BeanUtils.copyProperties(config, payConfig);
|
|
|
- payConfig.setAppId(config.getMiniappId());
|
|
|
+ payConfig.setAppId(param.getAppId());
|
|
|
WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
wxPayService.setConfig(payConfig);
|
|
|
TransferService transferService = wxPayService.getTransferService();
|
|
|
|
|
|
TransferBatchesRequest request = new TransferBatchesRequest();
|
|
|
- request.setAppid(config.getMiniappId());
|
|
|
+ request.setAppid(param.getAppId());
|
|
|
String code = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
request.setOutBatchNo("fsCourse" + code);
|
|
|
request.setBatchRemark("课堂答题奖励");
|
|
@@ -524,6 +545,21 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
ArrayList<TransferBatchesRequest.TransferDetail> transferDetailList = new ArrayList<>();
|
|
|
TransferBatchesRequest.TransferDetail transferDetail = new TransferBatchesRequest.TransferDetail();
|
|
|
transferDetail.setOpenid(param.getOpenId());
|
|
|
+
|
|
|
+// String openId;
|
|
|
+// //临时方法,有code的时候获取一下客户的openId
|
|
|
+// if (StringUtils.isNotEmpty(param.getCode())){
|
|
|
+// WxMaService wxService = WxMaConfiguration.getMaService(param.getAppId());
|
|
|
+// try {
|
|
|
+// WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(param.getCode());
|
|
|
+// openId = session.getOpenid();
|
|
|
+// } catch (WxErrorException e){
|
|
|
+// return R.error("openId获取失败," + e.getMessage());
|
|
|
+// }
|
|
|
+// }else {
|
|
|
+// openId = param.getOpenId();
|
|
|
+// }
|
|
|
+// transferDetail.setOpenid(openId);
|
|
|
String code1 = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
transferDetail.setOutDetailNo("fsCourse" + code1);
|
|
|
transferDetail.setTransferAmount(amount);
|
|
@@ -533,7 +569,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
|
|
|
try {
|
|
|
TransferBatchesResult transferBatchesResult = transferService.transferBatches(request);
|
|
|
- return R.ok("发送红包成功").put("orderCode", transferBatchesResult.getOutBatchNo());
|
|
|
+ return R.ok("发送红包成功").put("orderCode", transferBatchesResult.getOutBatchNo()).put("batchId", transferBatchesResult.getBatchId());
|
|
|
} catch (WxPayException e) {
|
|
|
e.printStackTrace();
|
|
|
return R.error("发送失败");
|
|
@@ -565,8 +601,8 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
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());
|
|
|
+ if (result.getResult().getBatchStatus().equals("FINISHED") && result.getResult().getFailNum()==0) {
|
|
|
+ R r = redPacketLogService.syncRedPacket(result.getResult().getOutBatchNo(),result.getResult().getBatchId());
|
|
|
logger.info("result:{}",r);
|
|
|
if (r.get("code").equals(200)){
|
|
|
return WxPayNotifyResponse.success("处理成功");
|
|
@@ -591,14 +627,9 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
//创建微信订单
|
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
|
BeanUtils.copyProperties(config,payConfig);
|
|
|
-// payConfig.setCertSerialNo("63AC73F33E0A21973BB1DE533421A2337FD91C20");
|
|
|
WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
wxPayService.setConfig(payConfig);
|
|
|
SignatureHeader signatureHeader = new SignatureHeader();
|
|
|
-// signatureHeader.setTimeStamp("1622450000"); // 时间戳(Unix时间戳)
|
|
|
-// signatureHeader.setNonce("5K8264ILTKCH16CQ2502SI8ZNMTM67VS"); // 随机字符串
|
|
|
-// signatureHeader.setSerial("63AC73F33E0A21973BB1DE533421A2337FD91C20");
|
|
|
-// signatureHeader.setSignature("HbjssPzTBkM2iSCmxknS663zigo3gQ1jGQ4R6E6x9356bmV6Um4WfgGWZOH+fdCx5dxjHEiIci5kOYKl0ZdRfnexFFuM2riXLSqnRboOJZ+ew8FH4ZP/zCxtlDnmIYbARoIN46RegcRmGgfOznkLcD7ihr0JixgoZ0BOYk7YLhhcbLZaE2OJmwyyYIdJCH5lvg0mXyX1yfutNxPZz13i3OmZiU42xYr4bByJICWMFTwkzha9GVfOp67q/oVu0bEGIMgGdAVoEUJZXOijKdZdOrieXT07wMU31KITKcnizaUGl5peXejbJEd6CAQcX5e8KRlRSjY8DybHAm0JawVuAw==");
|
|
|
signatureHeader.setTimeStamp(request.getHeader("Wechatpay-Timestamp"));
|
|
|
signatureHeader.setNonce(request.getHeader("Wechatpay-Nonce"));
|
|
|
signatureHeader.setSerial(request.getHeader("Wechatpay-Serial"));
|
|
@@ -606,7 +637,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
TransferBillsNotifyResult result = wxPayService.parseTransferBillsNotifyV3Result(notifyData,signatureHeader);
|
|
|
logger.info("到零钱回调:{}",result.getResult());
|
|
|
if (result.getResult().getState().equals("SUCCESS")) {
|
|
|
- R r = redPacketLogService.syncRedPacket(result.getResult().getOutBillNo());
|
|
|
+ R r = redPacketLogService.syncRedPacket(result.getResult().getOutBillNo(),result.getResult().getTransferBillNo());
|
|
|
logger.info("result:{}",r);
|
|
|
if (r.get("code").equals(200)){
|
|
|
return WxPayNotifyResponse.success("处理成功");
|
|
@@ -621,4 +652,79 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
|
|
|
return WxPayNotifyResponse.fail(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsCourseRedPacketLogMapper redPacketLogMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void bufaRedPacket() {
|
|
|
+// String json = configService.selectConfigByKey("redPacket.config");
|
|
|
+// RedPacketConfig config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
+ List<FsCourseRedPacketLog> logs = redPacketLogMapper.selectFail();
|
|
|
+ String appId = "wx414427b10866c04e";
|
|
|
+ for (FsCourseRedPacketLog log : logs){
|
|
|
+ FsUser user = userService.selectFsUserById(log.getUserId());
|
|
|
+ WxSendRedPacketParam param = new WxSendRedPacketParam();
|
|
|
+ param.setAppId(appId);
|
|
|
+ if (user==null || user.getMaOpenId()==null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ param.setOpenId(user.getMaOpenId());
|
|
|
+ param.setAmount(log.getAmount());
|
|
|
+ R r = this.sendRedPacketTest(param);
|
|
|
+ if (r.get("code").equals(200)){
|
|
|
+ log.setOutBatchNo(r.get("orderCode").toString());
|
|
|
+ log.setBatchId(r.get("batchId").toString());
|
|
|
+ redPacketLogMapper.updateFsCourseRedPacketLog(log);
|
|
|
+ logger.info("更新完成:{}",log.getLogId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+// Thread.sleep(30000);
|
|
|
+// List<FsCourseRedPacketLog> logs2 = redPacketLogMapper.selectFail();
|
|
|
+// String appId = "wx414427b10866c04e";
|
|
|
+// for (FsCourseRedPacketLog log : logs){
|
|
|
+// FsUser user = userService.selectFsUserById(log.getUserId());
|
|
|
+// WxSendRedPacketParam param = new WxSendRedPacketParam();
|
|
|
+// param.setAppId(appId);
|
|
|
+// if (user==null || user.getMaOpenId()==null){
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// param.setOpenId(user.getMaOpenId());
|
|
|
+// param.setAmount(log.getAmount());
|
|
|
+// R r = this.sendRedPacketTest(param);
|
|
|
+// if (r.get("code").equals(200)){
|
|
|
+// log.setOutBatchNo(r.get("orderCode").toString());
|
|
|
+// log.setBatchId(r.get("batchId").toString());
|
|
|
+// redPacketLogMapper.updateFsCourseRedPacketLog(log);
|
|
|
+// logger.info("更新完成:{}",log.getLogId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R sendRewardByTest(Long userId) {
|
|
|
+ List<FsCourseRedPacketLog> logs = redPacketLogMapper.selectFail(userId);
|
|
|
+ String appId = "wx414427b10866c04e";
|
|
|
+ for (FsCourseRedPacketLog log : logs) {
|
|
|
+ FsUser user = userService.selectFsUserById(log.getUserId());
|
|
|
+ WxSendRedPacketParam param = new WxSendRedPacketParam();
|
|
|
+ param.setAppId(appId);
|
|
|
+ if (user == null || user.getMaOpenId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ param.setOpenId(user.getMaOpenId());
|
|
|
+ param.setAmount(log.getAmount());
|
|
|
+ R r = this.sendRedPacketTest(param);
|
|
|
+ if (r.get("code").equals(200)) {
|
|
|
+ log.setOutBatchNo(r.get("orderCode").toString());
|
|
|
+ log.setBatchId(r.get("batchId").toString());
|
|
|
+ redPacketLogMapper.updateFsCourseRedPacketLog(log);
|
|
|
+ logger.info("更新完成:{}", log.getLogId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
}
|