luodangjia
2024-05-30 a3990d3644885c51f4ea0fc7a27c1097f4808bfb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.stylefeng.guns.modular.system.kaipiao;
 
import com.alibaba.fastjson.JSONObject;
import com.stylefeng.guns.modular.system.kaipiao.entity.ReturnData;
import com.stylefeng.guns.modular.system.kaipiao.util.CreatAndSendUtil;
 
 
import java.nio.charset.StandardCharsets;
import java.util.Base64;
 
public class SptBlueInvOpenDemo {
 
    /**
     * 调用数票通接口开具蓝字发票
     * @param dataJson 需要开具发票的订单信息及明细组成的json字符串,具体字段见接口对接文档
     * @param appSecret 企业密钥 由江苏航信分配获取
     * @param appId 企业标识 由江苏航信分配获取
     * @return ReturnData
     */
    public static ReturnData blueInvOpen(String dataJson, String appSecret, String appId){
        /*
           TODO
            校验订单流水号(orderNo),不能为空且不能与已开票据的重复
         */
 
        //接口代码详见各业务接口说明 全电蓝字发票开具为:SALE.DZSJLZINVOPEN
        String interfaceCode = "SALE.DZSJLZINVOPEN";
 
        ReturnData returnData = CreatAndSendUtil.creatAndSend(dataJson, appSecret, appId, interfaceCode);
 
        if (returnData != null){
            if ("0000".equals(returnData.getReturn_info().getReturn_code())){
                String data = returnData.getData();
                byte[] decode = Base64.getDecoder().decode(data.getBytes(StandardCharsets.UTF_8));
                returnData.setData(new String(decode));
                JSONObject jsonObject = JSONObject.parseObject(new String(decode));
//                System.out.println("发票号码:" + jsonObject.get("fphm"));
//                System.out.println("开票日期:" + jsonObject.get("kprq"));
            /*
                TODO
                 开票成功,改变数据库中的数据等操作
             */
            }else {
            /*
                 开票失败,return_message查看失败原因
             */
            }
            return returnData;
        }
        return null;
    }
 
 
    public static ReturnData getUrl(String dataJson, String appSecret, String appId){
        /*
           TODO
            校验订单流水号(orderNo),不能为空且不能与已开票据的重复
         */
 
        //接口代码详见各业务接口说明 全电蓝字发票开具为:SALE.DZSJLZINVOPEN
        String interfaceCode = "SALE.QDINVDOWNURL";
 
        ReturnData returnData = CreatAndSendUtil.creatAndSend(dataJson, appSecret, appId, interfaceCode);
 
        if (returnData != null){
            if ("0000".equals(returnData.getReturn_info().getReturn_code())){
                String data = returnData.getData();
                byte[] decode = Base64.getDecoder().decode(data.getBytes(StandardCharsets.UTF_8));
                returnData.setData(new String(decode));
                JSONObject jsonObject = JSONObject.parseObject(new String(decode));
//                System.out.println("发票号码:" + jsonObject.get("fphm"));
//                System.out.println("开票日期:" + jsonObject.get("kprq"));
            /*
                TODO
                 开票成功,改变数据库中的数据等操作
             */
            }else {
            /*
                 开票失败,return_message查看失败原因
             */
            }
            return returnData;
        }
        return null;
    }
 
    public static ReturnData toEmail(String dataJson, String appSecret, String appId){
        /*
           TODO
            校验订单流水号(orderNo),不能为空且不能与已开票据的重复
         */
 
        //接口代码详见各业务接口说明 全电蓝字发票开具为:SALE.DZSJLZINVOPEN
        String interfaceCode = "SALE.OWNEMAILDELIVERY";
 
        ReturnData returnData = CreatAndSendUtil.creatAndSend(dataJson, appSecret, appId, interfaceCode);
 
        if (returnData != null){
            if ("0000".equals(returnData.getReturn_info().getReturn_code())){
                String data = returnData.getData();
                byte[] decode = Base64.getDecoder().decode(data.getBytes(StandardCharsets.UTF_8));
                returnData.setData(new String(decode));
                JSONObject jsonObject = JSONObject.parseObject(new String(decode));
//                System.out.println("发票号码:" + jsonObject.get("fphm"));
//                System.out.println("开票日期:" + jsonObject.get("kprq"));
            /*
                TODO
                 开票成功,改变数据库中的数据等操作
             */
            }else {
            /*
                 开票失败,return_message查看失败原因
             */
            }
            return returnData;
        }
        return null;
    }
 
    public static ReturnData checkEamil(String dataJson, String appSecret, String appId){
        /*
           TODO
            校验订单流水号(orderNo),不能为空且不能与已开票据的重复
         */
 
        //接口代码详见各业务接口说明 全电蓝字发票开具为:SALE.DZSJLZINVOPEN
        String interfaceCode = "SALE.OWNEMAILDELIVERYQUERY";
 
        ReturnData returnData = CreatAndSendUtil.creatAndSend(dataJson, appSecret, appId, interfaceCode);
 
        if (returnData != null){
            if ("0000".equals(returnData.getReturn_info().getReturn_code())){
                String data = returnData.getData();
                byte[] decode = Base64.getDecoder().decode(data.getBytes(StandardCharsets.UTF_8));
                returnData.setData(new String(decode));
                JSONObject jsonObject = JSONObject.parseObject(new String(decode));
//                System.out.println("发票号码:" + jsonObject.get("fphm"));
//                System.out.println("开票日期:" + jsonObject.get("kprq"));
            /*
                TODO
                 开票成功,改变数据库中的数据等操作
             */
            }else {
            /*
                 开票失败,return_message查看失败原因
             */
            }
            return returnData;
        }
        return null;
    }
 
 
}