KKSU
2024-01-18 5cac1da67768c3dbbcd74e50ad59cb80fb82def0
src/test/java/cc/mrbird/febs/ProfitTest.java
@@ -46,6 +46,7 @@
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -196,54 +197,44 @@
    @Test
    public void rankProfit04() throws IOException {//获取用户填写的抬头
        FPUserTitleDto fpUserTitleDto = new FPUserTitleDto();
        fpUserTitleDto.setScene("WITH_WECHATPAY");
        fpUserTitleDto.setFapiao_apply_id("");
        String parseObj = JSONUtil.parseObj(fpUserTitleDto).toString();
        //初始化请求参数
        Map<String, Object> params = new HashMap<>();
        params.put("scene","WITH_WECHATPAY");
        params.put("fapiao_apply_id","4200002070202401175245187105");
        String parseObj = JSONUtil.parseObj(params).toString();
        System.out.println(parseObj);
        String baseUrl = "https://api.mch.weixin.qq.com";
        String canonicalUrl = "/v3/new-tax-control-fapiao/user-title";
        String urlparm = baseUrl+canonicalUrl;//有参数的get请求,加密是需要把参数加载进去URL
        List<BasicNameValuePair> parameters = new ArrayList<>();
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            parameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString()));
        }
        StringBuilder dataparm = new StringBuilder();
        params.forEach((k, v) -> dataparm.append("&" + k + "=" + v));
        String string = dataparm.toString();
        if (!"".equals(string)) {
            urlparm = baseUrl+canonicalUrl + "?" + dataparm.substring(1);
        }
        System.out.println(urlparm);
        PrivateKey privateKey = wxFaPiaoService.getPrivateKeyV3();
        String postStr = null;
        try {
            postStr = wxFaPiaoService.createAuthorization(
                    "POST",
                    baseUrl+canonicalUrl,
                    parseObj,
                    "GET",
                    urlparm,
                    "",
                    privateKey
            );
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        String token = AppContants.FP_TOKEN_HEADER_TYPE+postStr;
        System.out.println("WECHATPAY2-SHA256-RSA2048 "+postStr);
        String s = wxFaPiaoService.sendPost(baseUrl + canonicalUrl, parseObj, "WECHATPAY2-SHA256-RSA2048 "+postStr);
        String s = wxFaPiaoService.sendGet(baseUrl+canonicalUrl, params, "WECHATPAY2-SHA256-RSA2048 "+postStr);
        System.out.println(s);
        cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(s);
        System.out.println(jsonObject);
    }
    @Test
    public void rankProfit05() throws IOException {//获取用户填写的抬头
        byte[] bytes = "daL341aN5orDt13puXadsAf2rpuX12v3".getBytes("utf-8");
        try {
            //传入证书
            PrivateKey privateKey = wxFaPiaoService.getPrivateKeyV3();
            //刷新
            PrivateKeySigner signer = new PrivateKeySigner(AppContants.WX_CARD_NUM, privateKey);
            WechatPay2Credentials credentials = new WechatPay2Credentials("1658958205", signer);
            AutoUpdateCertificatesVerifier autoUpdateCertificatesVerifier = new AutoUpdateCertificatesVerifier(credentials
                    , bytes);
            NotificationHandler handler = new NotificationHandler(autoUpdateCertificatesVerifier,bytes);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
                                }
    @Test
    public void rankProfit2() throws IOException {//查询配置开发选项
@@ -263,22 +254,25 @@
            e.printStackTrace();
        }
        System.out.println("WECHATPAY2-SHA256-RSA2048"+postStr);
        try {
            HttpClient httpClient = new HttpClient();
            GetMethod method = new GetMethod(baseUrl+canonicalUrl);
            method.setRequestHeader("Accept", "application/json");
            method.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36");
            method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
            method.setRequestHeader("Connection", "keep-alive");
            method.setRequestHeader("Authorization", "WECHATPAY2-SHA256-RSA2048 "+postStr);
            httpClient.executeMethod(method);
            System.out.println(method);
            String responseBodyAsString = method.getResponseBodyAsString();
            cn.hutool.json.JSONObject maps = JSONUtil.parseObj(responseBodyAsString);
            System.out.println(maps);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String s = wxFaPiaoService.sendGet(baseUrl + canonicalUrl, new HashMap<>(), "WECHATPAY2-SHA256-RSA2048 "+postStr);
        System.out.println(s);
//        try {
//            HttpClient httpClient = new HttpClient();
//            GetMethod method = new GetMethod(baseUrl+canonicalUrl);
//            method.setRequestHeader("Accept", "application/json");
//            method.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36");
//            method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
//            method.setRequestHeader("Connection", "keep-alive");
//            method.setRequestHeader("Authorization", "WECHATPAY2-SHA256-RSA2048 "+postStr);
//            httpClient.executeMethod(method);
//            System.out.println(method);
//            String responseBodyAsString = method.getResponseBodyAsString();
//            cn.hutool.json.JSONObject maps = JSONUtil.parseObj(responseBodyAsString);
//            System.out.println(maps);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }
@@ -301,18 +295,8 @@
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        HttpClient httpClient = new HttpClient();
        String responseBodyAsString = wxFaPiaoService.sendGet(baseUrl + canonicalUrl, new HashMap<>(), "WECHATPAY2-SHA256-RSA2048 "+postStr);
        try {
            GetMethod method = new GetMethod(baseUrl+canonicalUrl);
            method.setRequestHeader("Accept", "application/json");
            method.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36");
            method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
//            method.setRequestHeader("Connection", "keep-alive");
            method.setRequestHeader("Authorization", "WECHATPAY2-SHA256-RSA2048 "+postStr);
            int i = httpClient.executeMethod(method);
            System.out.println(i);
            System.out.println(method);
            String responseBodyAsString = method.getResponseBodyAsString();
            cn.hutool.json.JSONObject maps = JSONUtil.parseObj(responseBodyAsString);
            System.out.println(maps);