|
@@ -53,6 +53,65 @@ public class WechatUtil {
|
|
|
private static final String URL_PARAM_CONNECT_FLAG = "&";
|
|
|
|
|
|
/**
|
|
|
+ * 菜单类型
|
|
|
+ *
|
|
|
+ * @author Scott
|
|
|
+ * @email
|
|
|
+ * @date 2016年11月15日 下午1:24:29
|
|
|
+ */
|
|
|
+ public enum WXTradeState {
|
|
|
+ /**
|
|
|
+ * 支付成功
|
|
|
+ */
|
|
|
+ SUCCESS("SUCCESS", "支付成功"),
|
|
|
+ /**
|
|
|
+ * 转入退款
|
|
|
+ */
|
|
|
+ REFUND("REFUND", "转入退款"),
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 未支付
|
|
|
+ */
|
|
|
+ NOTPAY("NOTPAY", "未支付"),
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 已关闭
|
|
|
+ */
|
|
|
+ CLOSED("CLOSED", "已关闭"),
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 已撤销(付款码支付)
|
|
|
+ */
|
|
|
+ REVOKED("REVOKED", "已撤销"),
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户支付中(付款码支付)
|
|
|
+ */
|
|
|
+ USERPAYING("USERPAYING", "用户支付中"),
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付失败(付款码支付)
|
|
|
+ */
|
|
|
+ PAYERROR("PAYERROR", "支付失败");
|
|
|
+
|
|
|
+ private String code;
|
|
|
+ private String codeZn;
|
|
|
+
|
|
|
+ private WXTradeState(String code, String codeZn) {
|
|
|
+ this.code = code;
|
|
|
+ this.codeZn = codeZn;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getCode() {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getCodeZn() {
|
|
|
+ return codeZn;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 方法描述:微信退款逻辑
|
|
|
* 创建时间:2017年4月12日 上午11:04:25
|
|
|
* 作者: xubo
|
|
@@ -66,12 +125,13 @@ public class WechatUtil {
|
|
|
BigDecimal bdOrderMoney = new BigDecimal(orderMoney, MathContext.DECIMAL32);
|
|
|
BigDecimal bdRefundMoney = new BigDecimal(refundMoney, MathContext.DECIMAL32);
|
|
|
//构建请求参数
|
|
|
- Map<Object, Object> params = buildRequsetMapParam(out_trade_no, bdOrderMoney, bdRefundMoney);
|
|
|
+ Map<Object, Object> params = buildRefundRequsetMapParam(out_trade_no, bdOrderMoney, bdRefundMoney);
|
|
|
String mapToXml = MapUtils.convertMap2Xml(params);
|
|
|
//请求微信
|
|
|
- String reponseXml = sendSSLPostToWx(mapToXml, WechatConfig.getSslcsf());
|
|
|
- WechatRefundApiResult result = (WechatRefundApiResult) XmlUtil.xmlStrToBean(reponseXml, WechatRefundApiResult.class);
|
|
|
- result.setOut_refund_no((String)params.get("out_refund_no"));
|
|
|
+ String reponseXml = sendRefundSSLPostToWx(mapToXml, WechatConfig.getSslcsf());
|
|
|
+ WechatRefundApiResult result =
|
|
|
+ (WechatRefundApiResult) XmlUtil.xmlStrToBean(reponseXml, WechatRefundApiResult.class);
|
|
|
+ result.setOut_refund_no((String) params.get("out_refund_no"));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -83,13 +143,14 @@ public class WechatUtil {
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- private static Map<Object, Object> buildRequsetMapParam(String out_trade_no, BigDecimal bdOrderMoney, BigDecimal bdRefundMoney) {
|
|
|
+ private static Map<Object, Object> buildRefundRequsetMapParam(String out_trade_no, BigDecimal bdOrderMoney,
|
|
|
+ BigDecimal bdRefundMoney) {
|
|
|
Map<Object, Object> params = new HashMap<Object, Object>();
|
|
|
params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
|
|
|
params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
|
|
|
params.put("nonce_str", CharUtil.getRandomString(16));//随机字符串,不长于32位。推荐随机数生成算法
|
|
|
params.put("out_trade_no", out_trade_no);//商户传给微信的订单号
|
|
|
- params.put("out_refund_no", System.currentTimeMillis()+"");//商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
|
|
|
+ params.put("out_refund_no", System.currentTimeMillis() + "");//商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
|
|
|
params.put("total_fee", bdOrderMoney.multiply(Constant.ONE_HUNDRED).intValue());//订单总金额,单位为分,只能为整数
|
|
|
params.put("refund_fee", bdRefundMoney.multiply(Constant.ONE_HUNDRED).intValue());//退款总金额,订单总金额,单位为分,只能为整数
|
|
|
params.put("op_user_id", CommonWxPayPropertiesBuilder.instance().getMchId());//操作员帐号, 默认为商户号
|
|
@@ -101,12 +162,21 @@ public class WechatUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 请求微信https
|
|
|
+ * 请求退款微信
|
|
|
**/
|
|
|
- public static String sendSSLPostToWx(String mapToXml, SSLConnectionSocketFactory sslcsf) {
|
|
|
+ public static String sendRefundSSLPostToWx(String mapToXml, SSLConnectionSocketFactory sslcsf) {
|
|
|
logger.info("*******退款(WX Request:" + mapToXml);
|
|
|
- System.out.println("*******退款(WX Request:" + mapToXml);
|
|
|
- HttpPost httPost = new HttpPost(CommonWxPayPropertiesBuilder.instance().getRefundUrl());
|
|
|
+ String xmlStr = sendSSLPostToWx(mapToXml, sslcsf, CommonWxPayPropertiesBuilder.instance().getRefundUrl());
|
|
|
+ logger.info("*******退款(WX Response:" + xmlStr);
|
|
|
+ return xmlStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求微信https
|
|
|
+ **/
|
|
|
+ private static String sendSSLPostToWx(String mapToXml, SSLConnectionSocketFactory sslcsf, String requestUrl) {
|
|
|
+
|
|
|
+ HttpPost httPost = new HttpPost(requestUrl);
|
|
|
httPost.addHeader("Connection", "keep-alive");
|
|
|
httPost.addHeader("Accept", "*/*");
|
|
|
httPost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
@@ -115,14 +185,18 @@ public class WechatUtil {
|
|
|
httPost.addHeader("Cache-Control", "max-age=0");
|
|
|
httPost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
|
|
|
httPost.setEntity(new StringEntity(mapToXml, "UTF-8"));
|
|
|
- CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslcsf).build();
|
|
|
+ CloseableHttpClient httpClient = null;
|
|
|
+ if (sslcsf != null) {
|
|
|
+ httpClient = HttpClients.custom().setSSLSocketFactory(sslcsf).build();
|
|
|
+ } else {
|
|
|
+ httpClient = HttpClients.createDefault();
|
|
|
+ }
|
|
|
+
|
|
|
CloseableHttpResponse response = null;
|
|
|
try {
|
|
|
response = httpClient.execute(httPost);
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
String xmlStr = EntityUtils.toString(entity, "UTF-8");
|
|
|
- logger.info("*******退款(WX Response:" + xmlStr);
|
|
|
- System.out.println("*******退款(WX Response:" + xmlStr);
|
|
|
return xmlStr;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
@@ -171,59 +245,10 @@ public class WechatUtil {
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
String xmlStr = EntityUtils.toString(entity, "UTF-8");
|
|
|
System.out.println(xmlStr);
|
|
|
- WechatRefundQueryResult result = (WechatRefundQueryResult) XmlUtil.xmlStrToBean(xmlStr, WechatRefundQueryResult.class);
|
|
|
+ WechatRefundQueryResult result =
|
|
|
+ (WechatRefundQueryResult) XmlUtil.xmlStrToBean(xmlStr, WechatRefundQueryResult.class);
|
|
|
result.setXmlStr(xmlStr);
|
|
|
-// Map<String, Object> result = XmlUtil.xmlStrToMap(xmlStr);//.xmlStrToBean(xmlStr, WechatRefundApiResult.class);
|
|
|
- return result;
|
|
|
- //将信息保存到数据库
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e.getMessage(), e);
|
|
|
- return null;
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- if (response != null) {
|
|
|
- response.close();
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- logger.error(e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法描述:微信查询订单逻辑
|
|
|
- * 创建时间:2018年11月02日 上午11:04:25
|
|
|
- * 作者: huangyaqin
|
|
|
- * @param
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static WechatRefundApiResult wxOrderQuery(String out_trade_no) {
|
|
|
- Map<Object, Object> params = new HashMap<Object, Object>();
|
|
|
- params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
|
|
|
- params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
|
|
|
- params.put("nonce_str", CharUtil.getRandomString(16));//随机字符串,不长于32位。推荐随机数生成算法
|
|
|
- params.put("out_trade_no", out_trade_no);//商户侧传给微信的订单号
|
|
|
- //签名前必须要参数全部写在前面
|
|
|
- params.put("sign", arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
|
|
|
- String mapToXml = MapUtils.convertMap2Xml(params);
|
|
|
- HttpPost httPost = new HttpPost(CommonWxPayPropertiesBuilder.instance().getOrderquery());
|
|
|
- httPost.addHeader("Connection", "keep-alive");
|
|
|
- httPost.addHeader("Accept", "*/*");
|
|
|
- httPost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
- httPost.addHeader("Host", "api.mch.weixin.qq.com");
|
|
|
- httPost.addHeader("X-Requested-With", "XMLHttpRequest");
|
|
|
- httPost.addHeader("Cache-Control", "max-age=0");
|
|
|
- httPost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
|
|
|
- httPost.setEntity(new StringEntity(mapToXml, "UTF-8"));
|
|
|
- CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(WechatConfig.getSslcsf()).build();
|
|
|
- CloseableHttpResponse response = null;
|
|
|
- try {
|
|
|
- response = httpClient.execute(httPost);
|
|
|
- HttpEntity entity = response.getEntity();
|
|
|
- String xmlStr = EntityUtils.toString(entity, "UTF-8");
|
|
|
- System.out.println("xmlStr : " + xmlStr);
|
|
|
- WechatRefundApiResult result = (WechatRefundApiResult) XmlUtil.xmlStrToBean(xmlStr, WechatRefundApiResult.class);
|
|
|
+ // Map<String, Object> result = XmlUtil.xmlStrToMap(xmlStr);//.xmlStrToBean(xmlStr, WechatRefundApiResult.class);
|
|
|
return result;
|
|
|
//将信息保存到数据库
|
|
|
} catch (Exception e) {
|
|
@@ -305,32 +330,26 @@ public class WechatUtil {
|
|
|
*/
|
|
|
public static String requestOnce(final String url, String data) {
|
|
|
BasicHttpClientConnectionManager connManager;
|
|
|
- connManager = new BasicHttpClientConnectionManager(
|
|
|
- RegistryBuilder.<ConnectionSocketFactory>create()
|
|
|
- .register("http", PlainConnectionSocketFactory.getSocketFactory())
|
|
|
- .register("https", SSLConnectionSocketFactory.getSocketFactory())
|
|
|
- .build(),
|
|
|
- null,
|
|
|
- null,
|
|
|
- null
|
|
|
- );
|
|
|
-
|
|
|
- HttpClient httpClient = HttpClientBuilder.create()
|
|
|
- .setConnectionManager(connManager)
|
|
|
- .build();
|
|
|
+ connManager = new BasicHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
|
|
|
+ .register("http", PlainConnectionSocketFactory
|
|
|
+ .getSocketFactory()).register("https",
|
|
|
+ SSLConnectionSocketFactory
|
|
|
+ .getSocketFactory())
|
|
|
+ .build(), null, null, null);
|
|
|
+
|
|
|
+ HttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connManager).build();
|
|
|
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
|
- RequestConfig requestConfig = RequestConfig.custom()
|
|
|
- .setSocketTimeout(5000)
|
|
|
- .setConnectTimeout(5000)
|
|
|
- .setConnectionRequestTimeout(10000).build();
|
|
|
+ RequestConfig requestConfig =
|
|
|
+ RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).setConnectionRequestTimeout(10000)
|
|
|
+ .build();
|
|
|
|
|
|
httpPost.setConfig(requestConfig);
|
|
|
|
|
|
StringEntity postEntity = new StringEntity(data, "UTF-8");
|
|
|
httpPost.addHeader("Content-Type", "text/xml");
|
|
|
-// httpPost.addHeader("User-Agent", "wxpay sdk java v1.0 " + CommonWxPayPropertiesBuilder.instance().getMchId());
|
|
|
+ // httpPost.addHeader("User-Agent", "wxpay sdk java v1.0 " + CommonWxPayPropertiesBuilder.instance().getMchId());
|
|
|
httpPost.addHeader("User-Agent", "wxpay sdk java v1.0 " + "1517534731");
|
|
|
httpPost.setEntity(postEntity);
|
|
|
|
|
@@ -358,28 +377,22 @@ public class WechatUtil {
|
|
|
public static String requestOnceGet(final String url, Map params) {
|
|
|
StringBuffer strtTotalURL = new StringBuffer(EMPTY);
|
|
|
BasicHttpClientConnectionManager connManager;
|
|
|
- connManager = new BasicHttpClientConnectionManager(
|
|
|
- RegistryBuilder.<ConnectionSocketFactory>create()
|
|
|
- .register("http", PlainConnectionSocketFactory.getSocketFactory())
|
|
|
- .register("https", SSLConnectionSocketFactory.getSocketFactory())
|
|
|
- .build(),
|
|
|
- null,
|
|
|
- null,
|
|
|
- null
|
|
|
- );
|
|
|
-
|
|
|
- HttpClient httpClient = HttpClientBuilder.create()
|
|
|
- .setConnectionManager(connManager)
|
|
|
- .build();
|
|
|
+ connManager = new BasicHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
|
|
|
+ .register("http", PlainConnectionSocketFactory
|
|
|
+ .getSocketFactory()).register("https",
|
|
|
+ SSLConnectionSocketFactory
|
|
|
+ .getSocketFactory())
|
|
|
+ .build(), null, null, null);
|
|
|
+
|
|
|
+ HttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connManager).build();
|
|
|
HttpGet httpGet = new HttpGet(url);
|
|
|
- RequestConfig requestConfig = RequestConfig.custom()
|
|
|
- .setSocketTimeout(5000)
|
|
|
- .setConnectTimeout(5000)
|
|
|
- .setConnectionRequestTimeout(10000).build();
|
|
|
+ RequestConfig requestConfig =
|
|
|
+ RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).setConnectionRequestTimeout(10000)
|
|
|
+ .build();
|
|
|
|
|
|
httpGet.setConfig(requestConfig);
|
|
|
httpGet.addHeader("Content-Type", "text/xml");
|
|
|
-// httpGet.addHeader("User-Agent", "wxpay sdk java v1.0 " + CommonWxPayPropertiesBuilder.instance().getMchId());
|
|
|
+ // httpGet.addHeader("User-Agent", "wxpay sdk java v1.0 " + CommonWxPayPropertiesBuilder.instance().getMchId());
|
|
|
httpGet.addHeader("User-Agent", "wxpay sdk java v1.0 " + "1517534731");
|
|
|
if (strtTotalURL.indexOf("?") == -1) {
|
|
|
strtTotalURL.append(url).append("?").append(getUrl(params, "UTF-8"));
|
|
@@ -436,6 +449,197 @@ public class WechatUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 调用付款码支付逻辑
|
|
|
+ *
|
|
|
+ * @param shop_name 门店名称
|
|
|
+ * @param orderBizType 订单业务类型
|
|
|
+ * @param attach 附加数据,该字段主要用于商户携带订单的自定义数据,如无可为null
|
|
|
+ * @param out_trade_no 商户订单编号
|
|
|
+ * @param orderMoney 订单总金额,单位:元
|
|
|
+ * @param ip 当前机器ip
|
|
|
+ * @param auth_code 扫码得到支付授权码
|
|
|
+ * @return 微信返回信息
|
|
|
+ */
|
|
|
+ public static WechatMicropayApiResult wxMicropay(String shop_name, String orderBizType, String attach,
|
|
|
+ String out_trade_no, double orderMoney, String ip,
|
|
|
+ String auth_code) {
|
|
|
+ //初始化请求微信服务器的配置信息包括appid密钥等
|
|
|
+ //转换金钱格式
|
|
|
+ BigDecimal bdOrderMoney = new BigDecimal(orderMoney, MathContext.DECIMAL32);
|
|
|
+ //构建请求参数
|
|
|
+ Map<Object, Object> params =
|
|
|
+ buildMicropayRequsetMapParam(shop_name, orderBizType, attach, out_trade_no, bdOrderMoney, ip,
|
|
|
+ auth_code);
|
|
|
+ String mapToXml = MapUtils.convertMap2Xml(params);
|
|
|
+ //请求微信
|
|
|
+ String reponseXml = sendMicropaySSLPostToWx(mapToXml);
|
|
|
+ WechatMicropayApiResult result =
|
|
|
+ (WechatMicropayApiResult) XmlUtil.xmlStrToBean(reponseXml, WechatMicropayApiResult.class);
|
|
|
+ if ("SUCCESS".equals(result.getReturn_code()) && "OK".equals(result.getReturn_msg())) {
|
|
|
+ //支付成功
|
|
|
+ if ("SUCCESS".equals(result.getResult_code())) {
|
|
|
+ result.setTrade_state(WXTradeState.SUCCESS.getCode());
|
|
|
+ } else if ("FAIL".equals(result.getResult_code())) {
|
|
|
+ //支付中
|
|
|
+ if ("USERPAYING".equals(result.getErr_code()) || "SYSTEMERROR".equals(result.getErr_code()) ||
|
|
|
+ "BANKERROR".equals(result.getErr_code())) {
|
|
|
+ result.setTrade_state(WXTradeState.USERPAYING.getCode());
|
|
|
+ //支付失败
|
|
|
+ } else {
|
|
|
+ result.setTrade_state(WXTradeState.PAYERROR.getCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static WechatReverseApiResult wxReverse(String out_trade_no) {
|
|
|
+ //初始化请求微信服务器的配置信息包括appid密钥等
|
|
|
+ //构建请求参数
|
|
|
+ Map<Object, Object> params = buildReverseRequsetMapParam(out_trade_no);
|
|
|
+ String mapToXml = MapUtils.convertMap2Xml(params);
|
|
|
+ //请求微信
|
|
|
+ String reponseXml = sendReverseSSLPostToWx(mapToXml, WechatConfig.getSslcsf());
|
|
|
+ WechatReverseApiResult result =
|
|
|
+ (WechatReverseApiResult) XmlUtil.xmlStrToBean(reponseXml, WechatReverseApiResult.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法描述:微信查询订单逻辑
|
|
|
+ * 创建时间:2018年11月02日 上午11:04:25
|
|
|
+ * 作者: huangyaqin
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static WechatRefundApiResult wxOrderQuery(String out_trade_no) {
|
|
|
+ //初始化请求微信服务器的配置信息包括appid密钥等
|
|
|
+ //构建请求参数
|
|
|
+ Map<Object, Object> params = buildQueryRequsetMapParam(out_trade_no);
|
|
|
+ String mapToXml = MapUtils.convertMap2Xml(params);
|
|
|
+ //请求微信
|
|
|
+ String reponseXml = sendQuerySSLPostToWx(mapToXml);
|
|
|
+ WechatRefundApiResult result =
|
|
|
+ (WechatRefundApiResult) XmlUtil.xmlStrToBean(reponseXml, WechatRefundApiResult.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定提交付款码支付请求输入参数
|
|
|
+ *
|
|
|
+ * @param shop_name 门店名称
|
|
|
+ * @param orderBizType 订单业务类型
|
|
|
+ * @param attach 附加数据,该字段主要用于商户携带订单的自定义数据,如无可为null
|
|
|
+ * @param out_trade_no 商户订单编号
|
|
|
+ * @param orderMoney 订单总金额,单位:元
|
|
|
+ * @param ip 当前机器ip
|
|
|
+ * @param auth_code 扫码得到支付授权码
|
|
|
+ * @return 提交付款码支付请求输入参数
|
|
|
+ */
|
|
|
+ private static Map<Object, Object> buildMicropayRequsetMapParam(String shop_name, String orderBizType,
|
|
|
+ String attach, String out_trade_no,
|
|
|
+ BigDecimal orderMoney, String ip,
|
|
|
+ String auth_code) {
|
|
|
+ Map<Object, Object> params = new HashMap<Object, Object>();
|
|
|
+ params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
|
|
|
+ params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
|
|
|
+ params.put("nonce_str", CharUtil.getRandomString(16));//随机字符串,不长于32位。推荐随机数生成算法
|
|
|
+
|
|
|
+ String orderBizTypeZn = "普通货物";
|
|
|
+ if ("00".equals(orderBizType)) {
|
|
|
+ orderBizTypeZn = "保税备货";
|
|
|
+ } else if ("02".equals(orderBizType)) {
|
|
|
+ orderBizTypeZn = "保税展示补货";
|
|
|
+ } else if ("10".equals(orderBizType)) {
|
|
|
+ orderBizTypeZn = "保税展示跨境";
|
|
|
+ }
|
|
|
+ params.put("body", shop_name + "-" + orderBizTypeZn);//商品简单描述,不长于128位
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(attach)) {
|
|
|
+ params.put("attach", attach);//附加数据,不长于127位,该字段主要用于商户携带订单的自定义数据
|
|
|
+ }
|
|
|
+
|
|
|
+ params.put("out_trade_no", out_trade_no);//商户传给微信的订单号
|
|
|
+ params.put("total_fee", orderMoney.multiply(Constant.ONE_HUNDRED).intValue());//订单总金额,单位为分,只能为整数
|
|
|
+ params.put("spbill_create_ip", ip);//当前机器ip
|
|
|
+ params.put("auth_code", auth_code);//扫码支付授权码,设备读取用户微信中的条码或者二维码信息
|
|
|
+ //签名前必须要参数全部写在前面
|
|
|
+ params.put("sign", arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
|
|
|
+ return params;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定撤销订单求输入参数
|
|
|
+ *
|
|
|
+ * @param out_trade_no 订单编号(发送到微信的编号)
|
|
|
+ * @return 撤销订单求输入参数
|
|
|
+ */
|
|
|
+ private static Map<Object, Object> buildReverseRequsetMapParam(String out_trade_no) {
|
|
|
+ Map<Object, Object> params = new HashMap<Object, Object>();
|
|
|
+ params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
|
|
|
+ params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
|
|
|
+ params.put("out_trade_no", out_trade_no);//商户传给微信的订单号
|
|
|
+ params.put("nonce_str", CharUtil.getRandomString(16));//随机字符串,不长于32位。推荐随机数生成算法
|
|
|
+ //签名前必须要参数全部写在前面
|
|
|
+ params.put("sign", arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
|
|
|
+ return params;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定查询订单求输入参数
|
|
|
+ *
|
|
|
+ * @param out_trade_no 订单编号(发送到微信的编号)
|
|
|
+ * @return 查询订单求输入参数
|
|
|
+ */
|
|
|
+ private static Map<Object, Object> buildQueryRequsetMapParam(String out_trade_no) {
|
|
|
+ Map<Object, Object> params = new HashMap<Object, Object>();
|
|
|
+ params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
|
|
|
+ params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
|
|
|
+ params.put("out_trade_no", out_trade_no);//商户传给微信的订单号
|
|
|
+ params.put("nonce_str", CharUtil.getRandomString(16));//随机字符串,不长于32位。推荐随机数生成算法
|
|
|
+ //签名前必须要参数全部写在前面
|
|
|
+ params.put("sign", arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
|
|
|
+ return params;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求退款微信
|
|
|
+ **/
|
|
|
+ private static String sendMicropaySSLPostToWx(String mapToXml) {
|
|
|
+ logger.info("*******付款码支付(WX Request:" + mapToXml);
|
|
|
+ String xmlStr = sendSSLPostToWx(mapToXml, null, CommonWxPayPropertiesBuilder.instance().getMicropayUrl());
|
|
|
+ logger.info("*******付款码支付(WX Response:" + xmlStr);
|
|
|
+ return xmlStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求撤销订单微信
|
|
|
+ **/
|
|
|
+ private static String sendReverseSSLPostToWx(String mapToXml, SSLConnectionSocketFactory sslcsf) {
|
|
|
+ logger.info("*******撤销订单(WX Request:" + mapToXml);
|
|
|
+ String xmlStr = sendSSLPostToWx(mapToXml, sslcsf, CommonWxPayPropertiesBuilder.instance().getReverseUrl());
|
|
|
+ logger.info("*******撤销订单(WX Response:" + xmlStr);
|
|
|
+ return xmlStr;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求查询订单微信
|
|
|
+ **/
|
|
|
+ private static String sendQuerySSLPostToWx(String mapToXml) {
|
|
|
+ logger.info("*******查询订单(WX Request:" + mapToXml);
|
|
|
+ String xmlStr = sendSSLPostToWx(mapToXml, null, CommonWxPayPropertiesBuilder.instance().getOrderquery());
|
|
|
+ logger.info("*******查询订单(WX Response:" + xmlStr);
|
|
|
+ return xmlStr;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
Map<Object, Object> parame = new TreeMap<Object, Object>();
|
|
|
parame.put("mch_id", ResourceUtil.getConfigByName("\\conf\\wx-mp", "wx.mchId"));//
|
|
@@ -446,7 +650,8 @@ public class WechatUtil {
|
|
|
|
|
|
String xml = MapUtils.convertMap2Xml(parame);
|
|
|
logger.info("xml:" + xml);
|
|
|
- Map<String, Object> resultUn = XmlUtil.xmlStrToMap(WechatUtil.requestOnce("https://apitest.mch.weixin.qq.com/sandboxnew/pay/getsignkey", xml));
|
|
|
+ Map<String, Object> resultUn = XmlUtil.xmlStrToMap(
|
|
|
+ WechatUtil.requestOnce("https://apitest.mch.weixin.qq.com/sandboxnew/pay/getsignkey", xml));
|
|
|
System.out.print(resultUn);
|
|
|
}
|
|
|
}
|