ASP版本 文件转十六进制

[浏览313]
ASP版本 文件转十六进制

最近接了一个彩信接口的网站,需要将 文本文件、图片文件 转换成 HexString,通过Form提交,.net、php、javascript的函数网上一抓一大把,asp的却不好找,今天我就来写一个asp版本的hexstring转换函数,为了方便以后用,直接写成类。

class bin2txt
  dim adostream
  private sub class_initialize
    set adostream = server.createobject("ADODB.Stream")
    adostream.type = 1
    adostream.mode = 3
  end sub
   
  public sub open(fn)
    adostream.open
    adostream.LoadFromFile fn
  end sub
   
  public function getHex(t)
    dim tmp,hexstr,binstr
    binstr = adostream.read()
    for i = 1 to lenB(binstr)
      tmp = hex(ascB(midB(binstr,i,1)))
      if len(tmp) = 1 then tmp = "0" & tmp
      hexstr = hexstr & tmp & t
    next
    getHex = hexstr
  end function
   
  public function getOct(t)
    dim tmp,octstr,binstr
    binstr = adostream.read()
    for i = 1 to lenB(binstr)
      tmp = (ascB(midB(binstr,i,1)))
      if len(tmp) = 2 then tmp = "0" & tmp
      if len(tmp) = 1 then tmp = "00" & tmp
      octstr = octstr & tmp & t
    next
    getOct = octstr
  end function
 
end class
使用方法,很简单,代码如下:

set f = new bin2txt
f.open server.mappath("sms/1.jpg")
response.write f.getHex()
彩信添加桢也添加玩函数

'addpage
'pid:帧编号
'showtime:帧展示时间
function addpage(pid,showtime,ttype,tfile,ptype,pfile,mtype,mfile)
  addpage = "&d" & pid & "=" & showtime
  if ttype <> "" and ptype <> "" then
    f.open server.mappath(tfile)
    addpage = addpage & "&tt" & pid & "=" & ttype &_
                        "&tv" & pid & "=" & f.getHex()
  end if
  if ptype <> "" and ptype <> "" then
    f.open server.mappath(ptype)
    addpage = addpage & "&pt" & pid & "=" & ptype &_
            "&pv" & pid & "=" & f.getHex()
  end if
  if mtype <> "" and mtype <> "" then
    f.open server.mappath(mtype)
    addpage = addpage & "&mt" & pid & "=" & mtype &_
            "&mv" & pid & "=" & f.getHex()
  end if
end function
 
set f = new bin2txt
f.open server.mappath("sms/title.txt")
sendstr = "id=***&pwd=***&subject=" & f.getHex()
sendstr = sendstr & addpage(1,5,"txt","sms/1.txt","jpg","sms/1.jpg","","")
sendstr = sendstr & addpage(2,5,"txt","sms/2.txt","jpg","sms/2.jpg","","")
response.write openApi("http://118.144.76.79:8080/mmsServer/sendMms",sendstr)

关闭 ]
友情链接

Copyright © 2014 ASP技巧教程源码大全 All Rights Reserved
晋ICP备14006235号-3 页面执行时间:92.773毫秒 返回顶部