payConfig
public class PayConfigUtil {String APP_ID = "wx632c8f211f8122c6";//微信公众号的id
String MCH_ID = "1497984412";//商户id
String API_KEY = "sbNCm1JnevqI36LrEaxFwcaT0hkGxFnC";//API密钥
String UFDOOER_URL =
"https://api.mch.weixin.qq.com/pay/unifiedorder";//微信的统一下单地址
String NOTIFY_URL = "http://139.196.100.189:8080/weixinpay/payment/result";//回调地址
String CREATE_IP = "117.159.15.221";
}
package com.zms.util;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
XMLUtil
public class XMLUtil {
public static Map doXMLParse(String strxml) throws JDOMException, IOException {
strxml = strxml.replaceFirst("encoding=\".*\"", "encoding=\"UTF-8\"");
if(null == strxml || "".equals(strxml)) {
return null;
}
Map m = new HashMap();
InputStream in = new ByteArrayInputStream(strxml.getBytes("UTF-8"));
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(in);
Element root = doc.getRootElement();
List list = root.getChildren();
Iterator it = list.iterator();
while(it.hasNext()) {
Element e = (Element) it.next();
String k = e.getName();
String v = "";
List children = e.getChildren();
if(children.isEmpty()) {
v = e.getTextNormalize();
} else {
v = XMLUtil.getChildrenText(children);
}
m.put(k, v);
}
//关闭流
in.close();
return m;
}
/**
* 获取子结点的xml
* @param children
* @return String
*/
public static String getChildrenText(List children) {
StringBuffer sb = new StringBuffer();
if(!children.isEmpty()) {
Iterator it = children.iterator();
while(it.hasNext()) {
Element e = (Element) it.next();
String name = e.getName();
String value = e.getTextNormalize();
List list = e.getChildren();
sb.append("<" + name + ">");
if(!list.isEmpty()) {
sb.append(XMLUtil.getChildrenText(list));
}
sb.append(value);
sb.append("</" + name + ">");
}
}
return sb.toString();
}
}
buyservlet
package com.zms.servlet;
import com.sun.javaws.jnl.XMLUtils;
BuyServlet
public class BuyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
}
public void weixin_notify(HttpServletRequest request,HttpServletResponse response) throws IOException {
String writeContent = "默认支付失败";
//微信支付图片 保存
String path = request.getServletContext().getRealPath("file");
File files = new File(path);
if(!files.exists()){
files.mkdirs();
}
//将结果写入文件中,实际开发删除
FileOutputStream fos = new FileOutputStream(path + "/result.txt",true);
StringBuffer sb = new StringBuffer();
InputStream input;
input = request.getInputStream();
String s;
BufferedReader reader = new BufferedReader(new InputStreamReader(input,"UTF-8"));
while((s=reader.readLine()) != null){
sb.append(s);
}
reader.close();
input.close();
//解析xml文件成map文件
Map<String,String> map = new HashMap<String, String>();
}
}