From 308a02454db3abd8267b0a1273a6bb231ce53c21 Mon Sep 17 00:00:00 2001 From: ChenJiaHe <763432473@qq.com> Date: 星期五, 27 八月 2021 15:54:06 +0800 Subject: [PATCH] 优化 --- src/main/java/com/hx/mp/util/CorpWXPayQrUtil.java | 73 ++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/mp/util/CorpWXPayQrUtil.java b/src/main/java/com/hx/mp/util/CorpWXPayQrUtil.java new file mode 100644 index 0000000..65010c7 --- /dev/null +++ b/src/main/java/com/hx/mp/util/CorpWXPayQrUtil.java @@ -0,0 +1,73 @@ +package com.hx.mp.util; + +import com.hx.exception.ServiceException; +import com.hx.util.HttpUtil; +import com.hx.util.SimpleTool; +import com.hx.util.StringUtils; +import net.sf.json.JSONObject; +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.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; +import org.apache.http.util.EntityUtils; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import javax.net.ssl.SSLContext; +import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.FileInputStream; +import java.security.KeyStore; +import java.util.*; + + +/** 鏈嶅姟鍟嗗晢鎴種ative锛堜簩缁寸爜鎵爜鏀粯锛� + * @author ChenJiaHe + */ +public class CorpWXPayQrUtil { + + + /**鏈嶅姟鍟�-鑾峰彇浜岀淮鐮佹敮浠樻暟鎹�*/ + private static final String PAY_NATIVE_URL = "https://api.mch.weixin.qq.com/v3/pay/partner/transactions/native"; + + /**鑾峰彇鏀粯浜岀淮鐮佹暟鎹� + * @param sp_appid 鏈嶅姟鍟嗙敵璇风殑鍏紬鍙穉ppid + * @param sp_mchid 鏈嶅姟鍟嗘埛鍙� + * @param sub_appid 瀛愬晢鎴风敵璇风殑鍏紬鍙穉ppid 涓嶅繀濉� + * @param sub_mchid 瀛愬晢鎴风殑鍟嗘埛鍙� + * @param description 鍟嗗搧鎻忚堪 + * @param out_trade_no 鍟嗘埛绯荤粺鍐呴儴璁㈠崟鍙� + * @param amount 閲戦锛堝垎锛� + * @param notify_url 鍥炶皟鍦板潃 + * @return + * @throws Exception + */ + public static JSONObject nativeQr(String sp_appid , String sp_mchid , String sub_appid + , String sub_mchid , String description , String out_trade_no , Integer amount + ,String notify_url ) + throws Exception { + + JSONObject parameters = new JSONObject(); + parameters.put("sp_appid", sp_appid); + parameters.put("sp_mchid", sp_mchid); + parameters.put("sub_appid", sub_appid); + parameters.put("sub_mchid", sub_mchid); + parameters.put("description", description); + parameters.put("out_trade_no", out_trade_no); + parameters.put("notify_url", notify_url); + + JSONObject amountObj = new JSONObject(); + amountObj.put("total",amount); + amountObj.put("currency","CNY"); + parameters.put("amount", amountObj); + + JSONObject returnObj = HttpUtil.HttpURLUtilJson(PAY_NATIVE_URL,parameters.toString()); + + return returnObj; + } +} -- Gitblit v1.8.0