微信app支付 java后台接Android

抽时间整理一下之前项目中的微信app支付,以备以后需要,如果对你可以有点帮助是最好不过的;直接上代码:public class WeChatAppConfig { /** * 预支付请求地址 */ public static final String PrepayUrl = "https://api.mch.weixin.qq.com/pay/uni...
摘要由CSDN通过智能技术生成

抽时间整理一下之前项目中的微信app支付,以备以后需要,如果对你可以有点帮助是最好不过的;

直接上代码:

public class WeChatAppConfig {
	
	 /**
	    * 预支付请求地址
	    */
	   public static final String  PrepayUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";
	 
	   /**
	    * 查询订单地址
	    */
	   public static final String  OrderUrl = "https://api.mch.weixin.qq.com/pay/orderquery";
	 
	   /**
	    * 关闭订单地址
	    */
	   public static final String  CloseOrderUrl = "https://api.mch.weixin.qq.com/pay/closeorder";
	 
	   /**
	    * 申请退款地址
	    */
	   public static final String  RefundUrl = "https://api.mch.weixin.qq.com/secapi/pay/refund";
	 
	   /**
	    * 查询退款地址
	    */
	   public static final String  RefundQueryUrl = "https://api.mch.weixin.qq.com/pay/refundquery";
	 
	   /**
	    * 下载账单地址
	    */
	   public static final String  DownloadBillUrl = "https://api.mch.weixin.qq.com/pay/downloadbill";
	 
	   /**
	    * 商户APPID
	    */
	   public static final String  AppId = "此处是商户appid";
	 
	   /**
	    * 商户账户 获取支付能力后,从邮件中得到
	    */
	   public static final String  MchId = "此处是mchid";
	 
	   /**
	    * 商户秘钥  32位,在微信商户平台中设置 api安全下的设置密钥(不是开放平台 )  注意!!! 注意!!!!
	    */
	   public static final String  AppSercret = "此处是商户密钥";
	 
	   /**
	    * sign type
	    */
	   public static final String  Sign = "MD5";
	   
	   /**
	    * 服务器异步通知页面路径
	    */
	  public static String notify_url = "http://catering.saimark.xusage.com/catering/a/****** (为后台url)";
	 
	   /**
	    * 页面跳转同步通知页面路径
	    */
	   public static String return_url = "此处为后台url";
	 
	   /**
	    * 退款通知地址
	    */
	   public static String refund_notify_url = "此处为后台url";
	 
	   /**
	    * 退款需要证书文件,证书文件的地址
	    */
	   public static String refund_file_path = "此处为后台url";
	 
	   /**
	    * 商品名称
	    */
	   public static String subject =  "subject(自己按需要更改,也可以传值进入)";
	 
	   /**
	    * 商品描述
	    */
	   public static String body = "微信支付(自己按需要更改,也可以传值进入)";
	 
	/*   private static  Properties properties;
	 
	   public static synchronized Properties getProperties(){
	      if(properties == null){
	         String path = System.getenv(RSystemConfig.KEY_WEB_HOME_CONF) + "/weichart.properties";
	         properties = PropertiesUtil.getInstance().getProperties(path);
	      }
	      return properties;
*/

}

HttpClientUtil:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyStore;
import java.util.Map;

import javax.net.ssl.SSLContext;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class HttpClientUtil {

	public static String post(String url, Map<String, String> headMap, Map<String, String> params) {
		try {
			HttpClient httpclient = new HttpClient();
			httpclient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
			PostMethod httpPost = new PostMethod(url);
			if (null != headMap) {
				for (String key : headMap.keySet()) {
					httpPost.setRequestHeader(key, headMap.get(key));
				}
			}

			if (null != params) {
				for (String pkey : params.keySet()) {
					httpPost.addParameter(pkey, params.get(pkey));
				}
			}
			httpclient.executeMethod(httpPost);

			BufferedReader reader = new BufferedReader(new InputStreamReader(httpPost.getResponseBodyAsStream()));
			StringBuffer stringBuffer = new StringBuffer();
			String str = "";
			while ((str = reader.readLine()) != null) {
				stringBuffer.append(str);
			}
			reader.close();
			return stringBuffer.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String postHttplient(String url, String xmlInfo) {
		try {
			HttpClient httpclient = new HttpClient();
			httpclient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
			PostMethod httpPost = new PostMethod(url);
			httpPost.setRequestEntity(new StringRequestEntity(xmlInfo));
			httpclient.executeMeth
  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值