航天信息金税盘接口 js 调用
生活随笔
收集整理的這篇文章主要介紹了
航天信息金税盘接口 js 调用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
航天信息金稅盤接口 js 調(diào)用
個人博客: https://blog.joden123.top
原文地址: https://blog.joden123.top/2018/12/02/essay/gold-tax-js/
背景
最近項目要求與單機版的金稅盤接口進(jìn)行對接,在這里簡單記錄一下自己的開發(fā)經(jīng)驗,希望可以幫助到有需要的人
PS:接口使用 js 對接,僅支持 ie 瀏覽器。
前置條件
在進(jìn)行開發(fā)時候需要有一些前置條件
-
開啟 activeX 控件
設(shè)置 --> Internet 選項 --> 安全 --> 自定義級別
把 activeX 相關(guān)設(shè)置勾上
可參考:
-
管理員身份運行調(diào)試
如果開票軟件安裝到本地 C盤 需要使用管理員打開 ie 瀏覽器,然后再進(jìn)行調(diào)試
金稅盤安裝
- 要確保金稅盤安裝準(zhǔn)確安裝了TaxCardX.dll
通用 js代碼
/** 航信金稅盤相關(guān)function */ var goldTax = {/*** 使用前先判斷是否是ie瀏覽器* @return true/false*/isIE: function () {if(!!window.ActiveXObject || "ActiveXObject" in window)return true;elsereturn false;},/*** 開啟金稅盤* @param certPassword 單機版為證書口令 服務(wù)器版為地址 留空則讀取開票BIN文件下cert.txt* @return * <pre>* {* 'success': true/false, // 成功或者失敗* 'code': -1/其他, // 錯誤碼,-1 為系統(tǒng)錯誤* 'msg': 'xxx', // 錯誤信息* 'data': {} // 接口返回相關(guān)數(shù)據(jù)* }* </pre>*/openCard: function (certPassword) {var result = {'success': false,'code': -1,'msg': '','data': {}};try {goldTax.card = new ActiveXObject("TaxCardX.GoldTax");// 單機版為證書口令 服務(wù)器版為地址 留空則讀取開票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 - 狀態(tài)碼, 1011 開啟成功 */RetMsg: goldTax.card.RetMsg, /* RetMsg 狀態(tài)信息 */InvLimit: goldTax.card.InvLimit, /* InvLimit – 開票限額, 金稅卡發(fā)票開具價稅合計限額 */TaxCode: goldTax.card.TaxCode, /* TaxCode 本單位稅號 */TaxClock: goldTax.card.TaxClock, /* TaxClock – 金稅卡時鐘 */MachineNo: goldTax.card.MachineNo, /* MachineNo – 開票機號碼,主開票機為 0 */IsInvEmpty: goldTax.card.IsInvEmpty, /* IsInvEmpty – 有票標(biāo)志,0為金稅卡中無可開發(fā)票,1為有票 */IsRepReached: goldTax.card.IsRepReached, /* IsRepReached – 抄稅標(biāo)志,0為未到抄稅期,1為已到抄稅期 */IsLockReached: goldTax.card.IsLockReached, /* IsLockReached – 鎖死標(biāo)志,0為未到鎖死期,1為已到鎖死期 */};} else {result.success = false;}} catch (e) {result.success = false;result.code = -1;result.msg = 'ActiveX Error, ' + e.description;}return result;},/*** 關(guān)閉金稅盤* @return* <pre>* {* 'success': true/false, // 成功或者失敗* 'code': -1/其他, // 錯誤碼,-1 為系統(tǒng)錯誤* '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 調(diào)用成功,其他失敗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;}},/*** 查詢庫存發(fā)票* @param invKind 發(fā)票種類* @return * <pre>* {* 'success': true/false, // 成功或者失敗* 'code': -1/其他, // 錯誤碼,-1 為系統(tǒng)錯誤* 'msg': 'xxx', // 錯誤信息* 'data': {} // 接口返回相關(guān)數(shù)據(jù)* }* </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 - 狀態(tài)碼, 3011 讀取成功,其他失敗 */RetMsg: goldTax.card.RetMsg, /* RetMsg 狀態(tài)信息 */InfoTypeCode: goldTax.card.InfoTypeCode, /* 要開具發(fā)票的十位代碼。為空或全為0時,表示無可用發(fā)票 */InfoNumber: goldTax.card.InfoNumber, /* 要開具發(fā)票的號碼 */InvStock: goldTax.card.InvStock, /* 剩余的可用發(fā)票份數(shù) */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;},/*** 發(fā)票校驗* @param o 傳入發(fā)票信息* @return * <pre>* {* 'success': true/false, // 成功或者失敗* 'code': -1/其他, // 錯誤碼,-1 為系統(tǒng)錯誤* 'msg': 'xxx', // 錯誤信息* 'data': {} // 接口返回相關(guān)數(shù)據(jù)* }* </pre>*/invoiceVeriferify: function(o) {return goldTax.inner.invoice(1, o);},/*** 發(fā)票開具* @param o 傳入發(fā)票信息* @return * <pre>* {* 'success': true/false, // 成功或者失敗* 'code': -1/其他, // 錯誤碼,-1 為系統(tǒng)錯誤* 'msg': 'xxx', // 錯誤信息* 'data': {} // 接口返回相關(guān)數(shù)據(jù)* }* </pre>*/invoicing: function(o) {return goldTax.inner.invoice(0, o);},/*** 發(fā)票打印* @param o 傳入發(fā)票信息* @return * <pre>* {* 'success': true/false, // 成功或者失敗* 'code': -1/其他, // 錯誤碼,-1 為系統(tǒng)錯誤* 'msg': 'xxx' // 錯誤信息* }* </pre>*/printInv: function(o) {var result = {'success': false,'code': -1,'msg': ''};try {if (typeof goldTax.card != 'undefined') {goldTax.card.InfoKind = o.InfoKind; /* 發(fā)票種類(0:專用發(fā)票 2:普通發(fā)票 11:貨物運輸業(yè)增值稅專用發(fā)票 12:機動車銷售統(tǒng)一發(fā)票) */goldTax.card.InfoTypeCode = o.InfoTypeCode; /* 要打印發(fā)票的十位代碼 */goldTax.card.InfoNumber = o.InfoNumber; /* 要打印發(fā)票的號碼 */goldTax.card.GoodsListFlag = o.GoodsListFlag; /* 銷貨清單標(biāo)志,0 – 打印發(fā)票,1 – 打印銷貨清單 */goldTax.card.InfoShowPrtDlg = o.InfoShowPrtDlg; /* 打印時是否顯示邊距確認(rèn)對話框,0 – 不出現(xiàn),1 – 出現(xiàn) */// 調(diào)用接口goldTax.card.PrintInv();result.code = goldTax.card.RetCode;result.msg = goldTax.card.RetMsg;// RetCode 5011 打印成功,5001 – 未找到發(fā)票或清單,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;},/*** 已開發(fā)票作廢* @param o 傳入發(fā)票信息* @return * <pre>* {* 'success': true/false, // 成功或者失敗* 'code': -1/其他, // 錯誤碼,-1 為系統(tǒng)錯誤* 'msg': 'xxx' // 錯誤信息* }* </pre>*/cancelInv: function(o) {var result = {'success': false,'code': -1,'msg': ''};try {if (typeof goldTax.card != 'undefined') {goldTax.card.InfoKind = o.InfoKind; /* 發(fā)票種類(0:專用發(fā)票 2:普通發(fā)票 11:貨物運輸業(yè)增值稅專用發(fā)票 12:機動車銷售統(tǒng)一發(fā)票) */goldTax.card.InfoTypeCode = o.InfoTypeCode; /* 要作廢發(fā)票的十位或十二位代碼 */goldTax.card.InfoNumber = o.InfoNumber; /* 要作廢發(fā)票的號碼 */// 調(diào)用接口goldTax.card.CancelInv();result.code = goldTax.card.RetCode;result.msg = goldTax.card.RetMsg;// RetCode 6011 打印成功,6001 – 當(dāng)月發(fā)票庫未找到該發(fā)票,6002 – 該發(fā)票已經(jīng)作廢,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;},// 內(nèi)部方法inner: {/*** invoice 接口* @param checkEWM 默認(rèn)為0(0: 發(fā)票開具, 1: 發(fā)票校驗, 2: 空白作廢)* @param o 傳入發(fā)票信息* @return * <pre>* {* 'success': true/false, // 成功或者失敗* 'code': -1/其他, // 錯誤碼,-1 為系統(tǒng)錯誤* 'msg': 'xxx', // 錯誤信息* 'data': {} // 接口返回相關(guān)數(shù)據(jù)* }* </pre>*/invoice: function(checkEWM, o) {var result = {'success': false,'code': -1,'msg': '','data': {}};try {if (typeof goldTax.card != 'undefined') {// CheckEWM值默認(rèn)為0(為1時用于發(fā)票校驗。// 注意:一旦CheckEWM值置1用于發(fā)票校驗之后,//如果要再進(jìn)行發(fā)票開具必須手動將CheckEWM值置為0,否則Invoice()方法的功能將一直處于發(fā)票校驗狀態(tài))goldTax.card.CheckEWM = checkEWM; goldTax.card.InvInfoInit(); /* 初始化發(fā)票抬頭信息 */goldTax.card.InfoKind = o.InfoKind; /* 增值稅普通發(fā)票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; /* 銷方地址電話 */// 如果是多商品多稅率 稅率應(yīng)該放到下面商品信息循環(huán)里if (typeof o.InfoTaxRate != 'undefined' && o.InfoTaxRate) { goldTax.card.InfoTaxRate = o.InfoTaxRate; /* 稅率,(已授權(quán)的稅率, 17% 傳17) */}goldTax.card.InfoNotes = o.InfoNotes; /* 備注 */goldTax.card.InfoInvoicer = o.InfoInvoicer; /* 開票人 */// 復(fù)核人,可為空if (typeof o.InfoChecker != 'undefined' && o.InfoChecker) {goldTax.card.InfoChecker = o.InfoChecker;}// 收款人,可為空if (typeof o.InfoCashier != 'undefined' && o.InfoCashier) {goldTax.card.InfoCashier = o.InfoCashier;}// 如不為空,則開具銷貨清單,此為發(fā)票上商品名稱欄的清單信息,應(yīng)為“(詳見銷貨清單)”字樣if (typeof o.InfoListName != 'undefined' && o.InfoListName) { goldTax.card.InfoListName = o.InfoListName;}// 清空商品明細(xì)列表goldTax.card.ClearInvList(); // 遍歷行$.each(o.InvList, function(i, v) {goldTax.card.InvListInit(); /* 初始化發(fā)票明細(xì)信息各項屬性 */goldTax.card.ListGoodsName = v.ListGoodsName; /* 商品或勞務(wù)名稱 */goldTax.card.ListTaxItem = v.ListTaxItem; /* 稅目,4位數(shù)字,商品所屬類別 */goldTax.card.ListStandard = v.ListStandard; /* 規(guī)格型號 */// 計量單位,如計量單位為空,則忽略數(shù)量和單價if (typeof v.ListUnit != 'undefined' && v.ListUnit) {goldTax.card.ListUnit = v.ListUnit;}// 建議傳入數(shù)量和含稅單價或含稅金額 由接口計算帶小數(shù)的稅額 規(guī)避誤差goldTax.card.ListNumber = v.ListNumber; // 數(shù)量goldTax.card.ListPrice = v.ListPrice; // 單價// 金額,可以不傳(為0),由接口軟件計算,如傳入則應(yīng)符合計算關(guān)系if (typeof v.ListAmount != 'undefined' && v.ListAmount ) {goldTax.card.ListAmount = v.ListAmount;}goldTax.card.ListPriceKind = v.ListPriceKind; /* 含稅價標(biāo)志,單價和金額的種類, 0為不含稅價,1為含稅價 */// 稅額可以不傳(為0),由接口軟件計算,如傳入則應(yīng)符合計算關(guān)系if (typeof v.ListTaxAmount != 'undefined' && v.ListTaxAmount) {goldTax.card.ListTaxAmount = v.ListTaxAmount;}// 添加一行goldTax.card.AddInvList();});// 調(diào)用接口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 - 狀態(tài)碼, 3011 讀取成功,其他失敗 */RetMsg: goldTax.card.RetMsg, /* RetMsg 狀態(tài)信息 */InfoAmount: goldTax.card.InfoAmount , /* 合計不含稅金額 */InfoTaxAmount: goldTax.card.InfoTaxAmount, /* 合計稅額 */InfoInvDate: goldTax.card.InfoInvDate, /* 開票日期 */InfMonth: goldTax.card.InfMonth, /* 所屬月份 */InfoTypeCode: goldTax.card.InfoTypeCode, /* 發(fā)票十位代碼 */InfoNumber: goldTax.card.InfoNumber, /* 發(fā)票號碼 */GoodsListFlag: goldTax.card.GoodsListFlag /* 銷貨清單標(biāo)志,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;}} };相關(guān)資料
CSDN 需要積分下載 金稅 防偽稅控 組件接口 開發(fā)文檔 代碼案例
沒有積分的 戳這里
總結(jié)
以上是生活随笔為你收集整理的航天信息金税盘接口 js 调用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: htcd816+android密码,HT
- 下一篇: JDBC相关知识点