|
楼主 |
发表于 2011-1-28 20:45
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
东莞的查询代码如下
- Option Explicit
- Sub chaxun()
- Dim xmlhttp As Object
- Dim intnum As Integer
- Dim i As Integer
- Dim strdm As String
- Dim strhm As String
- Dim strdjh As String
- Dim strmc As String
- Dim strje As String
- Dim strrq As String
- Dim stra As String
- Dim getpage As String
- Dim strjg As String
- intnum = Application.WorksheetFunction.CountA([A:A])
- For i = 1 To intnum - 1
- Cells(2, 7).Value = "正在查询第" & i & "张"
- strdm = Cells(i + 1, 1).Value
- strhm = Cells(i + 1, 2).Value
- strdjh = Cells(i + 1, 3).Value
- strmc = Cells(i + 1, 4).Value
- strje = Cells(i + 1, 5).Value
- strrq = Format(Cells(i + 1, 6).Value, "yyyy-mm-dd")
- Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
- xmlhttp.Open "post", "http://app.gd-n-tax.gov.cn/wssw/servlet/invoice_checking", False
- xmlhttp.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded"
- stra = URLEncode(strmc)
- xmlhttp.Send "fpdm=" & strdm & "&fphm=" & strhm & "&xhfswdjh=" & strdjh & "&xhfmc=" & stra & "&kpje=" & strje & "&kprq=" & strrq & "&INVOICE_CHECKING_CHECKCODE=2829&check_code=2829"
- Do Until xmlhttp.ReadyState = 4
- DoEvents
- Loop
- If xmlhttp.Status = 200 Then
- getpage = xmlhttp.responseText
- strjg = Mid(getpage, InStr(getpage, "查询结果") + 177, InStr(getpage, "如需进一步查验发票真伪") - InStr(getpage, "查询结果") - 266)
- Cells(i + 1, 8).Value = strjg
- Else
- reportErr (xmlhttp.Status)
- End If
- Next i
- Cells(2, 7).Value = "查询完毕!"
- MsgBox "OK"
- Cells(2, 7).Value = "查询状态提示栏"
- End Sub
- Sub reportErr(lStatus As Integer)
- Select Case lStatus
- Case 400
- MsgBox "Bad Request", vbCritical, "连接错误"
- Case 401
- MsgBox "Unauthorized", vbCritical, "连接错误"
- Case 402
- MsgBox "Payment Required", vbCritical, "连接错误"
- Case 403
- MsgBox "Forbidden", vbCritical, "连接错误"
- Case 404
- MsgBox "Not Found", vbCritical, "连接错误"
- Case 407
- MsgBox "Proxy Authentication Required", vbCritical, "连接错误"
- Case 408
- MsgBox "Request Timeout", vbCritical, "连接错误"
- Case 503
- MsgBox "Service Unavailable", vbCritical, "连接错误"
- Case Else
- MsgBox "Can not reach by other reason", vbCritical, "连接错误"
- End Select
- End Sub
- Public Function URLEncode(strInput As String) As String
- '-------------------------------------------------------
- '示例: Debug.Print URLEncode("PowerBASIC中国")
- '-------------------------------------------------------
- Dim strOutput As String
- Dim intAscii As Integer
- Dim i As Integer
- Dim strTemp As String
- For i = 1 To Len(strInput)
- intAscii = Asc(Mid(strInput, i, 1))
- If ((intAscii < 58) And (intAscii > 47)) Or _
- ((intAscii < 91) And (intAscii > 64)) Or _
- ((intAscii < 123) And (intAscii > 96)) _
- Then
- strOutput = strOutput & Chr$(intAscii)
- Else
- strTemp = Trim$(Hex$(intAscii))
- strOutput = strOutput & "%" & Left(strTemp, 2) & "%" & Right(strTemp, 2)
- End If
- Next
- URLEncode = strOutput
- End Function
复制代码 |
|