14
14
import com .egzosn .pay .common .util .str .StringUtils ;
15
15
import com .egzosn .pay .wx .bean .*;
16
16
17
- import java .io .IOException ;
18
- import java .io .InputStream ;
17
+ import java .io .*;
19
18
import java .net .URLEncoder ;
20
19
import java .security .GeneralSecurityException ;
21
20
import java .util .*;
@@ -537,7 +536,18 @@ public Map<String, Object> refundquery(RefundOrder refundOrder) {
537
536
@ Override
538
537
public Map <String , Object > downloadbill (Date billDate , String billType ) {
539
538
Map <String , Object > parameters = getDownloadBillParam (billDate , billType ,false );
540
- return downBillRet (parameters );
539
+ //设置签名
540
+ setSign (parameters );
541
+ String respStr = requestTemplate .postForObject (getReqUrl (WxTransactionType .DOWNLOADBILL ), XML .getMap2Xml (parameters ), String .class );
542
+ if (respStr .indexOf ("<" ) == 0 ) {
543
+ return XML .toJSONObject (respStr );
544
+ }
545
+
546
+ Map <String , Object > ret = new HashMap <String , Object >(3 );
547
+ ret .put (RETURN_CODE , SUCCESS );
548
+ ret .put (RETURN_MSG_CODE , "ok" );
549
+ ret .put ("data" , respStr );
550
+ return ret ;
541
551
}
542
552
543
553
/**
@@ -551,30 +561,61 @@ public Map<String, Object> downloadbill(Date billDate, String billType) {
551
561
@ Override
552
562
public Map <String , Object > downloadbill (Date billDate , String billType , boolean tarType ) {
553
563
Map <String , Object > parameters = getDownloadBillParam (billDate , billType ,tarType ==true ?true :false );
554
- //设置签名
555
- return downBillRet (parameters );
556
- }
557
-
558
- /**
559
- * 账单根据参数返回结果
560
- * @param parameters
561
- * @return
562
- */
563
- private Map <String , Object > downBillRet (Map <String , Object > parameters ) {
564
- //设置签名
564
+ //设置签名
565
565
setSign (parameters );
566
- String respStr = requestTemplate .postForObject (getReqUrl (WxTransactionType .DOWNLOADBILL ), XML .getMap2Xml (parameters ), String .class );
567
- if (respStr .indexOf ("<" ) == 0 ) {
568
- return XML .toJSONObject (respStr );
566
+ InputStream inputStream = requestTemplate .postForObject (getReqUrl (WxTransactionType .DOWNLOADBILL ), XML .getMap2Xml (parameters ), InputStream .class );
567
+
568
+ //写到本地1.zip 里面有个1文件,用txt打开即可。返回路径,这个类需要抽离到工具类
569
+ //入参需要文件存放路径,这样四个参数略多,是否需要封装一个实体。或者直接更改第三个参数就是路径,有路径默认传true
570
+ try {
571
+ writeToLocal ("D:\\ 1.zip" , inputStream );
572
+ } catch (IOException e ) {
573
+ e .printStackTrace ();
569
574
}
570
575
571
576
Map <String , Object > ret = new HashMap <String , Object >(3 );
572
577
ret .put (RETURN_CODE , SUCCESS );
573
578
ret .put (RETURN_MSG_CODE , "ok" );
574
- ret .put ("data" , respStr );
579
+ // ret.put("data", hashMap );
575
580
return ret ;
576
581
}
577
582
583
+ /**
584
+ * 将InputStream写入本地文件
585
+ * @param destination 写入本地目录
586
+ * @param inputStream 输入流
587
+ * @throws IOException IOException
588
+ */
589
+ private void writeToLocal (String destination , InputStream inputStream )
590
+ throws IOException {
591
+
592
+ // 判断字节大小
593
+ if (inputStream .available () != 0 ) {
594
+ System .out .println ("结果大小:" + inputStream .available ());
595
+ File file = new File (destination );
596
+ if (!file .getParentFile ().exists ()) {
597
+ boolean result = file .getParentFile ().mkdirs ();
598
+ if (!result ) {
599
+ System .out .println ("创建失败" );
600
+ }
601
+ }
602
+ OutputStream out = new FileOutputStream (file );
603
+ int size = 0 ;
604
+ int len = 0 ;
605
+ byte [] buf = new byte [1024 ];
606
+ while ((size = inputStream .read (buf )) != -1 ) {
607
+ len += size ;
608
+ out .write (buf , 0 , size );
609
+ }
610
+ System .out .println ("最终写入字节数大小:" + len );
611
+ inputStream .close ();
612
+ out .close ();
613
+
614
+ }
615
+
616
+ }
617
+
618
+
578
619
/**
579
620
* 下载账单公共参数
580
621
* @param billDate 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单;
0 commit comments