|  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.MallGoodsListVo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.MallMemberCouponVo; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.model.*; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.service.IXcxPayService; | 
|---|
|  |  |  | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.core.date.DateTime; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUtil; | 
|---|
|  |  |  | import cn.hutool.json.JSONArray; | 
|---|
|  |  |  | import cn.hutool.json.JSONUtil; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.boot.test.context.SpringBootTest; | 
|---|
|  |  |  | import org.springframework.core.io.ClassPathResource; | 
|---|
|  |  |  | import org.springframework.core.io.ResourceLoader; | 
|---|
|  |  |  | import org.springframework.util.Base64Utils; | 
|---|
|  |  |  | import org.springframework.web.client.RestTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | 
|---|
|  |  |  | private WxFaPiaoService wxFaPiaoService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ResourceLoader resourceLoader; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Test | 
|---|
|  |  |  | public void redisTest() throws IOException {//配置开发选项 | 
|---|
|  |  |  | String obj = redisUtils.getString("mall_goods_json");//获取JSONARRAY字符串对象 | 
|---|
|  |  |  | System.out.println(obj); | 
|---|
|  |  |  | JSONArray jsonArray = JSONUtil.parseArray(obj);//转换成JSONARRAY对象 | 
|---|
|  |  |  | List<MallGoodsListVo> mallGoodsListVos = JSONUtil.toList(jsonArray, MallGoodsListVo.class);//转换成对象集合 | 
|---|
|  |  |  | System.out.println(mallGoodsListVos.size()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Test | 
|---|
|  |  |  | public void rankProfit() throws IOException {//配置开发选项 | 
|---|
|  |  |  | //        System.out.println(new ClassPathResource("wxP12/apiclient_cert.p12").getFile().exists()); | 
|---|
|  |  |  | 
|---|
|  |  |  | //初始化请求参数 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | params.put("fapiao_apply_id","4200002059202401191880748568"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String baseUrl = "https://api.mch.weixin.qq.com"; | 
|---|
|  |  |  | String canonicalUrl = "/v3/new-tax-control-fapiao/user-title"; | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!"".equals(string)) { | 
|---|
|  |  |  | urlparm = baseUrl+canonicalUrl + "?" + dataparm.substring(1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | System.out.println(urlparm); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PrivateKey privateKey = wxFaPiaoService.getPrivateKeyV3(); | 
|---|
|  |  |  | String postStr = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String s = wxFaPiaoService.sendGet(baseUrl+canonicalUrl, params, "WECHATPAY2-SHA256-RSA2048 "+postStr); | 
|---|
|  |  |  | System.out.println(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Test | 
|---|
|  |  |  | public void rankProfit2() throws IOException {//查询配置开发选项 | 
|---|
|  |  |  | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String responseBodyAsString = wxFaPiaoService.sendGet(baseUrl + canonicalUrl, new HashMap<>(), "WECHATPAY2-SHA256-RSA2048 "+postStr); | 
|---|
|  |  |  | //完成签名并执行请求 | 
|---|
|  |  |  | X509Certificate x509Certificate = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | cn.hutool.json.JSONObject maps = JSONUtil.parseObj(responseBodyAsString); | 
|---|
|  |  |  | System.out.println(maps); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ByteArrayInputStream inputStream = new ByteArrayInputStream(pulicKey.getBytes(StandardCharsets.UTF_8)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | X509Certificate x509Certificate = (X509Certificate) cf.generateCertificate(inputStream); | 
|---|
|  |  |  | x509Certificate = (X509Certificate) cf.generateCertificate(inputStream); | 
|---|
|  |  |  | System.out.println(x509Certificate); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String timestamp = "1705548628"; | 
|---|
|  |  |  | String nonce = "sJBCGwYIM8WFJCpTE3gDGifC6VOyrPFY"; | 
|---|
|  |  |  | String body = "{\"id\":\"f23942b4-b128-56ef-9172-2da8204b5159\",\"create_time\":\"2024-01-18T11:30:28+08:00\",\"resource_type\":\"encrypt-resource\",\"event_type\":\"FAPIAO.USER_APPLIED\",\"summary\":\"用户已申请开票\",\"resource\":{\"original_type\":\"fapiao\",\"algorithm\":\"AEAD_AES_256_GCM\",\"ciphertext\":\"X7XjgHrepsnVpFqNgjl9EfRbJIdMUf15izFrtnvEf7So3SWlg6CFNofcQAJE+iL1XfkFk7DNNW0rILNbY1cGWGlAlKbbPhv5SFEakZVe9GZsSTd4EC5zTk9D6g+FTS6EQNxCkj4ut2WyYaSSqJjHgYaqdKzLNPSTGRVQnynafFE=\",\"associated_data\":\"fapiao\",\"nonce\":\"X7daAHdejNsm\"}}"; | 
|---|
|  |  |  | Map<String, Object> requestBody = JSONUtil.parseObj(body); | 
|---|
|  |  |  | String signature = "WECHATPAY/SIGNTEST/9WwfXW/noMdzDPcOrFD51Bf5YIThXLTtLCl5hoGlSfIBdY2UpE+5eHLs0XyF7y2cQc4OlzTzDDxSMTp/p/8ZenE2hMBaQjxVrdbTtrOLA1h13/WjCNaTr1URTqQ5+IF5bLCxAW8BmZ0jEqpmI/HYR3wdK8/7W91c1zfKODYgkvJzxFzd8OWi2GtELE5tLamkOLyb0GEcsGww2DUOypO5HjNyITgsy9R00w3OH92UInCD8Z6c5BAsQNySqFK8N52y38AlIWTtKROHmJtu+kHbt+nMOU0kbB5bZcPAptsnVYpp9KMmjMrmyjiKtHZb2TGIWiN/L+bgceyN3g=="; | 
|---|
|  |  |  | //构造验签名串 | 
|---|
|  |  |  | String signatureStr = timestamp + "\n" + nonce + "\n" + com.alibaba.fastjson.JSONObject.toJSONString(requestBody) + "\n"; | 
|---|
|  |  |  | System.out.println(signature.length()); | 
|---|
|  |  |  | System.out.println(signature); | 
|---|
|  |  |  | System.out.println(signatureStr.length()); | 
|---|
|  |  |  | System.out.println(signatureStr); | 
|---|
|  |  |  | // 加载SHA256withRSA签名器 | 
|---|
|  |  |  | Signature signer = Signature.getInstance("SHA256withRSA"); | 
|---|
|  |  |  | // 用微信平台公钥对签名器进行初始化(调上一节中的获取平台证书方法) | 
|---|
|  |  |  | signer.initVerify(x509Certificate); | 
|---|
|  |  |  | // 把我们构造的验签名串更新到签名器中 | 
|---|
|  |  |  | signer.update(signatureStr.getBytes(StandardCharsets.UTF_8)); | 
|---|
|  |  |  | // 把请求头中微信服务器返回的签名用Base64解码 并使用签名器进行验证 | 
|---|
|  |  |  | boolean result = signer.verify(Base64Utils.decodeFromString(signature)); | 
|---|
|  |  |  | System.out.println(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | BigDecimal amount = new BigDecimal("0.15").setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | System.out.println(amount); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Test | 
|---|
|  |  |  | public void aaaTest() { | 
|---|
|  |  |  | //        agentConsumer.vipLevelUp(133L); | 
|---|
|  |  |  | agentConsumer.getScoreMsg(152L); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|