标签:
云之讯:http://www.ucpaas.com/price
中国网建:http://sms.webchinese.cn/api.shtml 测试的时候发现短信达到延迟太久,没办法使用。
云通讯:http://www.yuntongxun.com/
我使用了云之讯来作为我的通讯第三方,平台提供了详细的接口说明和资费说明。
到他们官网可以下载到C#的demo,在我开发的过程中发现他们的demo缺少了一个语音电话,
根据他们的协议要,写了一个《云之讯语音通知协议》
/// <summary> /// 电话语言提醒 /// </summary> /// <param name="toPhone">被叫号码,可以是正常手机号码、固定号码,被叫为座机时需要添加区号,如:075512345678。</param> /// <param name="toSerNum">语音通知的被叫侧显示的号码。可显示手机号码、400号码或固话。查阅显号规则。</param> /// <param name="type">内容类型:0:文本;1:语音ID</param> /// <param name="content">当type为0时:文本内容,平台负责将该内容转成语音,呼通指定号码后,播放该语音文件;当type为1时:表示语音ID(语音文件必须先上传)。</param> /// <param name="playTimes">循环播放次数,1-3次,默认播放1次。</param> /// <returns>包体内容</returns> public string CallUpSomebody( string toPhone, string toSerNum,string type,string content,string playTimes) { if (toPhone == null) { throw new ArgumentNullException("toPhone"); } try { string date = DateTime.Now.ToString("yyyyMMddHHmmss"); // 构建URL内容 string sigstr = MD5Encrypt(m_mainAccount + m_mainToken + date); string uriStr; string xml = (m_bodyType == EBodyType.EType_XML ? ".xml" : ""); uriStr = string.Format("https://{0}:{1}/{2}/Accounts/{3}/Calls/voiceNotify{4}?sig={5}", m_restAddress, m_restPort, softVer, m_mainAccount, xml, sigstr); Uri address = new Uri(uriStr); WriteLog("CallBack url = " + uriStr); // 创建网络请求 HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest; setCertificateValidationCallBack(); // 构建Head request.Method = "POST"; Encoding myEncoding = Encoding.GetEncoding("utf-8"); byte[] myByte = myEncoding.GetBytes(m_mainAccount + ":" + date); string authStr = Convert.ToBase64String(myByte); request.Headers.Add("Authorization", authStr); // 构建Body StringBuilder data = new StringBuilder(); if (m_bodyType == EBodyType.EType_XML) { request.Accept = "application/xml"; request.ContentType = "application/xml;charset=utf-8"; data.Append("<?xml version=‘1.0‘ encoding=‘utf-8‘?><voiceNotify>"); data.Append("<appId>").Append(m_appId).Append("</appId>"); data.Append("<to>").Append(toPhone).Append("</to>"); data.Append("<type>").Append(type).Append("</type>"); data.Append("<content>").Append(content).Append("</content>"); data.Append("<toSerNum>").Append(toSerNum).Append("</toSerNum>"); data.Append("<playTimes>").Append(playTimes).Append("</playTimes>"); data.Append("</voiceNotify>"); } else { request.Accept = "application/json"; request.ContentType = "application/json;charset=utf-8"; data.Append("{"); data.Append("\"voiceNotify\":{"); data.Append("\"appId\":\"").Append(m_appId).Append("\""); data.Append(",\"to\":\"").Append(toPhone).Append("\""); data.Append(",\"type\":\"").Append(type).Append("\""); data.Append(",\"content\":\"").Append(content).Append("\""); data.Append(",\"toSerNum\":\"").Append(toSerNum).Append("\""); data.Append(",\"playTimes\":\"").Append(playTimes).Append("\""); data.Append("}}"); } byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString()); WriteLog("CreateSubAccount requestBody = " + data.ToString()); // 开始请求 using (Stream postStream = request.GetRequestStream()) { postStream.Write(byteData, 0, byteData.Length); } // 获取请求 using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { // Get the response stream StreamReader reader = new StreamReader(response.GetResponseStream()); string responseStr = reader.ReadToEnd(); WriteLog("CreateSubAccount responseBody = " + responseStr); if (responseStr != null && responseStr.Length > 0) { return responseStr; } } return null; } catch (Exception e) { throw e; } }
以上都提供了demo。使用起来比较方便。
标签:
原文地址:http://www.cnblogs.com/annkiny/p/5093734.html