SMS发送WapPush

首先要将这两个字段设置为"1"
tp_Pid = 1;
tp_Udhi = 1;短信内容编码要设置为:4也就是二进制MessageFmt=4;
然后对要发送的WapPush进行编码
 static private byte[] WapPushUrl(string href)
        
{
            href 
= href.ToLower().Replace("http://""");
            
byte[] tmp = new byte[href.Length];
            tmp 
= System.Text.Encoding.UTF8.GetBytes(href);
            
return tmp;
        }

        
static private byte[] WapPushContent(string text)
        
{
            
byte[] tmp = new byte[text.Length];
            tmp 
= System.Text.Encoding.UTF8.GetBytes(text);
            
return tmp;
        }

        
//转换为16进制
        private string bytesToHexStr(byte[] abyte0)
        
{
            
if(abyte0 == null)
                
return "";
            System.Text.StringBuilder stringbuffer 
= new System.Text.StringBuilder(abyte0.Length * 3);
            
for(int i = 0; i < abyte0.Length; i++)
            
{
                stringbuffer.Append(System.Convert.ToString(abyte0[i] 
& 0xff,16));
            }

            
return stringbuffer.ToString();
        }


        
public string GetWapString()
        
{
            System.Text.StringBuilder tmp 
= new StringBuilder();
            tmp.Append(
"0B05040B8423F0000303010129060603AE81EA8DCA02056A0045C6080C03");
            tmp.Append(bytesToHexStr(WapPushUrl(Href)));
            tmp.Append(
"000103");
            tmp.Append(bytesToHexStr(WapPushContent(Text)));
            tmp.Append(
"000101");

            
return tmp.ToString().ToUpper();
        }
posted @ 2007-04-15 20:54  码农没有码  阅读(838)  评论(0)    收藏  举报