| package com.matrix.component.wechat.externalInterface.business; | 
|   | 
| import com.matrix.component.wechat.externalInterface.common.Util; | 
| import com.matrix.component.wechat.externalInterface.protocol.payComProtocol.JsApiPayComReqData; | 
| import com.matrix.component.wechat.externalInterface.protocol.payComProtocol.JsApiPayComResData; | 
| import com.matrix.component.wechat.externalInterface.protocol.payProtocol.JsApiPayReqData; | 
| import com.matrix.component.wechat.externalInterface.protocol.payProtocol.JsApiPayResData; | 
| import com.matrix.component.wechat.externalInterface.protocol.queryProtocol.ScanPayQueryReqData; | 
| import com.matrix.component.wechat.externalInterface.protocol.queryProtocol.ScanPayQueryResData; | 
| import com.matrix.component.wechat.externalInterface.protocol.refundProtocol.RefundReqData; | 
| import com.matrix.component.wechat.externalInterface.protocol.refundProtocol.RefundResData; | 
| import com.matrix.component.wechat.externalInterface.service.JsApiPayComService; | 
| import com.matrix.component.wechat.externalInterface.service.JsApiPayService; | 
| import com.matrix.component.wechat.externalInterface.service.RefundService; | 
| import com.matrix.component.wechat.externalInterface.service.ScanPayQueryService; | 
| import org.apache.log4j.Logger; | 
|   | 
| /** | 
|  * User: rizenguo Date: 2014/12/1 Time: 17:05 | 
|  */ | 
| public class JsApiPayBusiness { | 
|   | 
|     private JsApiPayService jsApiPayService; | 
|   | 
|      | 
|     //打log用 | 
|     Logger log=Logger.getLogger(JsApiPayBusiness.class); | 
|      | 
|     public JsApiPayBusiness() throws Exception { | 
|         jsApiPayService = new JsApiPayService(); | 
|     } | 
|      | 
|      | 
|   | 
|     /** | 
|      *  | 
|      * 生成预付订单 | 
|      * @author:姜友瑶 | 
|      * @param scanPayReqData | 
|      *            返回类型 void | 
|      * @throws Exception | 
|      * @date 2016年10月13日 | 
|      */ | 
|     public JsApiPayResData createPrapareOrder(JsApiPayReqData jsApiPayReqData) throws Exception { | 
|         // 接受API返回 | 
|         String payServiceResponseString; | 
|          | 
|         long costTimeStart = System.currentTimeMillis(); | 
|   | 
|         payServiceResponseString = jsApiPayService.request(jsApiPayReqData); | 
|          | 
|         long costTimeEnd = System.currentTimeMillis(); | 
|         long totalTimeCost = costTimeEnd - costTimeStart; | 
|          | 
|         log.info("------------------request createPrapareOrder taking :" + totalTimeCost + "ms"+"--response="+payServiceResponseString); | 
|   | 
|         // 将从API返回的XML数据映射到Java对象 | 
|         JsApiPayResData jsApiPayResData = (JsApiPayResData) Util.getObjectFromXML(payServiceResponseString, | 
|                 JsApiPayResData.class); | 
|          | 
|         return jsApiPayResData; | 
|     } | 
|      | 
|     /** | 
|      *  | 
|      * 支付成功后查询微信订单 | 
|      * @author:jiangyouyao | 
|      * @param scanPayReqData | 
|      *            返回类型 void | 
|      * @throws Exception | 
|      * @date 2016年10月13日 | 
|      */ | 
|     public ScanPayQueryResData queryPrapareOrder(ScanPayQueryService scanPayQueryService ,ScanPayQueryReqData scanPayQueryReqData) throws Exception { | 
|         // 接受API返回 | 
|         String payServiceResponseString; | 
|          | 
|         long costTimeStart = System.currentTimeMillis(); | 
|   | 
|         payServiceResponseString = scanPayQueryService.request(scanPayQueryReqData); | 
|          | 
|         long costTimeEnd = System.currentTimeMillis(); | 
|         long totalTimeCost = costTimeEnd - costTimeStart; | 
|          | 
|         log.info("------------------request createPrapareOrder taking :" + totalTimeCost + "ms"+"--response="+payServiceResponseString); | 
|          | 
|         // 将从API返回的XML数据映射到Java对象 | 
|         ScanPayQueryResData scanPayQueryResData = (ScanPayQueryResData) Util.getObjectFromXML(payServiceResponseString, | 
|                 ScanPayQueryResData.class); | 
|          | 
|         return scanPayQueryResData; | 
|     } | 
|      | 
|      | 
|     /** | 
|      *  | 
|      * 专家提现,商家向用户(该系统中的专家)支付 | 
|      * @author:jiangyouyao | 
|      * @param scanPayReqData | 
|      *            返回类型 void | 
|      * @throws Exception | 
|      * @date 2017年5月25日 | 
|      */ | 
|     public JsApiPayComResData payComOrder(JsApiPayComService jsApiPayComService ,JsApiPayComReqData jsApiPayComReqData) throws Exception { | 
|         // 接受API返回 | 
|         String payServiceResponseString; | 
|          | 
|         long costTimeStart = System.currentTimeMillis(); | 
|   | 
|         payServiceResponseString = jsApiPayComService.request(jsApiPayComReqData); | 
|          | 
|         long costTimeEnd = System.currentTimeMillis(); | 
|          | 
|         long totalTimeCost = costTimeEnd - costTimeStart; | 
|          | 
|         log.info("------------------request createPrapareOrder taking :" + totalTimeCost + "ms"+"--response="+payServiceResponseString); | 
|          | 
|         // 将从API返回的XML数据映射到Java对象 | 
|         JsApiPayComResData jsApiPayComResData = (JsApiPayComResData) Util.getObjectFromXML(payServiceResponseString, | 
|                 JsApiPayComResData.class); | 
|          | 
|         return jsApiPayComResData; | 
|     } | 
|      | 
|      | 
|     /** | 
|      *  | 
|      * 退款,商家向用户(该系统中的专家)支付 | 
|      * @author:jiangyouyao | 
|      * @param scanPayReqData | 
|      *            返回类型 void | 
|      * @throws Exception | 
|      * @date 2017年5月25日 | 
|      */ | 
|     public RefundResData refundComOrder(RefundService refundService ,RefundReqData refundReqData) throws Exception { | 
|         // 接受API返回 | 
|         String payServiceResponseString; | 
|          | 
|         long costTimeStart = System.currentTimeMillis(); | 
|   | 
|         payServiceResponseString = refundService.request(refundReqData); | 
|          | 
|         long costTimeEnd = System.currentTimeMillis(); | 
|          | 
|         long totalTimeCost = costTimeEnd - costTimeStart; | 
|          | 
|         log.info("------------------request createPrapareOrder taking :" + totalTimeCost + "ms"+"--response="+payServiceResponseString); | 
|          | 
|         // 将从API返回的XML数据映射到Java对象 | 
|         RefundResData RefundResData = (RefundResData) Util.getObjectFromXML(payServiceResponseString, | 
|                 RefundResData.class); | 
|          | 
|         return RefundResData; | 
|     } | 
|   | 
|   | 
| } |