function TForm1.WapPushMsg(sTitle, sUrl: string; dStart, dOver: TDateTime): string;const sBody: string = '02056A0045C6080C03%s000AC307%s10C307%s0103%s000101'; sPush: string = '0605040B8423F081060603AE81EA8D%.*x%s'; function StrOrdHex(S: string): string; begin SetLength(Result, Length(S)*2); BinToHex(PChar(S), PChar(Result), Length(S)); end; var asUrl: string; iii:integer;begin Result := Format(sBody, [StrOrdHex(sUrl), FormatDateTime('yyyymmddhhnnss', dStart), FormatDateTime('yyyymmddhhnnss', dOver), StrOrdHex(AnsiToUtf8(sTitle))]); if Length(Result) >= 256 then raise Exception.Create('消息太长,请缩短标题或地址长度'); iii:=Length(Result) ; asUrl:=inttostr(iii); iii:=Length(Result) div 2 ; asUrl:=inttostr(iii); Result := Format(sPush, [2, Length(Result) div 2 + 128, Result]); Result := Format('FFFF%s', [Result]);end; --------------------------------- using System;using System.Collections.Generic;using System.Text; namespace common{ public class WapPush { private string StrToHex(string str) { string strTemp = ""; if (str == "") return ""; byte[] bTemp = System.Text.Encoding.Default.GetBytes(str); for (int i = 0; i < bTemp.Length; i++) { strTemp += bTemp[i].ToString("X"); } return strTemp; } public byte[] WapPushUrl(string href) { byte[] tmp = new byte[href.Length]; tmp = System.Text.Encoding.UTF8.GetBytes(href); return tmp; } public byte[] WapPushContent(string text) { byte[] tmp = new byte[text.Length]; tmp = System.Text.Encoding.UTF8.GetBytes(text); return tmp; } //转换为16进制 public 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()).ToUpper(); } public string GetWapString(string Url, string Content, DateTime BeginDatetime, DateTime EndDatetime) { System.Text.StringBuilder tmp = new StringBuilder(); tmp.Append("02056A0045C6080C03"); tmp.Append(bytesToHexStr(WapPushUrl(Url))); tmp.Append("000AC307"); tmp.Append(BeginDatetime.ToString("yyyyMMddHHmmss")); tmp.Append("10C307"); tmp.Append(EndDatetime.ToString("yyyyMMddHHmmss")); tmp.Append("0103"); tmp.Append(bytesToHexStr(WapPushContent(Content))); tmp.Append("000101"); System.Text.StringBuilder sPush = new StringBuilder(); sPush.Append("FFFF0605040B8423F081060603AE81EA8D"); int iLength = tmp.ToString().Length / 2 + 128; sPush.Append(Convert.ToString(iLength, 16)); sPush.Append(tmp.ToString()); return sPush.ToString().ToUpper(); } //public string GetWapString(string Url, string Content) //{ // System.Text.StringBuilder tmp = new StringBuilder(); // tmp.Append("0B05040B8423F0000303010129060603AE81EA8DCA02056A0045C6080C03"); // tmp.Append(bytesToHexStr(WapPushUrl(Url))); // tmp.Append("000103"); // tmp.Append(bytesToHexStr(WapPushContent(Content))); // tmp.Append("000101"); // return tmp.ToString().ToUpper(); //} private string StrToHex1(string str) { string strTemp = ""; if (str == "") return ""; byte[] bTemp = System.Text.Encoding.Default.GetBytes(str); for (int i = 0; i < bTemp.Length; i++) { strTemp += bTemp[i].ToString("X"); } return strTemp; } }}
wappush
最新推荐文章于 2022-02-23 15:02:25 发布