parent
334be111f5
commit
e76dc3245a
24 changed files with 206 additions and 132 deletions
File diff suppressed because one or more lines are too long
@ -1,64 +1,71 @@ |
||||
package com.ynxbd.wx.wxfactory.utils; |
||||
|
||||
import com.ynxbd.common.result.ResultEnum; |
||||
import com.ynxbd.common.result.ServiceException; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Slf4j |
||||
public class WxRespHelper { |
||||
|
||||
/** |
||||
* 成功相应 |
||||
*/ |
||||
public static String resp(ServiceException e) { |
||||
if (ResultEnum.PAY_NOTIFY_REPEAT.equals(e.getResultEnum())) { |
||||
return respOk(); |
||||
} |
||||
return respFail(e.getMessage()); |
||||
} |
||||
|
||||
/** |
||||
* 成功响应 |
||||
*/ |
||||
public static String respOk() { |
||||
log.info("【微信回调】通知成功"); |
||||
try { |
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("return_code", "SUCCESS"); |
||||
map.put("return_msg", "OK"); |
||||
return XmlHelper.mapToXml(map); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 失败响应 |
||||
*/ |
||||
private static String respFail(String message) { |
||||
log.info("回调通知: {}", message); |
||||
if (message == null) { |
||||
message = "FAIL"; |
||||
} |
||||
try { |
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("return_code", "FAIL"); |
||||
map.put("return_msg", message); |
||||
return XmlHelper.mapToXml(map); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
// public static void main(String[] args) throws DocumentException {
|
||||
//
|
||||
// TestPay testPay = XmlHelper.xmlToBean(xml, TestPay.class);
|
||||
// System.out.println(testPay);
|
||||
// }
|
||||
} |
||||
package com.ynxbd.wx.wxfactory.utils; |
||||
|
||||
import com.ynxbd.common.bean.enums.MerchantEnum; |
||||
import com.ynxbd.common.result.ResultEnum; |
||||
import com.ynxbd.common.result.ServiceException; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Slf4j |
||||
public class WxNotifyResp { |
||||
public WxNotifyResp(MerchantEnum merchantEnum) { |
||||
this.merchantEnum = merchantEnum; |
||||
} |
||||
|
||||
public final MerchantEnum merchantEnum; |
||||
|
||||
|
||||
/** |
||||
* 成功相应 |
||||
*/ |
||||
public String resp(ServiceException e) { |
||||
if (ResultEnum.PAY_NOTIFY_REPEAT.equals(e.getResultEnum())) { |
||||
return respOk(); |
||||
} |
||||
return respFail(e.getMessage()); |
||||
} |
||||
|
||||
/** |
||||
* 成功响应 |
||||
*/ |
||||
public String respOk() { |
||||
log.info("【{}】通知成功", this.merchantEnum.NAME); |
||||
try { |
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("return_code", "SUCCESS"); |
||||
map.put("return_msg", "OK"); |
||||
return XmlHelper.mapToXml(map); |
||||
} catch (Exception e) { |
||||
log.error("", e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 失败响应 |
||||
*/ |
||||
private String respFail(String message) { |
||||
log.info("【{}】回调通知: {}", this.merchantEnum.NAME, message); |
||||
if (message == null) { |
||||
message = "FAIL"; |
||||
} |
||||
try { |
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("return_code", "FAIL"); |
||||
map.put("return_msg", message); |
||||
return XmlHelper.mapToXml(map); |
||||
} catch (Exception e) { |
||||
log.error("", e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
// public static void main(String[] args) throws DocumentException {
|
||||
//
|
||||
// TestPay testPay = XmlHelper.xmlToBean(xml, TestPay.class);
|
||||
// System.out.println(testPay);
|
||||
// }
|
||||
} |
||||
Loading…
Reference in new issue