前一段,给移动做一个wappush的东西,在网上找资料,发现几乎没有,有的也是说的很含糊,最后,尝试了很久,终于解决了,奉献给大家.
(1):使用http://www.codeproject.com/csharp/wappush.asp这里说的方法生成一个16进制的字符串,这个串就是短信内容content.
(2):由于CMPP使用socket发送,因此content需要进行二进制编码,那么如果你采用c#语言,请使用下面的方法,其他语言类同。
public static byte[] hex2Ascii(string s)
{
int len = s.Length;
byte[] temp = new byte[len/2];
int j = 0;
for(int i=0;i<len;i++)
{
string s2 = s.Substring(i,2);
string s21 = s2.Substring(0,1);
string s22 = s2.Substring(1,1);
temp[j]=(byte)(str2byte(s21) * 16 + str2byte(s22));
i++;
j++;
}
return temp;
}
public static int str2byte(string ch)
{
string aa = ch.ToLower();
if(aa.Equals("a")) return 10;
if(aa.Equals("b")) return 11;
if(aa.Equals("c")) return 12;
if(aa.Equals("d")) return 13;
if(aa.Equals("e")) return 14;
if(aa.Equals("f")) return 15;
return Convert.ToInt32(aa);
}
(3):在CMPP协议中,在发送WAPPUSH时候,需要将TP_pID设置为0,将TP_udhi设置为64。
(4):test it!