微信支付 全套流程看完就会 pc扫码支付

package com........util;

import java.util.Iterator;

import java.util.Map;

import java.util.Set;

import java.util.SortedMap;

import javax.servlet.http.HttpServletRequest;

public class ConstantUtil {

/**

* 商家可以考虑读取配置文件

*/

public static String GATEURL = "https://api.mch.weixin.qq.com/pay/unifiedorder";//获取预支付id的接口url

public static String QUERYURL = "https://api.mch.weixin.qq.com/pay/orderquery";//获取微信支付订单支付情况url

public static String BODY="";//支付介绍看微信介绍

//微信扫码支付配置--start--微信公众平台APPID

public static String WECHAT_APP_ID="";//公司提供

public static String WECHAT_MCH_ID="";//公司提供

public static String WECHAT_APP_KEY="";//公司提供微信公众平台支付商户平台系统内的API密钥

public static String WECHAT_NOTIFY_URL="http://www.*******.com/weixinPayReturn";//微信扫码支付配置 回调路径--end--

public static String createSign(String Encoding, SortedMap parameters){

StringBuffer sb = new StringBuffer();

Set es = parameters.entrySet();

Iterator it = es.iterator();

while(it.hasNext()) {

Map.Entry entry = (Map.Entry)it.next();

String k = (String)entry.getKey();

Object v = entry.getValue();

if(null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {

sb.append(k + "=" + v + "&");

}

}

sb.append("key=" + ConstantUtil.WECHAT_APP_KEY);

String sign = MD5Util.MD5Encode(sb.toString(), Encoding).toUpperCase();

return sign;

}

public static boolean IsNumeric(String str) {

return str.matches("\\d *");

}

public static String parametersToXml(Map parameters) {

String xml = "";

Set es = parameters.entrySet();

Iterator it = es.iterator();

while(it.hasNext()) {

Map.Entry entry = (Map.Entry)it.next();

String key = (String)entry.getKey();

String val = (String)entry.getValue();

if(IsNumeric(val)) {

xml = xml + "<" + key + ">" + val + "";

} else {

xml = xml + "<" + key + ">";

}

}

xml = xml + "";

return xml;

}

public static String generateString(int length) {

StringBuffer sb = new StringBuffer();

Random random = new Random();

for (int i = 0; i < length; i++) {

sb.append(ALLCHAR.charAt(random.nextInt(ALLCHAR.length())));

}

return sb.toString();

}

public static String getIpAddress(HttpServletRequest request) {

String ip = request.getHeader("x-forwarded-for");

if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {

ip = request.getHeader("Proxy-Client-IP");

}

if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {

ip = request.getHeader("WL-Proxy-Client-IP");

}

if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {

ip = request.getHeader("HTTP_CLIENT_IP");

}

if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {

ip = request.getHeader("HTTP_X_FORWARDED_FOR");

}

if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {

ip = request.getRemoteAddr();

}

return ip.equals("0:0:0:0:0:0:0:1")?"127.0.0.1":ip;

}

}