旅游行业怎么利用C#接口发送短信

打印 上一主题 下一主题

主题 1036|帖子 1036|积分 3108

旅游企业一般拥有浩繁的分支机构,同时各地分支机构又有浩繁部属分散在当地各区的旅游营业报名点,以前传统的办理方案是采用专线、MODEM拔号等方式,专线的成本很高,MODEM拔号更费时,且远程拔号互联成本在多点情况下费用也不低。相反的是,群发短信业务不但费用低,且效率好。

 支持免费试用乐讯通PaaS平台 找好用的短信平台,选择乐讯通,短信群发|短信平台|群发短信软件|群发短信平台|乐讯通PaaS平台
http://yun.loktong.com/login/register/0c61bafb77
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace WinApiDemo
  8. {
  9.     class Program
  10.     {
  11.         private const string url = "http://www.lokapi.cn/smsUTF8.aspx";
  12.         private const string urlReply = "http://www.lokapi.cn/callApi.aspx";
  13.         private const string urlStatus = "http://www.lokapi.cn/statusApi.aspx";
  14.         private const string urlBalance = "http://www.lokapi.cn/smsUTF8.aspx";
  15.         private const string urlKeyword = "http://www.lokapi.cn/checkWord.aspx";
  16.         private const string rece = "json";
  17.         private const string username = "";
  18.         private const string password = "";
  19.         private const string encode = "utf-8";
  20.         //token
  21.         private const string tokenYZM = "";//验证码
  22.         private const string tokenTZ = "";//通知
  23.         private const string tokenYX = "";//营销
  24.         private const string tokenMMS = "";//彩信
  25.         private const string tokenVideo = "";//视频
  26.         private const string tokenSX = "";//闪信
  27.         private const string tokenVoice = "";//语音
  28.         private const string tokenInter = "";//国际
  29.         //模板ID
  30.         private const string templateid = "";
  31.         //参数
  32.         private const string param = "17733861234|2541";
  33.         private const string mobile = "";
  34.         private const string title = "祝福短信";//彩信标题
  35.         static void Main(string[] args)
  36.         {
  37.             string result = "";
  38.             string sign = "";
  39.             string passwordMd5 = Common.Md5Hash(password);
  40.             string ticks = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000).ToString();
  41.             Encoding encoding = Encoding.GetEncoding(encode);
  42.             StringBuilder sb = new StringBuilder();
  43.             #region 文字短信
  44.             sb.AppendFormat("action=sendtemplate&username={0}&password={1}&token={2}&timestamp={3}", username, passwordMd5, tokenYZM, ticks);
  45.             sign = Common.Md5Hash(sb.ToString());
  46.             sb.AppendFormat("&sign={0}&rece={1}", sign, rece);
  47.             sb.AppendFormat("&templateid={0}&param={1}", templateid, param);
  48.             result = Common.HttpPost(url, sb.ToString(), encoding);
  49.             Console.WriteLine(result);
  50.             #endregion
  51.             #region 彩信
  52.             sb.Clear();
  53.             sb.AppendFormat("action=sendimagetext&username={0}&password={1}&token={2}&timestamp={3}", username, passwordMd5, tokenYZM, ticks);
  54.             sign = Common.Md5Hash(sb.ToString());
  55.             sb.AppendFormat("&sign={0}&rece={1}", sign, rece);
  56.             sb.AppendFormat("&mobile={0}&title={1}", mobile, title);
  57.             //彩信发送主体
  58.             //文字
  59.             string content = "祝你生日快乐";
  60.             Encoding encodingGB = Encoding.GetEncoding("gb2312");
  61.             byte[] txt_bytes = encoding.GetBytes(content);
  62.             string txt = Convert.ToBase64String(txt_bytes);
  63.             //图片
  64.             string path = @"D:\我的文档\Pictures\11.jpg";
  65.             string extension = "jpg";//图片后缀
  66.             byte[] bytes = File.ReadAllBytes(path);
  67.             string imgContent = System.Convert.ToBase64String(bytes);
  68.             string message = string.Format("txt|{0},{1}|{2};", txt, extension, imgContent);
  69.             message = message.Replace("%", "%25");
  70.             message = message.Replace("&", "%26");
  71.             message = message.Replace("+", "%2B");
  72.             sb.AppendFormat("&message={0}", message);
  73.             result = Common.HttpPost(url, sb.ToString(), encoding);
  74.             Console.WriteLine(result);
  75.             #endregion
  76.             #region 视频
  77.             sb.Clear();
  78.             sb.AppendFormat("action=sendvideo&username={0}&password={1}&token={2}&timestamp={3}", username, passwordMd5, tokenYZM, ticks);
  79.             sign = Common.Md5Hash(sb.ToString());
  80.             sb.AppendFormat("&sign={0}&rece={1}", sign, rece);
  81.             sb.AppendFormat("&mobile={0}&templateid={1}", mobile, templateid);
  82.             result = Common.HttpPost(url, sb.ToString(), encoding);
  83.             Console.WriteLine(result);
  84.             #endregion
  85.             #region 闪信
  86.             sb.Clear();
  87.             sb.AppendFormat("action=sendshanxin&username={0}&password={1}&token={2}&timestamp={3}", username, passwordMd5, tokenYZM, ticks);
  88.             sign = Common.Md5Hash(sb.ToString());
  89.             sb.AppendFormat("&sign={0}&rece={1}", sign, rece);
  90.             sb.AppendFormat("&templateid={0}&param={1}", templateid, param);
  91.             result = Common.HttpPost(url, sb.ToString(), encoding);
  92.             Console.WriteLine(result);
  93.             #endregion
  94.             #region 语音
  95.             sb.Clear();
  96.             sb.AppendFormat("action=sendvoice&username={0}&password={1}&token={2}&timestamp={3}", username, passwordMd5, tokenYZM, ticks);
  97.             sign = Common.Md5Hash(sb.ToString());
  98.             sb.AppendFormat("&sign={0}&rece={1}", sign, rece);
  99.             sb.AppendFormat("&templateid={0}&param={1}", templateid, param);
  100.             result = Common.HttpPost(url, sb.ToString(), encoding);
  101.             Console.WriteLine(result);
  102.             #endregion
  103.             #region 国际
  104.             sb.Clear();
  105.             sb.AppendFormat("action=sendinternation&username={0}&password={1}&token={2}&timestamp={3}", username, passwordMd5, tokenYZM, ticks);
  106.             sign = Common.Md5Hash(sb.ToString());
  107.             sb.AppendFormat("&sign={0}&rece={1}", sign, rece);
  108.             sb.AppendFormat("&templateid={0}&param={1}", templateid, param);
  109.             result = Common.HttpPost(url, sb.ToString(), encoding);
  110.             Console.WriteLine(result);
  111.             #endregion
  112.             #region 文字回复报告
  113.             sb.Clear();
  114.             sb.AppendFormat("action=sms&username={0}&password={1}&timestamp={2}", username, passwordMd5, ticks);
  115.             sign = Common.Md5Hash(sb.ToString());
  116.             sb.AppendFormat("&sign={0}&rece={1}", sign, rece);
  117.             result = Common.HttpPost(urlReply, sb.ToString(), encoding);
  118.             Console.WriteLine(result);
  119.             #endregion
  120.             #region 状态报告
  121.             sb.Clear();
  122.             //action根据API文档选择合适产品的action
  123.             sb.AppendFormat("action=sms&username={0}&password={1}&timestamp={2}", username, passwordMd5, ticks);
  124.             sign = Common.Md5Hash(sb.ToString());
  125.             sb.AppendFormat("&sign={0}&rece={1}", sign, rece);
  126.             result = Common.HttpPost(urlStatus, sb.ToString(), encoding);
  127.             Console.WriteLine(result);
  128.             #endregion
  129.             #region 余额查询
  130.             sb.Clear();
  131.             sb.AppendFormat("action=overage&username={0}&password={1}&token={2}&timestamp={3}", username, passwordMd5, tokenTZ, ticks);
  132.             sign = Common.Md5Hash(sb.ToString());
  133.             sb.AppendFormat("&sign={0}&rece={1}", sign, rece);
  134.             result = Common.HttpPost(urlBalance, sb.ToString(), encoding);
  135.             Console.WriteLine(result);
  136.             #endregion
  137.             #region 屏蔽词检测
  138.             sb.Clear();
  139.             sb.AppendFormat("username={0}&password={1}&timestamp={2}", username, passwordMd5, ticks);
  140.             sign = Common.Md5Hash(sb.ToString());
  141.             sb.AppendFormat("&sign={0}&rece={1}&message={2}", sign, rece, "您的验证码是5412");
  142.             result = Common.HttpPost(urlKeyword, sb.ToString(), encoding);
  143.             Console.WriteLine(result);
  144.             #endregion
  145.             Console.ReadKey();
  146.         }
  147.     }
  148. }
复制代码
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Security.Cryptography;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace WinApiDemo
  10. {
  11.     public class Common
  12.     {
  13.         public static string HttpPost(string Url, string Body, Encoding encode)
  14.         {
  15.             string ResponseContent = "";
  16.             try
  17.             {
  18.                 HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
  19.                 httpWebRequest.ContentType = "application/x-www-form-urlencoded";
  20.                 httpWebRequest.Method = "POST";
  21.                 httpWebRequest.Timeout = 600000; //setInstanceFollowRedirects
  22.                 byte[] btBodys = encode.GetBytes(Body);
  23.                 httpWebRequest.ContentLength = btBodys.Length;
  24.                 Stream reqStream = httpWebRequest.GetRequestStream();
  25.                 reqStream.Write(btBodys, 0, btBodys.Length);
  26.                 HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  27.                 Stream resStream = httpWebResponse.GetResponseStream();
  28.                 StreamReader streamReader = new StreamReader(resStream, encode);
  29.                 ResponseContent = streamReader.ReadToEnd();
  30.                 streamReader.Close();
  31.                 resStream.Close();
  32.                 reqStream.Close();
  33.                 streamReader.Dispose();
  34.                 resStream.Dispose();
  35.                 reqStream.Dispose();
  36.                 httpWebResponse.Close();
  37.                 httpWebResponse.Dispose();
  38.                 httpWebRequest.Abort();
  39.             }
  40.             catch (Exception ex)
  41.             {
  42.                 return ex.ToString();
  43.             }
  44.             return ResponseContent;
  45.         }
  46.         public static string Md5Hash(string input)
  47.         {
  48.             MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
  49.             byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
  50.             StringBuilder sBuilder = new StringBuilder();
  51.             for (int i = 0; i < data.Length; i++)
  52.             {
  53.                 sBuilder.Append(data[i].ToString("x2"));
  54.             }
  55.             return sBuilder.ToString().ToUpper();
  56.         }
  57.     }
  58. }
复制代码
 
服务信息:发布旅游信息,吸引客户,这种方式费用低,效率好。景区宣传:可对旅游景区(点)或旅游公司新推出的旅游路线进行形貌,通过短信发送到潜伏顾客的手机上,实现对旅游产物及服务的跨地区、跨时空宣传。

订房/订票公司、旅行社可以通过短信通向客户发送消费积分、节日祝福、生日祝贺等,实现低成本有效的客户管理,加强客情沟通、提高客户满意度,提高营业收入。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

数据人与超自然意识

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表