全局代码,编写代码
Class TestCallWaybillPrinter
public Shared Sub WayBillPrinterTools()
Dim url7 As String = "http://localhost:4040/sf/waybill/print?type=V2.0.FM_poster_100mm150mm&output=noAlertPrint"
Dim url8 As String = "http://localhost:4040/sf/waybill/print?type=V2.0.FM_poster_100mm150mm&output=print"
Dim url9 As String = "http://localhost:4040/sf/waybill/print?type=V2.0.FM_poster_100mm150mm&output=image"
Dim url10 As String = "http://localhost:4040/sf/waybill/print?type=V3.0.FM_poster_100mm210mm&output=noAlertPrint"
Dim url11 As String = "http://localhost:4040/sf/waybill/print?type=V3.0.FM_poster_100mm210mm&output=print"
Dim url12 As String = "http://localhost:4040/sf/waybill/print?type=V3.0.FM_poster_100mm210mm&output=image"
Dim reqURL As String = url12
Dim jsonParam As String = AssemblyParameters(True)
Console.WriteLine("param :" & jsonParam)
Console.ReadKey(True)
Dim notTopLogo As Boolean = True
If reqURL.Contains("V2.0") AndAlso notTopLogo Then
reqURL = reqURL.Replace("V2.0", "V2.1")
End If
If reqURL.Contains("V3.0") AndAlso notTopLogo Then
reqURL = reqURL.Replace("V3.0", "V3.1")
End If
Dim result As String = postJson(reqURL, jsonParam)
Console.WriteLine("最终msg:" & result)
Console.ReadKey(True)
If result.Contains(""",""") Then
Dim arr As String() = result.Split(""",""")
For i As Integer = 0 To arr.Length - 1
generateImage(arr(i).ToString(), "D:\qiaoWaybill201811102-" & i & ".jpg")
Next
Else
generateImage(result, "D:\qiaoWaybill201811102-1.jpg")
End If
Console.WriteLine("结束")
Console.ReadKey(True)
End Sub
Private Shared Function AssemblyParameters(ByVal isFengMi As Boolean) As String
Dim waybillDtoList As IList(Of WaybillDto) = New List(Of WaybillDto)()
Dim dto As WaybillDto = New WaybillDto()
dto.appId = "SLKJ2019"
dto.appKey = "FBIqMkZjzxbsZgo7jTpeq7PD8CVzLT4Q"
dto.mailNo = "755123457777"
dto.consignerProvince = "广东省"
dto.consignerCity = "深圳市"
dto.consignerCounty = "南山区"
dto.consignerAddress = "学府路软件产业基地2B12楼5200708号"
dto.consignerCompany = "神一样的科技"
dto.consignerMobile = "15893799999"
dto.consignerName = "风一样的旭哥"
dto.consignerShipperCode = "518052"
dto.consignerTel = "0755-33123456"
dto.deliverProvince = "浙江省"
dto.deliverCity = "杭州市"
dto.deliverCounty = "拱墅区"
dto.deliverCompany = "神罗科技集团有限公司"
dto.deliverAddress = "舟山东路708号古墩路北(玉泉花园旁)百花苑西区7-2-201室"
dto.deliverName = "艾丽斯"
dto.deliverMobile = "15881234567"
dto.deliverShipperCode = "310000"
dto.deliverTel = "0571-26508888"
dto.destCode = "755"
dto.zipCode = "571"
dto.expressType = 1
dto.codValue = "999.9"
dto.insureValue = "501"
dto.monthAccount = "7550385912"
dto.orderNo = ""
dto.payMethod = 1
dto.childRemark = "子单号备注"
dto.mainRemark = "这是主运单的备注"
dto.returnTrackingRemark = "迁回单备注"
dto.encryptCustName = True
dto.encryptMobile = True
Dim rlsInfoDtoList As System.Collections.ArrayList = New System.Collections.ArrayList
Dim rlsMain As RlsInfoDto = New RlsInfoDto()
rlsMain.abFlag = "A"
rlsMain.codingMapping = "F33"
rlsMain.codingMappingOut = "1A"
rlsMain.destRouteLabel = "755WE-571A3"
rlsMain.destTeamCode = "012345678"
rlsMain.printIcon = "11110000"
rlsMain.proCode = "T4"
rlsMain.qrcode = "MMM={'k1':'755WE','k2':'021WT','k3':'','k4':'T4','k5':'755123456789','k6':''}"
rlsMain.sourceTransferCode = "021WTF"
rlsMain.waybillNo = "755123456789"
rlsMain.xbFlag = "XB"
rlsInfoDtoList.Add(rlsMain)
If dto.returnTrackingNo IsNot Nothing Then
Dim rlsBack As RlsInfoDto = New RlsInfoDto()
rlsBack.waybillNo = dto.returnTrackingNo
rlsBack.destRouteLabel = "021WTF"
rlsBack.printIcon = "11110000"
rlsBack.proCode = "T4"
rlsBack.abFlag = "A"
rlsBack.xbFlag = "XB"
rlsBack.codingMapping = "1A"
rlsBack.codingMappingOut = "F33"
rlsBack.destTeamCode = "87654321"
rlsBack.sourceTransferCode = "755WE-571A3"
rlsBack.qrcode = "MMM={'k1':'21WT','k2':'755WE','k3':'','k4':'T4','k5':'443123456789','k6':''}"
rlsInfoDtoList.Add(rlsBack)
End If
Dim cargo As CargoInfoDto = New CargoInfoDto()
cargo.cargo = "苹果7S"
cargo.cargoCount = 2
cargo.cargoUnit = "件"
cargo.sku = "00015645"
cargo.remark = "手机贵重物品 小心轻放"
Dim cargo2 As CargoInfoDto = New CargoInfoDto()
cargo2.cargo = "苹果macbook pro"
cargo2.cargoCount = 10
cargo2.cargoUnit = "件"
cargo2.sku = "00015646"
cargo2.remark = "笔记本贵重物品 小心轻放"
Dim cargoInfoList As System.Collections.ArrayList = New System.Collections.ArrayList
cargoInfoList.Add(cargo2)
cargoInfoList.Add(cargo)
dto.cargoInfoDtoList = cargoInfoList
dto.rlsInfoDtoList = rlsInfoDtoList
If isFengMi Then
dto.rlsInfoDtoList = rlsInfoDtoList
End If
waybillDtoList.Add(dto)
Return Newtonsoft.Json.JsonConvert.SerializeObject(waybillDtoList)
End Function
Private Shared Function postJson(ByVal reqURL As String, ByVal jsonParm As String) As String
Dim httpResult As String = ""
Try
Dim req As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(reqURL), System.Net.HttpWebRequest)
req.ContentType = "application/json;charset=utf-8"
req.Method = "POST"
req.Timeout = 20000
Dim bs As Byte() = System.Text.Encoding.UTF8.GetBytes(jsonParm)
Using reqStream As io.Stream = req.GetRequestStream()
reqStream.Write(bs, 0, bs.Length)
End Using
Using response As System.Net.HttpWebResponse = CType(req.GetResponse(), System.Net.HttpWebResponse)
Using sr As io.StreamReader = New io.StreamReader(response.GetResponseStream(), Encoding.[Default])
httpResult = sr.ReadToEnd().ToString()
End Using
End Using
If httpResult.Contains("[") Then
httpResult = httpResult.Substring(httpResult.IndexOf("[") + 1, httpResult.IndexOf("]") - httpResult.IndexOf("[") - 1)
End If
If httpResult.StartsWith("""") Then
httpResult = httpResult.Substring(1, httpResult.Length - 1)
End If
If httpResult.EndsWith("""") Then
httpResult = httpResult.Substring(0, httpResult.Length - 1)
End If
httpResult = httpResult.Replace("\n", "")
Catch ex As Exception
Return ex.Message
End Try
Return httpResult
End Function
Public Shared Function generateImage(ByVal imgStr As String, ByVal imgFilePath As String) As Boolean
If imgStr Is Nothing Then Return False
Try
Dim bytes As Byte() = Convert.FromBase64String(imgStr)
Dim x As Integer = 256
Dim a As Byte = CByte(x)
For i As Integer = 0 To bytes.Length - 1
If bytes(i) < 0 Then
bytes(i) += a
End If
Next
Using fs As io.FileStream = New io.FileStream(imgFilePath, io.FileMode.OpenOrCreate, io.FileAccess.Write)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
End Using
Catch e As Exception
Return False
End Try
Return True
End Function
End Class
Class CargoInfoDto
Public cargo As String
Public parcelQuantity As Integer
Public cargoCount As Integer
Public cargoUnit As String
Public cargoWeight As Double
Public cargoAmount As Double
Public cargoTotalWeight As Double
Public remark As String
Public sku As String
End Class
Class RlsInfoDto
Public abFlag As String
Public codingMapping As String
Public codingMappingOut As String
Public destRouteLabel As String
Public destTeamCode As String
Public printIcon As String
Public proCode As String
Public qrcode As String
Public sourceTransferCode As String
Public waybillNo As String
Public xbFlag As String
End Class
Class WaybillDto
Public mailNo As String
Public expressType As Integer
Public payMethod As Integer
Public returnTrackingNo As String
Public monthAccount As String
Public orderNo As String
Public zipCode As String
Public destCode As String
Public payArea As String
Public deliverCompany As String
Public deliverName As String
Public deliverMobile As String
Public deliverTel As String
Public deliverProvince As String
Public deliverCity As String
Public deliverCounty As String
Public deliverAddress As String
Public deliverShipperCode As String
Public consignerCompany As String
Public consignerName As String
Public consignerMobile As String
Public consignerTel As String
Public consignerProvince As String
Public consignerCity As String
Public consignerCounty As String
Public consignerAddress As String
Public consignerShipperCode As String
Public logo As String
Public sftelLogo As String
Public topLogo As String
Public topsftelLogo As String
Public appId As String
Public appKey As String
Public electric As String
Public cargoInfoDtoList As System.Collections.ArrayList
Public rlsInfoDtoList As System.Collections.ArrayList
Public insureValue As String
Public codValue As String
Public codMonthAccount As String
Public mainRemark As String
Public returnTrackingRemark As String
Public childRemark As String
Public custLogo As String
Public insureFee As String
Public encryptCustName As Boolean
Public encryptMobile As Boolean
End Class
调用代码
TestCallWaybillPrinter.WayBillPrinterTools
[此贴子已经被作者于2019/5/27 16:41:16编辑过]