public void Send(string mobileNo, string url) { var shortUrl = ShortUrl.Create(url).Result.ShortUrl; var modalText = "{orderNo}{mobileNo}|{codeNo}|尊敬的{customerName},欢迎您入住{hotelShortName}{roomNo}房间,点击 {shortUrl} 查看酒店介绍和相关活动【{signName}】"; var data = $"1021{mobileNo}|102001|尊敬的马虎维,欢迎您入住国贸大饭店8309房间,点击 {shortUrl} 查看酒店介绍和相关活动【国贸大饭店】"; var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var address = IPAddress.Parse("218.26.36.12"); socket.Connect(address, 9905); var bytes = Encoding.GetEncoding("GBK").GetBytes(data); var count = bytes.Length.ToString().PadLeft(4, '0'); bytes = Encoding.GetEncoding("GBK").GetBytes(count + data); socket.Send(bytes); var receiveBuffers = new byte[1024]; var length = socket.Receive(receiveBuffers); if (length <= 0) { Console.WriteLine("读取返回失败。"); } else { var rd = Encoding.GetEncoding("GBK").GetString(receiveBuffers, 0, length); Console.WriteLine($"返回结果:{rd}"); } socket.Close(); socket.Dispose(); }
private static void Main(string[] args) { var longUrl = "http://192.168.1.160:44373/Welcome/4d954670-66b9-44a1-9c62-d4339b12f839/Preview/index.html"; longUrl = "https://hotelsclient.wanbex.com/img/logo.png"; var result = ShortUrl.Create(longUrl).Result; Console.WriteLine($"执行{(result.Code == 0 ? "成功." : $"失败:{result.Code} {result.ErrMsg}")}"); if (result.Code == 0) { Console.WriteLine($" ShortUrl:{result.ShortUrl}"); } Console.WriteLine("\n"); //var queryResult = ShortUrl.Query(result.ShortUrl).Result; //Console.WriteLine($"执行{(queryResult.Code == 0 ? "成功." : $"失败:{queryResult.Code} {queryResult.ErrMsg}")}"); //if (queryResult.Code == 0) Console.WriteLine($" LongUrl:{queryResult.LongUrl}"); //Console.WriteLine("\n"); //Console.WriteLine($"与源地址比较:{queryResult.LongUrl == longUrl}"); Console.ReadLine(); return; var ms = new SmsService("1021", "102001"); do { var input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { continue; } if (input.ToLower() == "exit") { break; } var orders = input.ToLower().Split(' '); if (orders[0] != "send" || orders.Length == 1 || string.IsNullOrEmpty(orders[1])) { continue; } ms.Send(orders[1], longUrl); } while (true); Console.ReadLine(); }
public static async Task <string> Create(string longUrl) { var lr = HttpUtility.UrlEncode(longUrl); var client = ShortUrl.CreateHttpClient(null); var response = await client.PostAsync(string.Format(QueryUrl, lr), null); if (response.IsSuccessStatusCode) { var data = response.Content.ReadAsStringAsync(); var ret = JsonConvert.DeserializeObject <H5ipResult>(data.Result); if (ret.code == 0) { return(ret.short_url); } throw new Exception(ret.msg); } throw new Exception("error"); }