fwq
2022-05-11 4a044670a4b8a9bcc0a38b413ef803b9842a5052
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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.*;
 
 
/** 服务商商户Native(二维码扫码支付)
 * @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 服务商申请的公众号appid
     * @param sp_mchid 服务商户号
     * @param sub_appid 子商户申请的公众号appid 不必填
     * @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;
    }
}