package sjsw.bean;
class SMSPush
{
public SMSPush()
{
}
public static String getSMSPush(String url,String subject)
{
//0B05040B8423F00003030101
//29060603AE81EA8DA002056A0045C6080C03
//URL:::7777772E67646363742E676F762E636E2F736A7377776170
//000103
//CONTENT:::E7B2BEE5BDA9E697A0E999902CE5B0BDE59CA8E782ABE692AD
//000101
String sUdh1="0B05040B8423F00003B30201";
String sUdh2="0B05040B8423F00003B30202";
String sPdu = "29060603AE81EA8DCA02056A0045C6080C03";
String sUrl = "";
try
{
sUrl = byteArrayToHexString(url.getBytes());
System.out.println("url:::::::::"+sUrl);
}
catch (Exception ex)
{
}
String urlend = "000103";
String sMsg = "";
try
{
sMsg= byteArrayToHexString(subject.getBytes("UTF-8")); //显示给用户的内容,用utf-8编码。utf-8编码,英文字符直接用ascii码;中文如果unicode是(二进制)
System.out.println("msg::::::::::"+sMsg);
}
catch (Exception ex)
{
}
String sEnd = "000101";
System.out.println("**********************************1");
String pushString1="";
String pushString2="";
String pushString="";
if((sUrl+urlend+sMsg).length()<216)
{
pushString= sUdh1 + sPdu + sUrl + urlend + sMsg + sEnd;
}
else
{
String all = sUrl + urlend + sMsg + sEnd;
String part1=all.substring(0,216);
String part2=all.substring(216,all.length());
pushString1= sUdh1 + sPdu + part1 +";";
pushString2= sUdh2 + part2 +";";
pushString = pushString1 + pushString2;
}
System.out.println("pushString:::::::"+pushString);
return pushString;
}
public static String getSMSPhone(String phone)
{
String phone_temp=byteArrayToHexString(phone.getBytes());
return phone_temp;
}
public static String byteArrayToHexString(byte b[])
{
String result = "";
for (int i = 0; i < b.length; i++)
{
result = result + byteToHexString(b[i]);
}
return result;
}
public static String byteToHexString(byte b)
{
int n = b;
if (n < 0)
{
n = 256 + n;
}
int d1 = n / 16;
int d2 = n % 16;
return HexCode[d1] + HexCode[d2];
}
private static String HexCode[] ={"0", "1", "2", "3", "4", "5", "6", "7", "8", "9","A", "B", "C", "D", "E", "F"};
}
本篇文章可以判断url和宣传语是否超长,如果超长则分成两个包下发,已经用诺基亚3100成功测试。
参考文章:http://blog.csdn.net/cutemouse/archive/2006/12/29/1466969.aspx