2
2
3
3
import com .github .binarywang .utils .qrcode .QrcodeUtils ;
4
4
import com .github .binarywang .wxpay .bean .coupon .*;
5
- import com .github .binarywang .wxpay .bean .notify .WxPayOrderNotifyResult ;
6
- import com .github .binarywang .wxpay .bean .notify .WxPayOrderNotifyResultTest ;
5
+ import com .github .binarywang .wxpay .bean .notify .*;
7
6
import com .github .binarywang .wxpay .bean .order .WxPayAppOrderResult ;
8
7
import com .github .binarywang .wxpay .bean .order .WxPayMpOrderResult ;
9
8
import com .github .binarywang .wxpay .bean .order .WxPayNativeOrderResult ;
10
9
import com .github .binarywang .wxpay .bean .request .*;
11
10
import com .github .binarywang .wxpay .bean .result .*;
12
11
import com .github .binarywang .wxpay .bean .result .enums .TradeTypeEnum ;
13
12
import com .github .binarywang .wxpay .config .WxPayConfig ;
13
+ import com .github .binarywang .wxpay .constant .WxPayConstants ;
14
14
import com .github .binarywang .wxpay .constant .WxPayConstants .AccountType ;
15
15
import com .github .binarywang .wxpay .constant .WxPayConstants .BillType ;
16
16
import com .github .binarywang .wxpay .constant .WxPayConstants .SignType ;
19
19
import com .github .binarywang .wxpay .service .WxPayService ;
20
20
import com .github .binarywang .wxpay .testbase .ApiTestModule ;
21
21
import com .github .binarywang .wxpay .testbase .XmlWxPayConfig ;
22
+ import com .github .binarywang .wxpay .util .RequestUtils ;
22
23
import com .github .binarywang .wxpay .util .XmlConfig ;
23
24
import com .google .gson .Gson ;
24
25
import com .google .gson .GsonBuilder ;
29
30
import org .testng .annotations .Guice ;
30
31
import org .testng .annotations .Test ;
31
32
33
+ import javax .servlet .http .HttpServletRequest ;
34
+ import javax .servlet .http .HttpServletResponse ;
35
+ import java .math .BigDecimal ;
32
36
import java .nio .file .Files ;
33
37
import java .nio .file .Path ;
34
38
import java .util .Calendar ;
35
39
import java .util .Date ;
40
+ import java .util .Optional ;
36
41
37
42
import static com .github .binarywang .wxpay .constant .WxPayConstants .TarType ;
38
43
import static org .assertj .core .api .Assertions .assertThat ;
@@ -728,9 +733,9 @@ public void testUnifiedOrderV3() throws WxPayException {
728
733
//构建金额信息
729
734
WxPayUnifiedOrderV3Request .Amount amount = new WxPayUnifiedOrderV3Request .Amount ();
730
735
//设置币种信息
731
- amount .setCurrency (" CNY" );
736
+ amount .setCurrency (WxPayConstants . CurrencyType . CNY );
732
737
//设置金额
733
- amount .setTotal (1 );
738
+ amount .setTotal (BaseWxPayRequest . yuan2Fen ( BigDecimal . ONE ) );
734
739
request .setAmount (amount );
735
740
736
741
WxPayUnifiedOrderV3Result .JsapiResult result = this .payService .createOrderV3 (TradeTypeEnum .JSAPI , request );
@@ -767,6 +772,63 @@ public void testRefundV3() throws WxPayException {
767
772
System .out .println (GSON .toJson (result ));
768
773
}
769
774
775
+ /**
776
+ * 测试V3支付成功回调
777
+ * https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_5.shtml
778
+ *
779
+ * @throws Exception the exception
780
+ */
781
+ @ Test
782
+ public void testParseOrderNotifyV3Result (HttpServletRequest request , HttpServletResponse response ) throws Exception {
783
+
784
+ String timestamp = request .getHeader ("Wechatpay-Timestamp" );
785
+ Optional .ofNullable (timestamp ).orElseThrow (() -> new RuntimeException ("时间戳不能为空" ));
786
+
787
+ String nonce = request .getHeader ("Wechatpay-Nonce" );
788
+ Optional .ofNullable (nonce ).orElseThrow (() -> new RuntimeException ("nonce不能为空" ));
789
+
790
+ String serialNo = request .getHeader ("Wechatpay-Serial" );
791
+ Optional .ofNullable (serialNo ).orElseThrow (() -> new RuntimeException ("serialNo不能为空" ));
792
+
793
+ String signature = request .getHeader ("Wechatpay-Signature" );
794
+ Optional .ofNullable (signature ).orElseThrow (() -> new RuntimeException ("signature不能为空" ));
795
+
796
+ log .info ("请求头参数为:timestamp:{} nonce:{} serialNo:{} signature:{}" , timestamp , nonce , serialNo , signature );
797
+
798
+ // V2版本请参考com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResultTest里的单元测试
799
+ final WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = this .payService .parseOrderNotifyV3Result (RequestUtils .readData (request ),
800
+ new SignatureHeader (timestamp , nonce , signature , serialNo ));
801
+ log .info (GSON .toJson (wxPayOrderNotifyV3Result ));
802
+ }
803
+
804
+ /**
805
+ * 测试V3退款成功回调
806
+ * https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_11.shtml
807
+ *
808
+ * @throws Exception the exception
809
+ */
810
+ @ Test
811
+ public void testParseRefundNotifyV3Result (HttpServletRequest request , HttpServletResponse response ) throws Exception {
812
+
813
+ String timestamp = request .getHeader ("Wechatpay-Timestamp" );
814
+ Optional .ofNullable (timestamp ).orElseThrow (() -> new RuntimeException ("时间戳不能为空" ));
815
+
816
+ String nonce = request .getHeader ("Wechatpay-Nonce" );
817
+ Optional .ofNullable (nonce ).orElseThrow (() -> new RuntimeException ("nonce不能为空" ));
818
+
819
+ String serialNo = request .getHeader ("Wechatpay-Serial" );
820
+ Optional .ofNullable (serialNo ).orElseThrow (() -> new RuntimeException ("serialNo不能为空" ));
821
+
822
+ String signature = request .getHeader ("Wechatpay-Signature" );
823
+ Optional .ofNullable (signature ).orElseThrow (() -> new RuntimeException ("signature不能为空" ));
824
+
825
+ log .info ("支付请求头参数为:timestamp:{} nonce:{} serialNo:{} signature:{}" , timestamp , nonce , serialNo , signature );
826
+
827
+ final WxPayRefundNotifyV3Result wxPayRefundNotifyV3Result = this .payService .parseRefundNotifyV3Result (RequestUtils .readData (request ),
828
+ new SignatureHeader (timestamp , nonce , signature , serialNo ));
829
+ log .info (GSON .toJson (wxPayRefundNotifyV3Result ));
830
+ }
831
+
770
832
@ Test
771
833
public void testRefundQueryV3 () throws WxPayException {
772
834
WxPayRefundQueryV3Request request = new WxPayRefundQueryV3Request ();
@@ -778,10 +840,11 @@ public void testRefundQueryV3() throws WxPayException {
778
840
779
841
/**
780
842
* 测试包含正向代理的测试
843
+ *
781
844
* @throws WxPayException
782
845
*/
783
846
@ Test
784
- public void testQueryOrderV3WithProxy () {
847
+ public void testQueryOrderV3WithProxy () {
785
848
try {
786
849
WxPayOrderQueryV3Request request = new WxPayOrderQueryV3Request ();
787
850
request .setOutTradeNo ("n1ZvYqjAg3D3LUBa" );
0 commit comments