11package me .chanjar .weixin .mp .api .impl ;
22
3+ import com .github .binarywang .utils .qrcode .QrcodeUtils ;
34import com .google .inject .Inject ;
45import me .chanjar .weixin .common .exception .WxErrorException ;
56import me .chanjar .weixin .mp .api .ApiTestModule ;
1011import me .chanjar .weixin .mp .bean .pay .request .WxPaySendRedpackRequest ;
1112import me .chanjar .weixin .mp .bean .pay .request .WxPayUnifiedOrderRequest ;
1213import me .chanjar .weixin .mp .bean .pay .result .*;
14+ import org .testng .Assert ;
1315import org .testng .annotations .Guice ;
1416import org .testng .annotations .Test ;
1517
18+ import java .nio .file .Files ;
19+ import java .nio .file .Path ;
20+
1621/**
1722 * 测试支付相关接口
1823 * Created by Binary Wang on 2016/7/28.
2227@ Test
2328@ Guice (modules = ApiTestModule .class )
2429public class WxMpPayServiceImplTest {
25-
2630 @ Inject
2731 protected WxMpService wxService ;
2832
@@ -32,9 +36,17 @@ public void testGetPayInfo() throws Exception {
3236 }
3337
3438 /**
35- * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} .
39+ * 需要证书的接口需要先执行该方法
3640 */
3741 @ Test
42+ public void setSSLKey (){
43+ WxXmlMpInMemoryConfigStorage config = (WxXmlMpInMemoryConfigStorage ) this .wxService .getWxMpConfigStorage ();
44+ config .setSslContextFilePath (config .getKeyPath ());
45+ }
46+ /**
47+ * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} .
48+ */
49+ @ Test (dependsOnMethods = {"setSSLKey" })
3850 public void testRefund () throws Exception {
3951 WxPayRefundRequest request = new WxPayRefundRequest ();
4052 request .setOutRefundNo ("aaa" );
@@ -45,7 +57,6 @@ public void testRefund() throws Exception {
4557 System .err .println (result );
4658 }
4759
48-
4960 /**
5061 * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refundQuery(String, String, String, String)} .
5162 */
@@ -63,15 +74,10 @@ public void testRefundQuery() throws Exception {
6374 System .err .println (result );
6475 }
6576
66- @ Test
67- public void testCheckJSSDKCallbackDataSignature () throws Exception {
68-
69- }
70-
7177 /**
7278 * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#sendRedpack(WxPaySendRedpackRequest)} .
7379 */
74- @ Test
80+ @ Test ( dependsOnMethods = { "setSSLKey" })
7581 public void testSendRedpack () throws Exception {
7682 WxPaySendRedpackRequest request = new WxPaySendRedpackRequest ();
7783 request .setActName ("abc" );
@@ -86,7 +92,7 @@ public void testSendRedpack() throws Exception {
8692 /**
8793 * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryRedpack(String)}.
8894 */
89- @ Test
95+ @ Test ( dependsOnMethods = { "setSSLKey" })
9096 public void testQueryRedpack () throws Exception {
9197 WxPayRedpackQueryResult redpackResult = this .wxService .getPayService ().queryRedpack ("aaaa" );
9298 System .err .println (redpackResult );
@@ -125,7 +131,7 @@ public final void testCloseOrder() throws WxErrorException {
125131 /**
126132 * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest)}.
127133 */
128- @ Test
134+ @ Test ( dependsOnMethods = { "setSSLKey" })
129135 public final void testEntPay () throws WxErrorException {
130136 WxEntPayRequest request = new WxEntPayRequest ();
131137 System .err .println (this .wxService .getPayService ().entPay (request ));
@@ -134,8 +140,33 @@ public final void testEntPay() throws WxErrorException {
134140 /**
135141 * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String)}.
136142 */
137- @ Test
143+ @ Test ( dependsOnMethods = { "setSSLKey" })
138144 public final void testQueryEntPay () throws WxErrorException {
139145 System .err .println (this .wxService .getPayService ().queryEntPay ("11212121" ));
140146 }
147+
148+ @ Test
149+ public void testCreateScanPayQrcodeMode1 () throws Exception {
150+ String productId = "abc" ;
151+ byte [] bytes = this .wxService .getPayService ().createScanPayQrcodeMode1 (productId , null , null );
152+ Path qrcodeFilePath = Files .createTempFile ("qrcode_" , ".jpg" );
153+ Files .write (qrcodeFilePath , bytes );
154+ String qrcodeContent = QrcodeUtils .decodeQrcode (qrcodeFilePath .toFile ());
155+ System .out .println (qrcodeContent );
156+
157+ Assert .assertTrue (qrcodeContent .startsWith ("weixin://wxpay/bizpayurl?" ));
158+ Assert .assertTrue (qrcodeContent .contains ("product_id=" + productId ));
159+ }
160+
161+ @ Test
162+ public void testCreateScanPayQrcodeMode2 () throws Exception {
163+ String qrcodeContent = "abc" ;
164+ byte [] bytes = this .wxService .getPayService ().createScanPayQrcodeMode2 (qrcodeContent , null , null );
165+ Path qrcodeFilePath = Files .createTempFile ("qrcode_" , ".jpg" );
166+ Files .write (qrcodeFilePath , bytes );
167+
168+ Assert .assertEquals (QrcodeUtils .decodeQrcode (qrcodeFilePath .toFile ()), qrcodeContent );
169+ }
170+
171+
141172}
0 commit comments