use of com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult in project fw-cloud-framework by liuweijw.
the class WxSendRedpackServiceImpl method sendRedpack.
@Override
public R<Map<String, Object>> sendRedpack(PaySendRedpack paySendRedpack, WxPaySendRedpackRequest sendRedpackRequest) {
Map<String, Object> returnMap = new HashMap<String, Object>();
// 设置会出现签名加密返回
returnMap.put(PayConstant.RETURN_PARAM_RETCODE, PayConstant.RETURN_VALUE_SUCCESS);
returnMap.put("return_code", PayConstant.RETURN_VALUE_FAIL);
returnMap.put("return_msg", "请求出现异常!");
boolean isCommonRedPack = paySendRedpack.getRedPackType().intValue() == 0;
String resKey = paySendRedpack.getResKey();
String logPrefix = isCommonRedPack ? "【发放普通红包】" : "【发放裂变红包】";
try {
log.info(logPrefix + "请求:" + sendRedpackRequest.toString());
WxPayService wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(paySendRedpack.getWxPayConfig());
WxPaySendRedpackResult paySendRedpackResult = wxPayService.sendRedpack(sendRedpackRequest);
paySendRedpack.setReturnCode(paySendRedpackResult.getReturnCode());
paySendRedpack.setReturnMsg(paySendRedpackResult.getReturnMsg());
paySendRedpack.setResultCode(paySendRedpackResult.getResultCode());
paySendRedpack.setErrCode(paySendRedpackResult.getErrCode());
paySendRedpack.setErrCodeDes(paySendRedpackResult.getErrCodeDes());
// 订单流水号
returnMap.put("send_order_id", paySendRedpack.getSendOrderId());
// 订单编号
returnMap.put("mch_order_no", paySendRedpack.getMchOrderNo());
returnMap.put("return_code", paySendRedpackResult.getReturnCode());
returnMap.put("return_msg", paySendRedpackResult.getReturnMsg());
returnMap.put("result_code", paySendRedpackResult.getResultCode());
returnMap.put("err_code", paySendRedpackResult.getErrCode());
returnMap.put("err_code_des", paySendRedpackResult.getErrCodeDes());
if (PayConstant.RETURN_VALUE_SUCCESS.equals(paySendRedpackResult.getReturnCode()) && PayConstant.RETURN_VALUE_SUCCESS.equals(paySendRedpackResult.getResultCode())) {
paySendRedpack.setWxTotalAmount(paySendRedpackResult.getTotalAmount());
paySendRedpack.setSendListid(paySendRedpackResult.getSendListid());
paySendRedpack.setSendTime(paySendRedpackResult.getSendTime());
returnMap.put("total_amount", paySendRedpackResult.getTotalAmount());
returnMap.put("send_listid", paySendRedpackResult.getSendListid());
returnMap.put("send_time", paySendRedpackResult.getSendTime());
log.info(logPrefix + "响应:" + JSON.toJSONString(returnMap));
log.info(logPrefix + "结果:" + PayConstant.RETURN_VALUE_SUCCESS);
} else {
log.info(logPrefix + "响应:" + JSON.toJSONString(returnMap));
log.info(logPrefix + "结果:" + PayConstant.RETURN_VALUE_FAIL);
}
// 保存 发送明细数据入库
paySendRedpackRepository.saveAndFlush(paySendRedpack);
return new R<Map<String, Object>>().data(PayUtil.makeRetData(returnMap, resKey)).success();
} catch (WxPayException e) {
e.printStackTrace();
return new R<Map<String, Object>>().data(PayUtil.makeRetData(returnMap, resKey)).failure(logPrefix + "请求异常:" + e.toString());
}
}
Aggregations