@@ -627,6 +627,42 @@ public void testParseOrderNotifyResult() throws Exception {
627627
628628 }
629629
630+ /**
631+ * Test parse order notify result with JSON format should give helpful error.
632+ * 测试当传入V3版本的JSON格式通知数据时,应该抛出清晰的错误提示
633+ *
634+ * @throws Exception the exception
635+ */
636+ @ Test
637+ public void testParseOrderNotifyResultWithJsonShouldGiveHelpfulError () throws Exception {
638+ String jsonString = "{\n " +
639+ " \" id\" : \" EV-2018022511223320873\" ,\n " +
640+ " \" create_time\" : \" 2015-05-20T13:29:35+08:00\" ,\n " +
641+ " \" resource_type\" : \" encrypt-resource\" ,\n " +
642+ " \" event_type\" : \" TRANSACTION.SUCCESS\" ,\n " +
643+ " \" summary\" : \" 支付成功\" ,\n " +
644+ " \" resource\" : {\n " +
645+ " \" algorithm\" : \" AEAD_AES_256_GCM\" ,\n " +
646+ " \" ciphertext\" : \" test\" ,\n " +
647+ " \" associated_data\" : \" transaction\" ,\n " +
648+ " \" nonce\" : \" test\" \n " +
649+ " }\n " +
650+ "}" ;
651+
652+ try {
653+ this .payService .parseOrderNotifyResult (jsonString );
654+ fail ("Expected WxPayException for JSON input" );
655+ } catch (WxPayException e ) {
656+ // 验证错误消息包含V3版本和parseOrderNotifyV3Result方法的指导信息
657+ String message = e .getMessage ();
658+ assertTrue (message .contains ("V3版本" ), "错误消息应包含'V3版本'" );
659+ assertTrue (message .contains ("JSON格式" ), "错误消息应包含'JSON格式'" );
660+ assertTrue (message .contains ("parseOrderNotifyV3Result" ), "错误消息应包含'parseOrderNotifyV3Result'方法名" );
661+ assertTrue (message .contains ("SignatureHeader" ), "错误消息应包含'SignatureHeader'" );
662+ log .info ("JSON格式检测正常,错误提示: {}" , message );
663+ }
664+ }
665+
630666 /**
631667 * Test get wx api data.
632668 *
0 commit comments