中文转换成unicode码函数
因为手机短消息的发送是以pdu串的形式发送出去的,中文字符以unicode码来表示,所以在发送中文短消息之前必须首先将中文字符转换为unicode码,下面的函数将实现这个功能。这个函数主要应用到vb自带的一个格式转换函数:chrw()将中文转换为unicode码。
| public function chg(rmsg as string) as string dim tep as string dim temp as string dim i as integer dim b as integer tep = rmsg i = len(tep) b = i / 4 if i = b * 4 then b = b - 1 tep = left(tep, b * 4) else tep = left(tep, b * 4) end if chg = "" for i = 1 to b temp = "&h" & mid(tep, (i - 1) * 4 + 1, 4) chg = chg & chrw(cint(val(temp))) next i end function |
| public function telc(num as string) as string dim tl as integer dim ltem, rtem, ttem as string dim ti as integer ttem = "" tl = len(num) if tl <> 11 and tl <> 13 then msgbox "wrong number." & tl exit function end if if tl = 11 then tl = tl + 2 num = "86" & num end if for ti = 1 to tl step 2 ltem = mid(num, ti, 1) rtem = mid(num, ti + 1, 1) if ti = tl then rtem = "f" ttem = ttem & rtem & ltem next ti telc = ttem end function |
| const prex = "0891" const midx = "11000d91" const sufx = "000800" public function sendsms(csca as string, num as string, msg as string) as _boolean dim pdu, psmsc, pnum, pmsg as string dim leng as string dim length as integer length = len(msg) length = 2 * length leng = hex(length) if length < 16 then leng = "0" & leng psmsc = trim(telc(csca)) pnum = trim(telc(num)) pmsg = trim(ascg(msg)) pdu = prex & psmsc & midx & pnum & sufx & leng & pmsg sleep(1) mobcomm.output = "at+cmgf=0" + vbcr mobcomm.output = "at+cmgs=" & str(15 + length) + vbcr mobcomm.output = pdu & chr$(26) sleep(1) sendsms = true end function |
| public function ascg(smsg as string) as string dim si, sb as integer dim stmp as integer dim stemp as string sb = len(smsg) ascg = "" for si = 1 to sb stmp = ascw(mid(smsg, si, 1)) if abs(stmp) < 127 then stemp = "00" & hex(stmp) else stemp = hex(stmp) end if ascg = ascg & stemp next si ascg = trim(ascg) end function |
| public sub readsms(rnum as string) mobcomm.output = "at+cmgf=1" + vbcr mobcomm.output = "at+cmgr=" & rnum + vbcr end sub |
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器