From 1a66508ad3d73dcc456162c553b03f2208570b51 Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Wed, 31 Aug 2022 16:15:54 +0800 Subject: [PATCH] 20220822 --- src/main/java/cc/mrbird/febs/pay/util/WeixinServiceUtil.java | 102 ++++++++++++++++++++++++++------------------------ 1 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/pay/util/WeixinServiceUtil.java b/src/main/java/cc/mrbird/febs/pay/util/WeixinServiceUtil.java index 1125bb7..8da26bb 100644 --- a/src/main/java/cc/mrbird/febs/pay/util/WeixinServiceUtil.java +++ b/src/main/java/cc/mrbird/febs/pay/util/WeixinServiceUtil.java @@ -3,10 +3,9 @@ import cc.mrbird.febs.common.exception.FebsException; import cc.mrbird.febs.common.properties.XcxProperties; import cc.mrbird.febs.common.utils.SpringContextHolder; -import cc.mrbird.febs.pay.model.BrandWCPayRequestData; -import cc.mrbird.febs.pay.model.JsApiPayBusiness; -import cc.mrbird.febs.pay.model.JsApiPayReqData; -import cc.mrbird.febs.pay.model.JsApiPayResData; +import cc.mrbird.febs.pay.model.*; +import cc.mrbird.febs.pay.service.impl.RefundService; +import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -41,14 +40,19 @@ return buildBrandWCPayRequestData(desc, outTradeNo, price, openId, attach, wecharPaynotifyUrl); } + public BrandWCPayRequestData createRechargeWallet(String desc, String outTradeNo, int price, String openId, String attach) throws Exception { + String wecharRechargePaynotifyUrl = xcxProperties.getWecharRechargePaynotifyUrl(); + return buildBrandWCPayRequestData(desc, outTradeNo, price, openId, attach, wecharRechargePaynotifyUrl); + } + private BrandWCPayRequestData buildBrandWCPayRequestData(String desc, String outTradeNo, int price, String openId, String attach, String notifyUrl) throws Exception { // 创建微信支付预付接口 JsApiPayBusiness jsApiPayBusiness = new JsApiPayBusiness(); String idAddr = getIpAddr(WebUtil.getRequest()); - String mchID = WechatConfigure.WECHARPAY_MCHID; - String paySecret = WechatConfigure.WECHARPAY_SECRET; - String appId = WechatConfigure.MINIPROGRAM_APPID; + String mchID = xcxProperties.getWecharpayMchid(); + String paySecret = xcxProperties.getWecharpaySecret(); + String appId = xcxProperties.getXcxAppid(); JsApiPayReqData jsApiPayReqData = new JsApiPayReqData( appId, mchID, paySecret, notifyUrl, desc, @@ -81,48 +85,48 @@ * @param opUserID 操作员id,默认为商户号 * @return */ -// public boolean comRefund(String outTradeNo, String outRefundNo,int totalFee, -// int refundFee, String opUserID){ -// LogUtil.info("#---outTradeNo:{}#---outRefundNo:{}#---totalFee:{}#---refundFee:{}", -// outTradeNo,outRefundNo,totalFee,refundFee); -// BusParameterSettings mchID = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_MCHID, HostInterceptor.getCompanyId()); -// if(opUserID==null){ -// opUserID=mchID.getParamValue(); -// } -// RefundResData result=null; -// boolean flag=false; -// try { -// JsApiPayBusiness jsApiPayBusiness = new JsApiPayBusiness(); -// Long companyId=HostInterceptor.getCompanyId(); -// BusParameterSettings paySecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_SECRET, companyId); -// BusParameterSettings appId = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_APPID, companyId); -// BusParameterSettings certLocalPath = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_CERTLOCAL_PATH, companyId); -// -// RefundReqData refundReqData=new RefundReqData(mchID.getParamValue(),appId.getParamValue(),paySecret.getParamValue(), outTradeNo, outRefundNo, totalFee, refundFee,opUserID); -// RefundService refundService=new RefundService(); -// HttpsRequest2 request2= (HttpsRequest2) refundService.getServiceRequest(); -// request2.setCertLocalPath(certLocalPath.getParamValue()); -// request2.setMchId(mchID.getParamValue()); -// -// result = jsApiPayBusiness.refundComOrder(refundService, refundReqData); -// LogUtil.info("#退款,企业付款到个人---result:{}",result); -// //如果返回余额不足时 -// if (StringUtils.equals(AppConstance.REFUND_FAIL_NOTENOUGH, result.getErr_code())) { -// LogUtil.info("#退款失败,{}!", "商户余额不足"); -// throw new GlobleException("退款失败,请联系管理员!"); -// } -// } catch (Exception e) { -// LogUtil.error("#企业付款到个人异常#退款#outTradeNo:{}#opUserID:{}", e, outTradeNo,opUserID); -// } -// -// if (result.getResult_code().equals(WechatConfigure.SUCCESS)) { -// flag=true; -// }else{ -// flag=false; -// throw new GlobleException(result.getErr_code_des()); -// } -// return flag; -// } + public boolean comRefund(String outTradeNo, String outRefundNo,int totalFee, + int refundFee, String opUserID){ + log.info("#---outTradeNo:{}#---outRefundNo:{}#---totalFee:{}#---refundFee:{}", + outTradeNo,outRefundNo,totalFee,refundFee); + + String mchID = xcxProperties.getWecharpayMchid(); + if(opUserID==null){ + opUserID=mchID; + } + RefundResData result=null; + boolean flag=false; + try { + JsApiPayBusiness jsApiPayBusiness = new JsApiPayBusiness(); + String paySecret = xcxProperties.getWecharpaySecret(); + String appId = xcxProperties.getXcxAppid(); + String certLocalPath = xcxProperties.getCertLocalPath(); + + RefundReqData refundReqData=new RefundReqData(mchID,appId,paySecret, outTradeNo, outRefundNo, totalFee, refundFee,opUserID); + RefundService refundService=new RefundService(); + HttpsRequest2 request2= (HttpsRequest2) refundService.getServiceRequest(); + request2.setCertLocalPath(certLocalPath); + request2.setMchId(mchID); + + result = jsApiPayBusiness.refundComOrder(refundService, refundReqData); + log.info("#退款,企业付款到个人---result:{}",result); + //如果返回余额不足时,商户余额不足时微信返回状态码(退款失败时) + if (StrUtil.equals("NOTENOUGH", result.getErr_code())) { + log.info("#退款失败,{}!", "商户余额不足"); + flag=false; + } + } catch (Exception e) { + log.error("#企业付款到个人异常#退款#outTradeNo:{}#opUserID:{}", e, outTradeNo,opUserID); + flag=false; + } + + if (result.getResult_code().equals("SUCCESS")) { + flag=true; + }else{ + flag=false; + } + return flag; + } /**@Description 支付获取远程设备的ip @date 2017年6月27日 -- Gitblit v1.9.1