From 60c63a51f1ac178066cad14e17aa748f4e8a4e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=B5=A9?= Date: Thu, 17 Sep 2020 10:45:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=94=B5=E5=95=86=E6=94=B6=E4=BB=98?= =?UTF-8?q?=E9=80=9A=E5=9B=9E=E8=B0=83=E9=80=9A=E7=9F=A5=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/EcommerceServiceImplTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java new file mode 100644 index 000000000..7d381f854 --- /dev/null +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java @@ -0,0 +1,48 @@ +package com.github.binarywang.wxpay.service.impl; + +import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; +import com.github.binarywang.wxpay.service.WxPayService; +import com.github.binarywang.wxpay.testbase.ApiTestModule; +import com.google.inject.Inject; +import lombok.extern.slf4j.Slf4j; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.nio.charset.StandardCharsets; + +@Slf4j +@Test +@Guice(modules = ApiTestModule.class) +public class EcommerceServiceImplTest { + + @Inject + private WxPayService wxPayService; + + @Test + public void testNotifySign(){ + //通知报文主体 + String notifyData = ""; + //请求头 Wechatpay-Timestamp + String timeStamp = ""; + //请求头 Wechatpay-Nonce + String nonce = ""; + //请求头 Wechatpay-Signature + String signed = ""; + //请求头 Wechatpay-Serial + String serialNo = ""; + + SignatureHeader header = new SignatureHeader(); + header.setNonce(nonce); + header.setSerialNo(serialNo); + header.setTimeStamp(timeStamp); + header.setSigned(signed); + + String beforeSign = String.format("%s\n%s\n%s\n", + header.getTimeStamp(), + header.getNonce(), + notifyData); + boolean signResult = wxPayService.getConfig().getVerifier().verify(header.getSerialNo(), + beforeSign.getBytes(StandardCharsets.UTF_8), header.getSigned()); + log.info("签名结果:{} \nheader:{} \ndata:{}", signResult, header, notifyData); + } +}