public void wxpay() {
ApWxPayDTO awp = new ApWxPayDTO();
awp.setBody(subject);
awp.setOutTradeNo(outTradeNo);
awp.setTotalFee(100);
String rootPath = “”;
awp.setNotifyUrl(rootPath + "/lm/payment/wxnotify");
try {
Map<String, String> resultMap = wxPayService.unifiedOrder(awp);
if ("SUCCESS".equals(resultMap.get("return_code"))) {
if ("SUCCESS".equalsIgnoreCase(resultMap.get("result_code"))) {
String codeUrl = resultMap.get("code_url");
} else {
throw new BusinessException("交易失败!");
}
} else {
throw new BusinessException("通信失败!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public Map<String, String> wxnotify(HttpServletRequest request, HttpServletResponse response) {
String resXml = "";
InputStream inStream;
Map<String, String> returnMap = new HashMap<String, String>();
try {
inStream = request.getInputStream();
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outSteam.write(buffer, 0, len);
}
String result = new String(outSteam.toByteArray(), WXPayConstants.CHARSET);
outSteam.close();
inStream.close();
returnMap = wxPayService.isSignatureValid(result);
resXml = returnMap.get("resXml");
} catch (Exception e) {
throw new BusinessException("支付回调异常", e);
} finally {
try {
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
out.write(resXml.getBytes());
out.flush();
out.close();
} catch (IOException e) {
throw new BusinessException("支付回调异常", e);
}
}
return returnMap;
}
public class WxPayService extends BaseService {
public Map<String, String> getWXParameter() {
Map<String, String> map = new HashMap<String, String>();
String wxAppId = ApApiFacadeHolder.getApApiFacade().getSysControl("wxAppId");
String wxMchId = ApApiFacadeHolder.getApApiFacade().getSysControl("wxMchId");
String wxApiKey = ApApiFacadeHolder.getApApiFacade().getSysControl("wxApiKey");
map.put("appid", wxAppId);
map.put("mch_id"