资源简介
微信公众号支付需要到的工具类和我个人支付的代码都在里面。
博客:http://blog.csdn.net/aofavx/article/details/52220394
博客:http://blog.csdn.net/aofavx/article/details/52220394
代码片段和文件信息
package com.weixin;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import com.pay.tenpay.util.http.HttpClientConnectionManager;
/**
* 微信支付订单处理类
* @author aofavx
*/
@SuppressWarnings(“deprecation“)
public class GetWxOrderno
{
public static DefaultHttpClient httpclient;
static
{
httpclient = new DefaultHttpClient();
httpclient = (DefaultHttpClient)HttpClientConnectionManager.getSSLInstance(httpclient);
}
/**
* 提交数据到统一支付接口,获取微信生成的统一支付订单号
* @param url
* @param xmlParam
* @return
*/
@SuppressWarnings(“rawtypes“)
public static String getPayNo(String urlString xmlParam){
DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS true);
HttpPost httpost= HttpClientConnectionManager.getPostMethod(url);
String prepay_id = ““;
try {
httpost.setEntity(new StringEntity(xmlParam “UTF-8“));
HttpResponse response = httpclient.execute(httpost);
String jsonStr = EntityUtils.toString(response.getEntity() “UTF-8“);
if(jsonStr.indexOf(“FAIL“)!=-1){
return prepay_id;
}
Map map = doxmlParse(jsonStr);
prepay_id = (String) map.get(“prepay_id“);
} catch (Exception e) {
e.printStackTrace();
}
return prepay_id;
}
/**
* 解析xml返回第一级元素键值对。如果第一级元素有子节点,则此节点的值是子节点的xml数据。
* @param strxml
* @return
* @throws JDOMException
* @throws IOException
*/
public static Map doxmlParse(String strxml) throws Exception {
if(null == strxml || ““.equals(strxml)) {
return null;
}
Map m = new HashMap();
InputStream in = String2Inputstream(strxml);
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 = getChildrenText(children);
}
m.put(k URLDecoder.decode(v“utf-8“));
}
//关闭流
in.close();
return m;
}
/**
* 获取子结点的xml
* @param children
* @return String
*/
public static String getChildrenText(List children) {
StringB
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3771 2016-08-18 15:06 GetWxOrderno.java
文件 1498 2016-08-16 17:45 pay.jsp
文件 147 2018-08-16 00:38 README.md
目录 0 2018-08-16 00:38 util\
文件 4523 2016-08-18 15:03 util\GetWxOrderno.java
目录 0 2018-08-16 00:38 util\http\
文件 2048 2016-08-18 15:03 util\http\HttpClientConnectionManager.java
文件 1890 2016-08-18 15:02 util\http\HttpConnect.java
文件 3516 2016-08-18 15:02 util\http\HttpRequest.java
文件 1803 2016-08-18 15:02 util\http\HttpResponse.java
文件 713 2016-08-18 15:02 util\http\HttpResultType.java
文件 1249 2016-08-18 15:02 util\http\MySSLSocketFactory.java
文件 602 2016-08-18 15:02 util\http\TrustAnyTrustManager.java
文件 1167 2016-08-18 15:03 util\MD5Util.java
文件 6797 2016-08-18 15:03 util\RequestHandler.java
文件 2108 2016-08-18 15:03 util\Sha1Util.java
文件 1079 2016-08-18 15:03 util\TenpayConfig.java
文件 3692 2016-08-18 15:03 util\TenpayUtil.java
文件 16185 2016-08-18 15:07 WechatActivityController.java
- 上一篇:ocjp认证之1Z0-808笔记
- 下一篇:2019年阿里云ACP云计算认证考试题库
评论
共有 条评论