航天信息金税盘接口 js 调用

news/2024/10/19 2:20:36/

航天信息金税盘接口 js 调用

个人博客: https://blog.joden123.top
原文地址: https://blog.joden123.top/2018/12/02/essay/gold-tax-js/

背景

最近项目要求与单机版的金税盘接口进行对接,在这里简单记录一下自己的开发经验,希望可以帮助到有需要的人

PS:接口使用 js 对接,仅支持 ie 浏览器。

前置条件

在进行开发时候需要有一些前置条件

  1. ie 浏览器
  • 开启 activeX 控件

    设置 --> Internet 选项 --> 安全 --> 自定义级别

    activeX 相关设置勾上

    可参考:

  • 管理员身份运行调试

    如果开票软件安装到本地 C盘 需要使用管理员打开 ie 浏览器,然后再进行调试

  1. 金税盘安装

    • 要确保金税盘安装准确安装了TaxCardX.dll

通用 js代码

/** 航信金税盘相关function */
var goldTax = {/*** 使用前先判断是否是ie浏览器* @return true/false*/isIE: function () {if(!!window.ActiveXObject || "ActiveXObject" in window)return true;elsereturn false;},/*** 开启金税盘* @param certPassword 单机版为证书口令  服务器版为地址 留空则读取开票BIN文件下cert.txt* @return * <pre>*     {*        'success': true/false, // 成功或者失败*        'code': -1/其他, // 错误码,-1 为系统错误*        'msg': 'xxx', // 错误信息*        'data': {} // 接口返回相关数据*     }* </pre>*/openCard: function (certPassword) {var result = {'success': false,'code': -1,'msg': '','data': {}};try {goldTax.card = new ActiveXObject("TaxCardX.GoldTax");// 单机版为证书口令  服务器版为地址 留空则读取开票BIN文件下cert.txtif(typeof certPassword != 'undefined') {goldTax.card.CertPassword = certPassword;}// 开启金税盘goldTax.card.OpenCard();result.code = goldTax.card.RetCode;result.msg = goldTax.card.RetMsg;// 1011 开启成功if (result.code == 1011) {result.success = true;result.data = {RetCode: goldTax.card.RetCode, /* RetCode - 状态码, 1011 开启成功 */RetMsg: goldTax.card.RetMsg, /* RetMsg 状态信息 */InvLimit: goldTax.card.InvLimit, /* InvLimit – 开票限额, 金税卡发票开具价税合计限额 */TaxCode: goldTax.card.TaxCode, /* TaxCode 本单位税号 */TaxClock: goldTax.card.TaxClock, /* TaxClock – 金税卡时钟 */MachineNo: goldTax.card.MachineNo, /* MachineNo – 开票机号码,主开票机为 0 */IsInvEmpty: goldTax.card.IsInvEmpty, /* IsInvEmpty – 有票标志,0为金税卡中无可开发票,1为有票 */IsRepReached: goldTax.card.IsRepReached, /* IsRepReached – 抄税标志,0为未到抄税期,1为已到抄税期 */IsLockReached: goldTax.card.IsLockReached, /* IsLockReached – 锁死标志,0为未到锁死期,1为已到锁死期 */};} else {result.success = false;}} catch (e) {result.success = false;result.code = -1;result.msg = 'ActiveX Error, ' + e.description;}return result;},/*** 关闭金税盘* @return* <pre>*     {*        'success': true/false, // 成功或者失败*        'code': -1/其他, // 错误码,-1 为系统错误*        'msg': 'xxx' // 错误信息*     }* </pre>*/closeCard: function() {var result = {'success': false,'code': -1,'msg': ''};if (typeof goldTax.card != 'undefined') {try {goldTax.card.closeCard();result.code = goldTax.card.RetCode;result.msg = goldTax.card.RetMsg;// RetCode 9000 调用成功,其他失败if (result.code == 9000) {result.success = true;} else {result.success = false;}} catch (e) {result.success = false;result.code = -1;result.msg = 'ActiveX Error, ' + e.description;}return result;}},/*** 查询库存发票* @param invKind 发票种类* @return * <pre>*     {*        'success': true/false, // 成功或者失败*        'code': -1/其他, // 错误码,-1 为系统错误*        'msg': 'xxx', // 错误信息*        'data': {} // 接口返回相关数据*     }* </pre>*/invoiceInventory: function(invKind) {var result = {'success': false,'code': -1,'msg': '','data': {}};try {if (typeof goldTax.card != 'undefined') {goldTax.card.InfoKind = invKind;goldTax.card.GetInfo();result.code = goldTax.card.RetCode;result.msg = goldTax.card.RetMsg;// RetCode 3011 读取成功,其他失败if (result.code == 3011) {result.success = true;result.data = {RetCode: goldTax.card.RetCode, /* RetCode - 状态码, 3011 读取成功,其他失败 */RetMsg: goldTax.card.RetMsg, /* RetMsg 状态信息 */InfoTypeCode: goldTax.card.InfoTypeCode, /* 要开具发票的十位代码。为空或全为0时,表示无可用发票 */InfoNumber: goldTax.card.InfoNumber, /* 要开具发票的号码 */InvStock: goldTax.card.InvStock, /* 剩余的可用发票份数 */TaxClock: goldTax.card.TaxClock /* 金税盘时钟 */};} else {result.success = false;}} else {result.success = false;result.code = -1;result.msg = 'Please Open Card First';}} catch (e) {result.success = false;result.code = -1;result.msg = 'ActiveX Error, ' + e.description;}return result;},/*** 发票校验* @param o 传入发票信息* @return * <pre>*     {*        'success': true/false, // 成功或者失败*        'code': -1/其他, // 错误码,-1 为系统错误*        'msg': 'xxx', // 错误信息*        'data': {} // 接口返回相关数据*     }* </pre>*/invoiceVeriferify: function(o) {return goldTax.inner.invoice(1, o);},/*** 发票开具* @param o 传入发票信息* @return * <pre>*     {*        'success': true/false, // 成功或者失败*        'code': -1/其他, // 错误码,-1 为系统错误*        'msg': 'xxx', // 错误信息*        'data': {} // 接口返回相关数据*     }* </pre>*/invoicing: function(o) {return goldTax.inner.invoice(0, o);},/*** 发票打印* @param o 传入发票信息* @return * <pre>*     {*        'success': true/false, // 成功或者失败*        'code': -1/其他, // 错误码,-1 为系统错误*        'msg': 'xxx' // 错误信息*     }* </pre>*/printInv: function(o) {var result = {'success': false,'code': -1,'msg': ''};try {if (typeof goldTax.card != 'undefined') {goldTax.card.InfoKind = o.InfoKind; /* 发票种类(0:专用发票  2:普通发票  11:货物运输业增值税专用发票  12:机动车销售统一发票) */goldTax.card.InfoTypeCode = o.InfoTypeCode; /* 要打印发票的十位代码 */goldTax.card.InfoNumber = o.InfoNumber; /* 要打印发票的号码 */goldTax.card.GoodsListFlag = o.GoodsListFlag; /* 销货清单标志,0 – 打印发票,1 – 打印销货清单 */goldTax.card.InfoShowPrtDlg = o.InfoShowPrtDlg; /* 打印时是否显示边距确认对话框,0 – 不出现,1 – 出现 */// 调用接口goldTax.card.PrintInv();result.code = goldTax.card.RetCode;result.msg = goldTax.card.RetMsg;// RetCode 5011 打印成功,5001 – 未找到发票或清单,5012 – 未打印,5013 – 打印失败if (result.code == 5011) {result.success = true;} else {result.success = false;}} else {result.success = false;result.code = -1;result.msg = 'Please Open Card First';}}  catch (e) {result.success = false;result.code = -1;result.msg = 'ActiveX Error, ' + e.description;}return result;},/*** 已开发票作废* @param o 传入发票信息* @return * <pre>*     {*        'success': true/false, // 成功或者失败*        'code': -1/其他, // 错误码,-1 为系统错误*        'msg': 'xxx' // 错误信息*     }* </pre>*/cancelInv: function(o) {var result = {'success': false,'code': -1,'msg': ''};try {if (typeof goldTax.card != 'undefined') {goldTax.card.InfoKind = o.InfoKind; /* 发票种类(0:专用发票  2:普通发票  11:货物运输业增值税专用发票  12:机动车销售统一发票) */goldTax.card.InfoTypeCode = o.InfoTypeCode; /* 要作废发票的十位或十二位代码 */goldTax.card.InfoNumber = o.InfoNumber; /* 要作废发票的号码 */// 调用接口goldTax.card.CancelInv();result.code = goldTax.card.RetCode;result.msg = goldTax.card.RetMsg;// RetCode 6011 打印成功,6001 – 当月发票库未找到该发票,6002 – 该发票已经作废,6012 – 作废失败,6013 – 作废失败(异常)if (result.code == 6011) {result.success = true;} else {result.success = false;}} else {result.success = false;result.code = -1;result.msg = 'Please Open Card First';}}  catch (e) {result.success = false;result.code = -1;result.msg = 'ActiveX Error, ' + e.description;}return result;},// 内部方法inner: {/*** invoice 接口* @param checkEWM 默认为0(0: 发票开具, 1: 发票校验, 2: 空白作废)* @param o 传入发票信息* @return * <pre>*     {*        'success': true/false, // 成功或者失败*        'code': -1/其他, // 错误码,-1 为系统错误*        'msg': 'xxx', // 错误信息*        'data': {} // 接口返回相关数据*     }* </pre>*/invoice: function(checkEWM, o) {var result = {'success': false,'code': -1,'msg': '','data': {}};try {if (typeof goldTax.card != 'undefined') {// CheckEWM值默认为0(为1时用于发票校验。// 注意:一旦CheckEWM值置1用于发票校验之后,//如果要再进行发票开具必须手动将CheckEWM值置为0,否则Invoice()方法的功能将一直处于发票校验状态)goldTax.card.CheckEWM = checkEWM; goldTax.card.InvInfoInit(); /* 初始化发票抬头信息 */goldTax.card.InfoKind = o.InfoKind; /* 增值税普通发票2 专票0 */goldTax.card.InfoClientName = o.InfoClientName; /* 购方名称 */goldTax.card.InfoClientTaxCode = o.InfoClientTaxCode; /* 购方税号 */goldTax.card.InfoClientBankAccount = o.InfoClientBankAccount; /* 购方开户行及账号 */goldTax.card.InfoClientAddressPhone = o.InfoClientAddressPhone; /* 购方地址电话 */goldTax.card.InfoSellerBankAccount = o.InfoSellerBankAccount; /* 销方开户行及账号 */goldTax.card.InfoSellerAddressPhone = o.InfoSellerAddressPhone; /* 销方地址电话 */// 如果是多商品多税率 税率应该放到下面商品信息循环里if (typeof o.InfoTaxRate != 'undefined' && o.InfoTaxRate) { goldTax.card.InfoTaxRate = o.InfoTaxRate; /* 税率,(已授权的税率, 17% 传17) */}goldTax.card.InfoNotes = o.InfoNotes; /* 备注 */goldTax.card.InfoInvoicer = o.InfoInvoicer; /* 开票人 */// 复核人,可为空if (typeof o.InfoChecker != 'undefined' && o.InfoChecker) {goldTax.card.InfoChecker = o.InfoChecker;}// 收款人,可为空if (typeof o.InfoCashier != 'undefined' && o.InfoCashier) {goldTax.card.InfoCashier = o.InfoCashier;}// 如不为空,则开具销货清单,此为发票上商品名称栏的清单信息,应为“(详见销货清单)”字样if (typeof o.InfoListName != 'undefined' && o.InfoListName) { goldTax.card.InfoListName = o.InfoListName;}// 清空商品明细列表goldTax.card.ClearInvList(); // 遍历行$.each(o.InvList, function(i, v) {goldTax.card.InvListInit(); /* 初始化发票明细信息各项属性 */goldTax.card.ListGoodsName = v.ListGoodsName; /* 商品或劳务名称 */goldTax.card.ListTaxItem = v.ListTaxItem; /* 税目,4位数字,商品所属类别 */goldTax.card.ListStandard = v.ListStandard; /* 规格型号 */// 计量单位,如计量单位为空,则忽略数量和单价if (typeof v.ListUnit != 'undefined' && v.ListUnit) {goldTax.card.ListUnit = v.ListUnit;}// 建议传入数量和含税单价或含税金额 由接口计算带小数的税额 规避误差goldTax.card.ListNumber = v.ListNumber; // 数量goldTax.card.ListPrice = v.ListPrice; // 单价// 金额,可以不传(为0),由接口软件计算,如传入则应符合计算关系if (typeof v.ListAmount != 'undefined' && v.ListAmount ) {goldTax.card.ListAmount = v.ListAmount;}goldTax.card.ListPriceKind = v.ListPriceKind; /* 含税价标志,单价和金额的种类, 0为不含税价,1为含税价 */// 税额可以不传(为0),由接口软件计算,如传入则应符合计算关系if (typeof v.ListTaxAmount != 'undefined' && v.ListTaxAmount) {goldTax.card.ListTaxAmount = v.ListTaxAmount;}// 添加一行goldTax.card.AddInvList();});// 调用接口goldTax.card.Invoice();result.code = goldTax.card.RetCode;result.msg = goldTax.card.RetMsg;// RetCode 4011 开票成功,其他失败if (result.code == 4011) {result.success = true;result.data = {RetCode: goldTax.card.RetCode, /* RetCode - 状态码, 3011 读取成功,其他失败 */RetMsg: goldTax.card.RetMsg, /* RetMsg 状态信息 */InfoAmount: goldTax.card.InfoAmount , /* 合计不含税金额 */InfoTaxAmount: goldTax.card.InfoTaxAmount, /* 合计税额 */InfoInvDate: goldTax.card.InfoInvDate, /* 开票日期 */InfMonth: goldTax.card.InfMonth, /* 所属月份 */InfoTypeCode: goldTax.card.InfoTypeCode, /* 发票十位代码 */InfoNumber: goldTax.card.InfoNumber, /* 发票号码 */GoodsListFlag: goldTax.card.GoodsListFlag /* 销货清单标志,0 – 无销货清单,1 – 有销货清单 */};} else {result.success = false;}} else {result.success = false;result.code = -1;result.msg = 'Please Open Card First';}} catch (e) {result.success = false;result.code = -1;result.msg = 'ActiveX Error, ' + e.description;}return result;}}
};

相关资料

CSDN 需要积分下载 金税 防伪税控 组件接口 开发文档 代码案例

没有积分的 戳这里


http://www.ppmy.cn/news/685191.html

相关文章

航天金税3发票导入功能开发教程(一)

前言 此教程是通用教程,无关开发语言, 只要按这个方法,应该就可以实现批量开票功能 程序是大概是2016年的9月开发的,虽然5,6年了,但这个方法应该还是可用。 公司以前是hook航天金税软件,去处理开票, 在我去的那年,人家升级了,于是不能自动开票了,当时这个开票功…

软件更新|增值税发票税控开票软件(金税盘版_V2.051ZS_20221031)

公开 FWSK(KP)_ V2.0.51_ZS_20221031 综合说明 一&#xff0e;补丁下发说明 版本号 V2.0.51 补丁编号 FWSK(KP)_ V2.0.51_ZS_20221031 系统 名称 增值税发票税控开票软件&#xff08;金税盘版&#xff09;V2.0.51 下发日期 2022-10-30 升级 范围 全国范围 下发 原…

TP6在composer包里写控制器

前提&#xff1a;首先要了解下如何自建composer包。 1.先建一个空包&#xff0c;加一个文件&#xff1a;composer.json {"name": "test/ctrs","type": "library","license": "MIT","autoload": {&quo…

可用性测试基本概念和常见测试方法

可用性测试是一种非功能类型的软件测试。大致分为可理解性、可学习性、可操作性、吸引力、合规性。可用性测试是确定软件产品在规定的条件和要求下对用户的理解程度、易学性、易操作性以及对用户的吸引力的程度。 这种类型的测试通常由现实生活中的用户而不是开发团队执行。开…

升级鸿蒙系统好不好用,昨天随手发了一个有关升级鸿蒙系统后的使用体会,没料到引发这么大的讨论。看来大家对这个话题关注度很高。作为一个普通消费者,... - 雪球...

来源&#xff1a;雪球App&#xff0c;作者&#xff1a; 新山野&#xff0c;(https://xueqiu.com/1343651531/181846205) 昨天随手发了一个有关升级鸿蒙系统后的使用体会&#xff0c;没料到引发这么大的讨论。看来大家对这个话题关注度很高。作为一个普通消费者&#xff0c; 没有…

iqooneo系统升级好不好_vivo iQOO手机系统更新好吗?

IQOO为VIVO旗下子品牌&#xff0c;该手机搭载骁龙855处理器&#xff0c;采用6.41英寸的AMOLED灵动水滴屏&#xff0c;屏占比高达91.7%。全系标配DSP屏幕指纹&#xff0c;中框采用超跑腰线处理&#xff0c;纤薄质感&#xff0c;后盖采用暗夜光轨设计&#xff0c;两扇惊艳的电光纹…

荣耀还能不能升级鸿蒙系统,为什么荣耀手机不能第一时间升级鸿蒙系统,应该是这个原因吧...

「来源: &#xff5c;创业者李孟 ID&#xff1a;cyzlimeng」 鸿蒙系统都出了&#xff0c;为什么荣耀不第一时间用&#xff1f; 的确比较晚&#xff0c;第四季度荣耀的手机才能开始更新&#xff0c;不过能够支持更新已经不错了&#xff0c;对于荣耀来说&#xff0c;应该是荣耀老…

怎么更新鸿蒙系统mate10,能不能升级鸿蒙系统?

电梯直达 huafen185613402 初窥门径 发表于 2021-2-28 14:28:33 来自&#xff1a;华为Mate 10 Pro 最新回复 2021-2-28 17:34:28 这个手机现在性能还非常好呀&#xff0c;期待能够给予鸿蒙系统升级 产品型号BLA-AL00 出现频率总是 问题类型其他 应用名称Android 系统 应用版本1…