From ec4e65ba157bded805081aa40977b1d996fd2b21 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Wed, 17 Jan 2024 11:29:57 +0800
Subject: [PATCH] fapiao

---
 src/test/java/cc/mrbird/febs/ProfitTest.java |  145 ++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 110 insertions(+), 35 deletions(-)

diff --git a/src/test/java/cc/mrbird/febs/ProfitTest.java b/src/test/java/cc/mrbird/febs/ProfitTest.java
index 9ee9405..2dc3b0a 100644
--- a/src/test/java/cc/mrbird/febs/ProfitTest.java
+++ b/src/test/java/cc/mrbird/febs/ProfitTest.java
@@ -4,6 +4,7 @@
 import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
 import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
 import cc.mrbird.febs.common.exception.FebsException;
+import cc.mrbird.febs.common.utils.AppContants;
 import cc.mrbird.febs.common.utils.HttpCurlUtil;
 import cc.mrbird.febs.common.utils.MallUtils;
 import cc.mrbird.febs.common.utils.RedisUtils;
@@ -12,8 +13,7 @@
 import cc.mrbird.febs.mall.mapper.*;
 import cc.mrbird.febs.mall.service.*;
 import cc.mrbird.febs.mall.vo.MallMemberCouponVo;
-import cc.mrbird.febs.pay.model.BrandWCPayRequestData;
-import cc.mrbird.febs.pay.model.HeaderDto;
+import cc.mrbird.febs.pay.model.*;
 import cc.mrbird.febs.pay.service.IXcxPayService;
 import cc.mrbird.febs.pay.service.WxFaPiaoService;
 import cc.mrbird.febs.pay.util.WechatConfigure;
@@ -35,10 +35,12 @@
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPatch;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -52,6 +54,8 @@
 import java.net.URLConnection;
 import java.nio.charset.Charset;
 import java.security.KeyPair;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
 import java.util.*;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
@@ -106,59 +110,130 @@
     @Autowired
     ResourceLoader resourceLoader;
     @Test
-    public void rankProfit() throws IOException {
+    public void rankProfit() throws IOException {//配置开发选项
 //        System.out.println(new ClassPathResource("wxP12/apiclient_cert.p12").getFile().exists());
 //        System.out.println(new File("src/main/resources/wxP12/apiclient_cert.p12").exists());
 //
 //        InputStream inputStream = new FileInputStream(file);
 //        System.out.println(resourceLoader.getResource("classpath:/wxP12/apiclient_cert.p12").exists());
-        KeyPair privateKey = wxFaPiaoService.getPrivateKey();
+        PrivateKey privateKey = wxFaPiaoService.getPrivateKeyV3();
         HeaderDto headerDto = new HeaderDto();
         headerDto.setCallback_url("https://api.blnka.cn/api/xcxPay/fapiaoCallBack");
-        headerDto.setShow_fapiao_cell(true);
+        headerDto.setShow_fapiao_cell(false);
         String parseObj = JSONUtil.parseObj(headerDto).toString();
         String baseUrl = "https://api.mch.weixin.qq.com";
         String canonicalUrl = "/v3/new-tax-control-fapiao/merchant/development-config";
-        String postStr = wxFaPiaoService.createAuthorization(
-                "POST",
-                canonicalUrl,
-                parseObj,
-                privateKey
-
-        );
-        // 创建httppost
+        String postStr = null;
         try {
-            HttpClient httpClient = new HttpClient();
-            PostMethod post = new PostMethod("https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/development-config");
-            post.setRequestHeader("Accept", "application/json");
-            post.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");
-            post.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
-            post.setRequestHeader("Connection", "keep-alive");
-            post.setRequestHeader("Authorization",  "WECHATPAY2-SHA256-RSA2048 "+postStr);
-            RequestEntity entity = new StringRequestEntity(parseObj, "text/html", "utf-8");
-            post.setRequestEntity(entity);
-            httpClient.executeMethod(post);
-            String responseBodyAsString = post.getResponseBodyAsString();
-            cn.hutool.json.JSONObject maps = JSONUtil.parseObj(responseBodyAsString);
-            System.out.println(maps);
-        } catch (IOException e) {
+            postStr = wxFaPiaoService.createAuthorization(
+                    "PATCH",
+                    baseUrl+canonicalUrl,
+                    parseObj,
+                    privateKey
+            );
+        } catch (NoSuchAlgorithmException e) {
             e.printStackTrace();
         }
 
+        String token = AppContants.FP_TOKEN_HEADER_TYPE+postStr;
+        System.out.println("WECHATPAY2-SHA256-RSA2048 "+postStr);
+        String s = wxFaPiaoService.sendPatch(baseUrl + canonicalUrl, parseObj, token);
+        System.out.println(s);
     }
 
     @Test
-    public void rankProfit2() throws IOException {
-        KeyPair privateKey = wxFaPiaoService.getPrivateKey();
+    public void rankProfit03() throws IOException {//创建电子发票卡券模板
+        FPCardTemplateDto fpCardTemplateDto = new FPCardTemplateDto();
+        fpCardTemplateDto.setCard_appid("wxad2fdb2fcad10fb2");
+
+        FPCardTemplateInformationDto fpCardTemplateInformationDto = new FPCardTemplateInformationDto();
+        fpCardTemplateInformationDto.setLogo_url("http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0");
+        fpCardTemplateInformationDto.setPayee_name("发票测试");
+
+        FPCardTemplateCustomCellDto fpCardTemplateCustomCellDto = new FPCardTemplateCustomCellDto();
+        fpCardTemplateCustomCellDto.setWords("电子发票");
+        fpCardTemplateCustomCellDto.setDescription("查看发票");
+        fpCardTemplateCustomCellDto.setJump_url("http://www.qq.com");
+        fpCardTemplateCustomCellDto.setMiniprogram_path("gh_86a091e50ad4@app");
+        fpCardTemplateCustomCellDto.setMiniprogram_user_name("pages/xxxPage");
+        fpCardTemplateInformationDto.setCustom_cell(fpCardTemplateCustomCellDto);
+
+        fpCardTemplateDto.setCard_template_information(fpCardTemplateInformationDto);
+
+        String parseObj = JSONUtil.parseObj(fpCardTemplateDto).toString();
+        System.out.println(parseObj);
+        String baseUrl = "https://api.mch.weixin.qq.com";
+        String canonicalUrl = "/v3/new-tax-control-fapiao/card-template";
+        PrivateKey privateKey = wxFaPiaoService.getPrivateKeyV3();
+        String postStr = null;
+        try {
+            postStr = wxFaPiaoService.createAuthorization(
+                    "POST",
+                    baseUrl+canonicalUrl,
+                    parseObj,
+                    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);
+        System.out.println(s);
+    }
+
+
+
+    @Test
+    public void rankProfit04() throws IOException {//获取用户填写的抬头
+        FPUserTitleDto fpUserTitleDto = new FPUserTitleDto();
+        fpUserTitleDto.setScene("WITH_WECHATPAY");
+        fpUserTitleDto.setFapiao_apply_id("");
+
+        String parseObj = JSONUtil.parseObj(fpUserTitleDto).toString();
+        System.out.println(parseObj);
+        String baseUrl = "https://api.mch.weixin.qq.com";
+        String canonicalUrl = "/v3/new-tax-control-fapiao/user-title";
+        PrivateKey privateKey = wxFaPiaoService.getPrivateKeyV3();
+        String postStr = null;
+        try {
+            postStr = wxFaPiaoService.createAuthorization(
+                    "POST",
+                    baseUrl+canonicalUrl,
+                    parseObj,
+                    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);
+        System.out.println(s);
+        cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(s);
+        System.out.println(jsonObject);
+    }
+
+    @Test
+    public void rankProfit2() throws IOException {//查询配置开发选项
+        PrivateKey privateKey = wxFaPiaoService.getPrivateKeyV3();
         String baseUrl = "https://api.mch.weixin.qq.com";
         String canonicalUrl = "/v3/new-tax-control-fapiao/merchant/development-config";
-        String postStr = wxFaPiaoService.createAuthorization(
-                "GET",
-                canonicalUrl,
-                "",
-                privateKey
+        String postStr = null;
+        try {
+            postStr = wxFaPiaoService.createAuthorization(
+                    "GET",
+                    baseUrl+canonicalUrl,
+                    "",
+                    privateKey
 
-        );
+            );
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }
+        System.out.println("WECHATPAY2-SHA256-RSA2048"+postStr);
         try {
             HttpClient httpClient = new HttpClient();
             GetMethod method = new GetMethod(baseUrl+canonicalUrl);

--
Gitblit v1.9.1