zoukankan      html  css  js  c++  java
  • 税控接口

    当时从其他税控接口里面提取的JSON脚本,根据脚本实现了一份Delphi的源代码。

    JSON脚本:

    [{
      "ClassName": "",
      "Title": "开具增值税专用发票",
      "X": 150,
      "Y": 3,
      "ConfirmTitle": "",
      "ConfirmClass": "",
      "SI_Mode": 0,
      "ParentPath": "",
      "InvType": 0,//表示增票
      "ClickPosition": {
        "ImportPoint": "-680, 25",    
        //导入按钮的位置
        "MImportPoint": "-680, 75",
        //手动导入按钮的位置
        "BImportPoint": "-680, 95",    
        //自动导入按钮的位置
        "ListPoint":"-440,25",    
        //清单按钮的位置
        "InvZKPoint":"-380,25",    
        //发票界面的折扣按钮的位置
        "PricePoint":"-315,25",
        "AddPoint":"-255,25",
        "DeletePoint":"-195,25",
        "PrintPoint": "-125, 25",    
        //打印按钮的位置
        "SelectPoint": "590, 29",    
        //选择单据按钮的位置
        "ListZKPoint":"450,25"
      },
      "CtrlPosition": {
        "InvFirstPoint": { //发票界面的首行位置
          "PosIndex": 0,
          "Reference": "2",
          "Position":"120,325",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "InvNo": { //发票号码
          "PosIndex": 16,
          "Reference": "2",
          "Position":"730,53",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "InvCode": { //发票代码
          "PosIndex": 17,
          "Reference": "2",
          "Position":"200,53",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "PrintDate": { //打印日期
          "PosIndex": 15,
          "Reference": "2",
          "Position":"770,100",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "GFName": { //购方名称
          "PosIndex": 38,
          "Reference": "2",
          "Position":"230,135",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "GFTaxNo": { //购方税号
          "PosIndex": 33,
          "Reference": "2",
          "Position":"230,157",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "GFAddrTel": { //购方地址电话
          "PosIndex": 35,
          "Reference": "2",
          "Position":"230,180",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "GFBankAccount": { //购方银行账号
          "PosIndex": 31,
          "Reference": "2",
          "Position":"230,203",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "XFBankAccount": { //销方银行账号
          "PosIndex": 22,
          "Reference": "2",
          "Position":"235,553",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "Memo": { //备注
          "PosIndex": 10,
          "Reference": "2",
          "Position":"590,480",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "FHR": { //复核人
          "PosIndex": 9,
          "Reference": "2",
          "Position":"380,590",
          "ParentTitle": "",
          "ParentClass": ""
        },
        "SKR": { //收款人
          "PosIndex": 7,
          "Reference": "2",
          "Position":"170,590",
          "ParentTitle": "",
          "ParentClass": ""
        }
      } 
    }]

    delphi代码:

    function SetWindowCtrlText(aHandle: THandle; aValue: string): Boolean;
    begin
      SendMessage(aHandle, WM_SETTEXT, 0, integer(aValue));
    end;
    
    procedure TFrmMain.btnInputClick(Sender: TObject);
    var
      i: integer;
      HR: THandle;
      ClassName, Title: string;
      sl: TSendInputHelper;
      InvFirstPoint: TPoint;
      current, BillDetail: TBillDetail;
      BillDetailList: TList<TBillDetail>;
      num2, millisecondsTimeout: integer;
    begin
      BillDetailList := TList<TBillDetail>.Create;
      for i := 1 to 6 do
      begin
        BillDetail := TBillDetail.Create;
        BillDetail.SPMC := '商品名称';
        BillDetail.SPGGXH := '规格';
        BillDetail.JLDW := '单位';
        BillDetail.sl := 1;
        BillDetail.DJ := 1000;
        BillDetail.JE := 1000;
        BillDetailList.Add(BillDetail);
      end;
    
      for i := 0 to JSON.Count - 1 do
      begin
        ClassName := JSON.Items[i].ItemByName('ClassName').AsString;
        Title := JSON.Items[i].ItemByName('Title').AsString;
        if (ClassName <> '') and (Title <> '') then
        begin
          HR := FindWindow(PWideChar(ClassName), PWideChar(Title));
        end
        else
        begin
          if ClassName <> '' then
          begin
            HR := FindWindow(PWideChar(ClassName), nil);
          end
          else
          begin
            HR := FindWindow(nil, PWideChar(Title));
          end;
        end;
        if HR <> 0 then
        begin
          Break;
        end;
      end;
      if HR <> 0 then
      begin
        SetForegroundWindow(HR);
        SetText(JSON.Items[i], HR, 'GFName', '购方名称');
        SetText(JSON.Items[i], HR, 'GFTaxNo', '1234567890123456');
        SetText(JSON.Items[i], HR, 'GFAddrTel', '地址电话');
        SetText(JSON.Items[i], HR, 'GFBankAccount', '银行账号');
        SetText(JSON.Items[i], HR, 'Memo', '备注');
        SetText(JSON.Items[i], HR, 'FHR', '复核人');
        SetText(JSON.Items[i], HR, 'SKR', '收款人');
    
        sl := TSendInputHelper.Create;
        try
          InvFirstPoint := GetPoint(JSON.Items[i], 'InvFirstPoint');
          MoveAndClick(HR, InvFirstPoint);
    
          num2 := 0;
          millisecondsTimeout := 1000;
    
          for current in BillDetailList do
          begin
            Application.ProcessMessages;
            if (num2 <= BillDetailList.Count - 1) and (num2 > 0) then
            begin
              sl.AddDelay(millisecondsTimeout);
              sl.AddVirtualKey(VK_RETURN);
              sl.AddDelay(millisecondsTimeout);
              sl.AddVirtualKey(VK_HOME);
              sl.Flush;
            end;
    
            sl.AddText(current.SPMC);
            sl.AddVirtualKey(VK_TAB);
            sl.AddDelay(millisecondsTimeout);
            Delay(millisecondsTimeout);
            sl.AddText(current.SPGGXH);
            sl.AddVirtualKey(VK_TAB);
            sl.AddDelay(millisecondsTimeout);
    
            sl.AddText(current.JLDW);
            sl.AddVirtualKey(VK_TAB);
            sl.AddDelay(millisecondsTimeout);
    
            sl.AddText(CurrToStr(current.sl));
            sl.AddVirtualKey(VK_TAB);
            sl.AddDelay(millisecondsTimeout);
    
            sl.AddText(CurrToStr(current.DJ));
            sl.AddVirtualKey(VK_TAB);
            sl.AddDelay(millisecondsTimeout);
    
            sl.AddText(CurrToStr(current.JE));
            sl.AddVirtualKey(VK_RETURN);
            sl.AddDelay(millisecondsTimeout);
            sl.AddVirtualKey(VK_RETURN);
            sl.AddDelay(millisecondsTimeout);
            sl.AddVirtualKey(VK_RETURN);
            sl.Flush;
            inc(num2);
          end;
        finally
          FreeAndNil(sl);
        end;
      end;
    end;
    
    procedure TFrmMain.FormCreate(Sender: TObject);
    begin
      JSON := TQJson.Create;
      JSON.Parse(JsonFile.Text);
    end;
    
    procedure TFrmMain.FormDestroy(Sender: TObject);
    begin
      FreeAndNil(JSON);
    end;
    
    function TFrmMain.GetPoint(aJSON: TQJson; aName: string): TPoint;
    var
      sPoint: string;
    begin
      sPoint := aJSON.ItemByPath('CtrlPosition.' + aName + '.Position').AsString;
      Result.X := StrToInt(Copy(sPoint, 1, Pos(',', sPoint) - 1));
      Result.Y := StrToInt(Copy(sPoint, Pos(',', sPoint) + 1, 10));
    end;
    
    procedure TFrmMain.MoveAndClick(aHandle: THandle; p: TPoint);
    var
      rect: TRect;
      point: TPoint;
    begin
      GetWindowRect(aHandle, rect);
      point.X := rect.Left;
      point.Y := rect.Top;
      ClientToScreen(point);
      SetCursorPos(point.X + p.X, point.Y + p.Y);
      mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
      mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    end;
    
    function TFrmMain.SetText(aJSON: TQJson; aHandle: THandle; aName, aValue: string): Boolean;
    var
      p1, p, point: TPoint;
      sPoint: string;
      sl: TSendInputHelper;
      rect: TRect;
    begin
      GetWindowRect(aHandle, rect);
      GetCursorPos(p1);
      sl := TSendInputHelper.Create;
      try
        sPoint := aJSON.ItemByPath('CtrlPosition.' + aName + '.Position').AsString;
        p.X := StrToInt(Copy(sPoint, 1, Pos(',', sPoint) - 1));
        p.Y := StrToInt(Copy(sPoint, Pos(',', sPoint) + 1, 10));
        point.X := rect.Left;
        point.Y := rect.Top;
        ClientToScreen(point);
        SetCursorPos(point.X + p.X, point.Y + p.Y + 75);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
        sl.AddText(aValue);
        sl.Flush;
      finally
        SetCursorPos(p1.X, p1.Y);
        FreeAndNil(sl);
      end;
    end;
  • 相关阅读:
    centos7 & ubuntu14.02安装sublime 3
    flask之flask-restful
    ubuntu14.04安装python3.7.1
    vim中多行注释和多行删除命令
    python3之scrapy安装使用
    python3 之 linux命令实现
    ubuntu14.04安装pyspider
    升级3.4成3.6 ubuntu14.04 和miniconda虚拟环境
    python3 之初学者常犯的5个错误
    python3 之 格式化json
  • 原文地址:https://www.cnblogs.com/masg/p/9925350.html
Copyright © 2011-2022 走看看