From 3868b706ee3ee115a400d77abc3b69b83ea448c7 Mon Sep 17 00:00:00 2001
From: jyy <jyy>
Date: Fri, 03 Sep 2021 14:15:36 +0800
Subject: [PATCH] bug123

---
 zq-erp/src/main/java/com/matrix/component/wechat/externalInterface/weixinUtil/WeixinServiceUtil.java |  101 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 83 insertions(+), 18 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/component/wechat/externalInterface/weixinUtil/WeixinServiceUtil.java b/zq-erp/src/main/java/com/matrix/component/wechat/externalInterface/weixinUtil/WeixinServiceUtil.java
index 771333f..82d2c05 100644
--- a/zq-erp/src/main/java/com/matrix/component/wechat/externalInterface/weixinUtil/WeixinServiceUtil.java
+++ b/zq-erp/src/main/java/com/matrix/component/wechat/externalInterface/weixinUtil/WeixinServiceUtil.java
@@ -1,5 +1,6 @@
 package com.matrix.component.wechat.externalInterface.weixinUtil;
 
+import com.matrix.component.wechat.externalInterface.common.HttpsRequest2;
 import com.matrix.core.exception.GlobleException;
 import com.matrix.core.tools.LogUtil;
 import com.matrix.core.tools.StringUtils;
@@ -18,7 +19,10 @@
 import com.matrix.component.wechat.externalInterface.service.JsApiPayComService;
 import com.matrix.component.wechat.externalInterface.service.RefundService;
 import com.matrix.component.wechat.externalInterface.service.ScanPayQueryService;
+import com.matrix.system.common.bean.BusParameterSettings;
 import com.matrix.system.common.constance.AppConstance;
+import com.matrix.system.common.dao.BusParameterSettingsDao;
+import com.matrix.system.common.interceptor.HostInterceptor;
 import com.matrix.system.shopXcx.api.tools.WxShopOrderUtil;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +47,13 @@
 
 	@Autowired
 	private WxShopOrderUtil wxShopOrderUtil;
+
+	@Autowired
+	BusParameterSettingsDao busParameterSettingsDao;
+
+
+
+
 	
 	/**
 	 * 支付"175.9.82.254"
@@ -58,11 +69,41 @@
 	 * @return 预支付订单返回的结果对象(该结果对象已封装),在H5页面使用该对象信息
 	 * @throws Exception
 	 */
-	public BrandWCPayRequestData createOrder(String desc,String outTradeNo, int price, String openId,String attach) throws Exception {
+	public BrandWCPayRequestData createOrder(String desc, String outTradeNo, int price, String openId, String attach) throws Exception {
+		Long companyId=HostInterceptor.getCompanyId();
+		BusParameterSettings notifyUrl = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_NOTIFYURL, companyId);
+		return buildBrandWCPayRequestData(desc, outTradeNo, price, openId, attach, notifyUrl);
+	}
+
+	/**
+	 * 创建充值订单
+	 */
+	public BrandWCPayRequestData createRechargeOrder(String desc, String outTradeNo, int price, String openId, String attach) throws Exception {
+		Long companyId=HostInterceptor.getCompanyId();
+		BusParameterSettings notifyUrl = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_RECHARGE_NOTIFYURL, companyId);
+		return buildBrandWCPayRequestData(desc, outTradeNo, price, openId, attach, notifyUrl);
+	}
+
+
+
+	private BrandWCPayRequestData buildBrandWCPayRequestData(String desc, String outTradeNo, int price, String openId, String attach, BusParameterSettings notifyUrl) throws Exception {
 		// 创建微信支付预付接口
 		JsApiPayBusiness jsApiPayBusiness = new JsApiPayBusiness();
 		String idAddr = getIpAddr(WebUtil.getRequest());
-		JsApiPayReqData jsApiPayReqData = new JsApiPayReqData(desc, outTradeNo, price, idAddr, openId, attach);
+
+		Long companyId=HostInterceptor.getCompanyId();
+
+		BusParameterSettings mchID = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_MCHID, companyId);
+		BusParameterSettings paySecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_SECRET, companyId);
+
+
+		BusParameterSettings appId = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_APPID, companyId);
+
+		JsApiPayReqData jsApiPayReqData = new JsApiPayReqData(appId.getParamValue(),mchID.getParamValue(),
+				paySecret.getParamValue(),
+				notifyUrl.getParamValue(),
+				desc, outTradeNo, price, idAddr, openId, attach);
+
 		// 创建预付订单并返回请求结果
 		JsApiPayResData result = jsApiPayBusiness.createPrapareOrder(jsApiPayReqData);
 		// 把预付订单的信息存放在request域中
@@ -71,17 +112,16 @@
 		LogUtil.info("#---签名信息:return_msg = {}" , result.getReturn_msg());
 		if (result.getReturn_code().equals("SUCCESS")) {
 			// 请求成功, 构建BrandWCPayRequest发起支付需要的参数
-			BrandWCPayRequestData payData = new BrandWCPayRequestData(result.getPrepay_id());
+			BrandWCPayRequestData payData = new BrandWCPayRequestData(result.getPrepay_id(),appId.getParamValue(),paySecret.getParamValue());
 			WebUtil.getRequest().setAttribute("payData", payData);
 			return payData;
 		}else{
 			LogUtil.error("创建微信支付订单失败msg={}",result.getReturn_msg());
 			throw new GlobleException("创建微信支付订单失败,请检查程序配置");
 		}
-
 	}
-	
-	
+
+
 	/**@Description 支付后,向微信发送请求、查询订单,看订单是否真的支付成功了
 	   @date 2017年6月27日
 	   @atuhor jiangyouyao
@@ -115,19 +155,34 @@
 	 * @param desc 描述
 	 * @param outTradeNo  提现申请编号
 	 * @param totalFee 提现金额(分)
-	 * @param spBillCreateIP 调用接口的IP
 	 * @param openid
 	 * @return
 	 */
-	public JsApiPayComResData comPay(String desc, String outTradeNo,int totalFee, String openid){
+	public JsApiPayComResData comPay(String desc, String outTradeNo,int totalFee, String openid,Long companyId){
 		JsApiPayComResData result=null;
-		//boolean flag=false;
 		try {
 			JsApiPayBusiness jsApiPayBusiness = new JsApiPayBusiness();
 			// TODO 企业付款
-			JsApiPayComReqData jsApiPayComReqData=new JsApiPayComReqData("","",0,"","","");
+
+			BusParameterSettings mchID = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_MCHID, companyId);
+			BusParameterSettings appId = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_APPID, companyId);
+			BusParameterSettings paySecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_SECRET, companyId);
+
+			BusParameterSettings certLocalPath = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_CERTLOCAL_PATH, companyId);
+
+			JsApiPayComReqData jsApiPayComReqData=new JsApiPayComReqData(mchID.getParamValue(),
+					appId.getParamValue(),
+					paySecret.getParamValue(),
+					desc,outTradeNo,totalFee,openid,"NO_CHECK","");
 			JsApiPayComService jsApiPayComService=new JsApiPayComService();
+
+			HttpsRequest2 request2= (HttpsRequest2) jsApiPayComService.getServiceRequest();
+			request2.setCertLocalPath(certLocalPath.getParamValue());
+			request2.setMchId(mchID.getParamValue());
+
+
 			result = jsApiPayBusiness.payComOrder(jsApiPayComService, jsApiPayComReqData);
+
 			LogUtil.info("#提现,企业付款到个人---result:{}",result);
 			if (result.getResult_code().equals("SUCCESS")) {
 				return result;
@@ -155,15 +210,25 @@
 			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=WechatConfigure.mchID;
+			opUserID=mchID.getParamValue();
 		}
 		RefundResData result=null;
 		boolean flag=false;
 		try {
 			JsApiPayBusiness jsApiPayBusiness = new JsApiPayBusiness();
-			RefundReqData refundReqData=new RefundReqData(outTradeNo, outRefundNo, totalFee, refundFee,opUserID);
+			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);
 			//如果返回余额不足时
@@ -191,12 +256,12 @@
 	 * @return
 	 */
 	public String getIpAddr(HttpServletRequest request) { 
-	       String ip = request.getHeader("x-forwarded-for"); 
-	      /* if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
-	           ip = request.getHeader("Proxy-Client-IP"); 
-	       } 
-	       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
-	           ip = request.getHeader("WL-Proxy-Client-IP"); 
+	       String ip = request.getHeader("x-forwarded-for");
+	      /* if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+	           ip = request.getHeader("Proxy-Client-IP");
+	       }
+	       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+	           ip = request.getHeader("WL-Proxy-Client-IP");
 	       } */
 	       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
 	           ip = request.getRemoteAddr(); 

--
Gitblit v1.9.1