| 
					
				 | 
			
			
				@@ -18,6 +18,7 @@ import com.yonge.toolset.utils.string.StringUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.util.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.Arrays; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.HashMap; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -90,21 +91,29 @@ public class PaymentSdk { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return 关闭的支付对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @throws Exception 异常 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public Map<String, Object> closePayment(String paymentId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Map<String, Object> payment = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public HttpResponseResult<Map<String, Object>> closePayment(String paymentId, String reason, String expend) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String, Object> paymentParams = new HashMap<>(10); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         paymentParams.put("payment_id", paymentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        paymentParams.put("reason", "reason"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        paymentParams.put("expend", "expend"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        paymentParams.put("notify_url", "notify_url"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        payment = com.huifu.adapay.model.Payment.close(paymentParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        paymentParams.put("reason", reason); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        paymentParams.put("expend", expend); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        paymentParams.put("notify_url", HuifuConfiguration.getHuifuProperties().getNotifyUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String error_code = (String) payment.get("error_code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (null != error_code) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            String errorMsg = (String) payment.get("error_msg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            throw new ThirdpartyException(errorMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, Object> res; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = Payment.close(paymentParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (BaseAdaPayException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return HttpResponseResult.failed(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return payment; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (CollectionUtils.isEmpty(res)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return HttpResponseResult.failed("请求失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("汇付[关闭支付对象] Resp:{}", res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String errorCode = (String) res.get("error_code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (null != errorCode) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String errorMsg = (String) res.get("error_msg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return HttpResponseResult.failed(errorMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return HttpResponseResult.succeed(res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -171,6 +180,44 @@ public class PaymentSdk { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 退款 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 关闭的支付对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public HttpResponseResult<Map<String, Object>> refundPayment(RefundReq refundReq) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        refundReq.setFail_fast("Y"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //创建分账对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, String> div_member = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        div_member.put("member_id", "0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        div_member.put("amount", refundReq.getRefund_amt()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        div_member.put("fee_flag", "Y"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Map<String, String>> div_members = Arrays.asList(div_member); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        refundReq.setDiv_members(JSONObject.toJSONString(div_members)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("汇付[退款对象] Req:{}", JSONObject.toJSONString(refundReq)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //调用sdk方法,创建退款,得到退款对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, Object> paymentParams = MapUtil.populateMap(new HashMap<>(), refundReq); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, Object> res; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = Refund.create(refundReq.getId(),paymentParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (BaseAdaPayException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return HttpResponseResult.failed(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (null == res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return HttpResponseResult.failed("请求失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("汇付[创建退款对象] Resp:{}", res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String errorCode = (String) res.get("error_code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (null != errorCode) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String errorMsg = (String) res.get("error_msg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return HttpResponseResult.failed(errorMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return HttpResponseResult.succeed(res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      *  查看退款订单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 |