📄 qydzjskh.java
字号:
package testDzjs.yhServer.appInstance;
import testDzjs.yhServer.com.SendReceive;
import testDzjs.yhServer.com.YHBuildProtocol;
import java.net.Socket;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import logger.Logger;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2005-4-16
* Time: 22:45:32
* To change this template use File | Settings | File Templates.
*/
/**
* 企业电子缴税开户
*/
public class QyDzjsKh implements YhInterface{
SendReceive sendReceive = new SendReceive(); //发送接收实例
YHBuildProtocol buildProtocol = new YHBuildProtocol(); //构造协议实例
Socket socket = null; //套接字
BufferedInputStream in = null; //输入流
BufferedOutputStream out = null; //输出流
//请求包
private String packageType = "07"; //包类型
private String nshType = "2"; //纳税种类 1双定征收户(个体) 2建帐征收户(单位)
private String sbType = "2"; //申报方式 0电话申报 2计算机申报
private String nsrbm = "43040718517441X"; //纳税人识别号
private String yhdm = "02"; //银行代码 01工行 02农行 03中行 04建行
private String yhzhlx = "1"; //账号类型 1、对公账户 2、信用卡 3 灵通卡 4活期存折 5 综合帐户卡
private String yhzh = "111111111111"; //帐号
private String khsfzhm = "11111111" ; //开户人身份证号码
private String nshdh = "443322111"; //纳税人联系电话
private String swjg_dm = "14304071400"; //税务机关代码 有效位数只需5位
//请求包
private int[] sendLength = {2,1,1,22,2,1,50,20,20,11,};//请求包长度
private int[] receiveLength = {2,2,11,80,8,6,40};//返回包长度
//返回包
private String rPackageType = "04"; //返回包类型
private String rjybz = ""; //交易标志 00 成功 02已登记 05 纳税人识别号不存在 13 纳税人识别号重复 25 纳税人种类错99 其它08 帐户状态错不是双定征收户
private String rswjg_dm = ""; //纳税人税务机关代码
private String rnsrmc = ""; //纳税人名称
private String rdnbm = ""; //电脑编码
private String rsbmm = ""; //申报密码
private String rfkxx = ""; //反馈信息
//返回包
String[] receive = new String[7]; //返回包内容
private long sCount = 0;
private String tmp = "";
/**
* 外部调用入口
* @param socket
* @param in
* @param out
*/
public void start(Socket socket,BufferedInputStream in,BufferedOutputStream out,long l){
this.sCount = l;
this.socket = socket;
this.in = in;
this.out = out;
run();
}
/**
* 处理流程
*/
private void run(){
khcl();
sender(buildSendBody());
this.tmp = receiver();
System.out.println("{" + this.tmp + "}");
System.out.println("Dddddddddddddddd" + this.tmp.length());
jgcl();
parseReceiver(this.tmp);
}
/**
* 设置纳税号
*/
public void setNsrbm(String nsrbm){
this.nsrbm = nsrbm;
}
/**
* 设置税务机关代码
*/
public void setSwjgdm(String swjgdm){
this.swjg_dm = swjgdm;
}
public void setNsrmc(String nsrmc){
}
/**
* 向输出流发送数据
* @param message
*/
private void sender(byte[] message){
try {
sendReceive.sendByte(message,out);
} catch (IOException e) {
try {
this.socket.close();
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
}
/**
* 从输入流读取数据
* @return
*/
private String receiver(){
String receive = "";
try {
receive = sendReceive.receive(in);
this.socket.close();
} catch (IOException e) {
try {
this.socket.close();
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
Logger.getInstance().addInfo(sCount + "收到税局开户返回包:" + receive);
return receive;
}
public String getInfo(){
return "";
}
/**
* 开户处理
* 生成请求包中的值
*/
private void khcl(){
nshType = "2";
sbType = "2";
if(nsrbm.equals(""))
nsrbm = "43040718517441X";
yhdm = "02";
yhzhlx = "2";
yhzh = nsrbm;
khsfzhm = nsrbm;
nshdh = "8899123";
if(swjg_dm.equals(""))
swjg_dm = "14304071400";
}
/**
* 开户结果处理
*/
private void jgcl(){
if(!rPackageType.equals("04")){
System.out.println("返回包类型错误");
return;
}
if(!rjybz.equals("00")){
System.out.println("开户失败!错误代码:" + rjybz + " 反馈信息:" + rfkxx);
return;
//交易标志 00 成功 02已登记 05 纳税人识别号不存在 13 纳税人识别号重复 25 纳税人种类错99 其它08 帐户状态错不是双定征收户
}
rswjg_dm = this.receive[2]; //纳税人税务机关代码
rnsrmc = this.receive[3]; //纳税人名称
rdnbm = this.receive[4]; //电脑编码
rsbmm = this.receive[5]; //申报密码
rfkxx = this.receive[6]; //反馈信息
}
/**
* 解析返回包内容
* @param receive
*/
private void parseReceiver(String receive){
int startx = 0;
for(int i = 0;i < receiveLength.length;i ++){
this.receive[i] = readString(receive,startx,receiveLength[i]);
startx += receiveLength[i];
}
rPackageType = this.receive[0];
rjybz = this.receive[1]; //交易标志 00 成功 02已登记 05 纳税人识别号不存在 13 纳税人识别号重复 25 纳税人种类错99 其它08 帐户状态错不是双定征收户
rswjg_dm = this.receive[2]; //纳税人税务机关代码
rnsrmc = this.receive[3]; //纳税人名称
rdnbm = this.receive[4]; //电脑编码
rsbmm = this.receive[5]; //申报密码
rfkxx = this.receive[6]; //反馈信息
}
/**
* 字串读取
* @param str
* @param startx
* @param length
* @return
*/
private String readString(String str,int startx,int length){
return str.substring(startx,startx+length);
}
/**
* 构造请求包
* @return
*/
private byte[] buildSendBody(){
byte[] body;
String[] send = {packageType,nshType,sbType,nsrbm,yhdm,yhzhlx,yhzh,khsfzhm,nshdh,swjg_dm};
body = buildProtocol.getProtocolData(send,sendLength);
return body;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -