| | |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.ID; |
| | | import com.doumee.dao.business.RefundMapper; |
| | | import com.doumee.dao.business.TransactionsMapper; |
| | |
| | | import com.doumee.dao.business.model.Transactions; |
| | | import com.doumee.dao.business.web.request.RefundDTO; |
| | | import com.doumee.dao.system.model.SystemDictData; |
| | | import com.doumee.service.business.RefundService; |
| | | import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; |
| | | import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest; |
| | | import com.github.binarywang.wxpay.bean.result.WxPayRefundResult; |
| | | import com.github.binarywang.wxpay.exception.WxPayException; |
| | | import com.wechat.pay.java.service.refund.model.AmountReq; |
| | | import com.wechat.pay.java.service.refund.model.CreateRequest; |
| | | import com.wechat.pay.java.service.refund.model.QueryByOutRefundNoRequest; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import okhttp3.OkHttpClient; |
| | | import okhttp3.Request; |
| | | import okhttp3.Response; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 微信小程序-公共方法 |
| | |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Autowired |
| | | private WxPayProperties wxPayProperties; |
| | | |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | public Refund wxRefund(RefundDTO refundDTO) { |
| | | public boolean wxRefund(RefundDTO refundDTO) { |
| | | // 发送退款请求 |
| | | Refund refund = new Refund(); |
| | | refund.setId(Constants.getUUID()); |
| | | refund.setCreateDate(new Date()); |
| | | refund.setMemberId(refundDTO.getMemberId()); |
| | | refund.setMoney(refundDTO.getRefundAmount()); |
| | | // refund.setOnlineOrderid(refNum); |
| | | refund.setPayWay(Constants.ZERO); |
| | | refund.setStatus(Constants.ZERO); |
| | | refund.setDoneDate(new Date()); |
| | | refund.setCreator(refundDTO.getCreator()); |
| | | refund.setType(refundDTO.getType()); |
| | | refund.setObjId(refundDTO.getOrderId()); |
| | | refund.setReason(refundDTO.getReason()); |
| | | refund.setCanBalance(refundDTO.getCanBalance()); |
| | | refundMapper.insert(refund); |
| | | |
| | | CreateRequest request = new CreateRequest(); |
| | | request.setOutTradeNo(refundDTO.getOrderId()); |
| | | request.setOutRefundNo(refund.getId()); |
| | | request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId()); |
| | | request.setNotifyUrl(WxMiniConfig.wxProperties.getRefundNotifyUrl()); |
| | | AmountReq amountReq = new AmountReq(); |
| | | amountReq.setTotal(refundDTO.getTotalAmount().longValue()); |
| | | amountReq.setRefund(refundDTO.getRefundAmount().longValue()); |
| | | amountReq.setCurrency("CNY"); |
| | | request.setAmount(amountReq); |
| | | try { |
| | | // 发送退款请求 |
| | | String refNum = ID.nextGUID(); |
| | | WxPayRefundRequest request = new WxPayRefundRequest(); |
| | | request.setOutTradeNo(refundDTO.getOrderId()); |
| | | request.setOutRefundNo(refNum); |
| | | request.setTotalFee(refundDTO.getTotalAmount().intValue()); |
| | | request.setRefundFee(refundDTO.getRefundAmount().intValue()); |
| | | System.out.println("实际总金额" + refundDTO.getTotalAmount()); |
| | | System.out.println("实际退款金额" + refundDTO.getRefundAmount()); |
| | | log.error("=============="+JSONObject.toJSONString(request)); |
| | | com.wechat.pay.java.service.refund.model.Refund response = WxMiniConfig.refundService.create(request); |
| | | log.error("=============="+JSONObject.toJSONString(response)); |
| | | if ("SUCCESS".equals(response.getStatus().name()) |
| | | || "PROCESSING".equals(response.getStatus().name()) ) { |
| | | return true; |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,退款申请失败哦!"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,退款申请失败!"); |
| | | } |
| | | |
| | | } |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | public com.wechat.pay.java.service.refund.model.Refund isSuucessRefund(String outTradeNo) { |
| | | // 发送退款请求 |
| | | |
| | | QueryByOutRefundNoRequest request = new QueryByOutRefundNoRequest(); |
| | | request.setOutRefundNo(outTradeNo); |
| | | request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId()); |
| | | try { |
| | | log.error("=============="+JSONObject.toJSONString(request)); |
| | | com.wechat.pay.java.service.refund.model.Refund response = WxMiniConfig.refundService.queryByOutRefundNo(request); |
| | | log.error("=============="+JSONObject.toJSONString(response)); |
| | | if ("SUCCESS".equals(response.getStatus().name()) |
| | | || "PROCESSING".equals(response.getStatus().name()) ) { |
| | | return response; |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | public Refund wxRefundOld(RefundDTO refundDTO) { |
| | | // 发送退款请求 |
| | | String refNum = ID.nextGUID(); |
| | | CreateRequest request = new CreateRequest(); |
| | | request.setOutTradeNo(refundDTO.getOrderId()); |
| | | request.setOutRefundNo(refNum); |
| | | request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId()); |
| | | request.setNotifyUrl(WxMiniConfig.wxProperties.getRefundNotifyUrl()); |
| | | // |
| | | AmountReq amountReq = new AmountReq(); |
| | | amountReq.setTotal(refundDTO.getTotalAmount().longValue()); |
| | | amountReq.setRefund(refundDTO.getRefundAmount().longValue()); |
| | | amountReq.setCurrency("CNY"); |
| | | request.setAmount(amountReq); |
| | | System.out.println("实际总金额" + refundDTO.getTotalAmount()); |
| | | System.out.println("实际退款金额" + refundDTO.getRefundAmount()); |
| | | // request.setTotalFee(1); |
| | | // request.setRefundFee(1); |
| | | WxPayRefundResult response = WxMiniConfig.wxPayService.refund(request); |
| | | if ("SUCCESS".equals(response.getReturnCode()) && "SUCCESS".equals(response.getResultCode())) { |
| | | try { |
| | | com.wechat.pay.java.service.refund.model.Refund response = WxMiniConfig.refundService.create(request); |
| | | if ("SUCCESS".equals(response.getStatus().name()) ) { |
| | | //存储退款记录 与 流水记录 |
| | | Refund refund = new Refund(); |
| | | refund.setId(Constants.getUUID()); |
| | |
| | | transactionsMapper.insert(transactions); |
| | | return refund; |
| | | } else{ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),response.getErrCode() + response.getErrCodeDes()); |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,退款失败!"); |
| | | } |
| | | } catch (WxPayException e) { |
| | | }catch (BusinessException e){ |
| | | throw e; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,退款失败!"); |
| | | } |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"退款发生异常请联系管理员"); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html |
| | | * @return |
| | | */ |
| | | public void generateWXMiniCode(Locks locks,SystemDictData systemDictData){ |
| | | public void generateWXMiniCode(Locks locks,SystemDictData systemDictData,String prePath,String path){ |
| | | |
| | | if(Objects.isNull(systemDictData)){ |
| | | return; |
| | |
| | | Response response = client.newCall(request).execute(); |
| | | if (response.isSuccessful()) { |
| | | InputStream inputStream = new ByteArrayInputStream(response.body().bytes()); |
| | | // 得到文件大小 |
| | | int i = inputStream.available(); |
| | | byte[] mFileBody = new byte[i]; |
| | | // 读数据 |
| | | inputStream.read(mFileBody); |
| | | locks.setInfo("data:image/Jpeg;base64," + Base64.getEncoder().encodeToString(mFileBody)); |
| | | String nowDate = DateUtil.getNowShortDate(); |
| | | File file = new File(prePath+path,locks.getSiteId()+"-"+locks.getCode()+"-"+nowDate+".png"); |
| | | FileUtils.copyInputStreamToFile(inputStream,file); |
| | | locks.setInfo(locks.getSiteId()+"-"+locks.getCode()+"-"+nowDate+".png"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |