企業簡訊通 C# HTTP介面 傳送簡訊

來源:互聯網
上載者:User

標籤:

/*功能:企業簡訊通 C# HTTP介面 傳送簡訊修改日期:2014-09-01說明:http://api.cnsms.cn/?ac=send&uid=使用者帳號&pwd=MD5位32密碼&mobile=號碼&content=內容狀態:100 發送成功101 驗證失敗102 簡訊不足103 操作失敗104 非法字元105 內容過多106 號碼過多107 頻率過快108 號碼內容空109 帳號凍結110 禁止頻繁單條發送111 系統暫訂發送112 號碼不正確120 系統升級*/using System;using System.Text;using System.Net;using System.IO;using System.Data;namespace EsmsTest{    class SendEsms    {        static void Main(string[] args)        {            string strContent = "企業簡訊通 測試c#";//GET 方式           String getReturn = doGetRequest("http://api.cnsms.cn/?ac=send&uid=100226&pwd=fa246d0262c3925617b0c72bb20eeb1d&mobile=13585519197,13900008888&content=" + strContent);           Console.WriteLine("Get response is: " + getReturn);           StringBuilder sbTemp = new StringBuilder();//POST            sbTemp.Append("ac=send&uid=70299999&pwd=fa246d0262c3925617b0c72bb20eeb1d&mobile=13339196131,15375379376&content=" + strContent);             byte[] bTemp = Encoding.ASCII.GetBytes(sbTemp.ToString());            String postReturn = doPostRequest("http://api.cnsms.cn/", bTemp);            Console.WriteLine("Post response is: " + postReturn);        }        //POST方式發送得結果        private static String doPostRequest(string url, byte[] bData)        {            System.Net.HttpWebRequest hwRequest;            System.Net.HttpWebResponse hwResponse;            string strResult = string.Empty;            try            {                hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);                hwRequest.Timeout = 5000;                hwRequest.Method = "POST";                hwRequest.ContentType = "application/x-www-form-urlencoded";                hwRequest.ContentLength = bData.Length;                System.IO.Stream smWrite = hwRequest.GetRequestStream();                smWrite.Write(bData, 0, bData.Length);                smWrite.Close();            }            catch (System.Exception err)            {                WriteErrLog(err.ToString());                return strResult;            }            //get response            try            {                hwResponse = (HttpWebResponse)hwRequest.GetResponse();                StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.ASCII);                strResult = srReader.ReadToEnd();                srReader.Close();                hwResponse.Close();            }            catch (System.Exception err)            {                WriteErrLog(err.ToString());            }            return strResult;        }        //GET方式發送得結果        private static String doGetRequest(string url)        {            HttpWebRequest hwRequest;            HttpWebResponse hwResponse;            string strResult = string.Empty;            try            {                hwRequest = (System.Net.HttpWebRequest)WebRequest.Create(url);                hwRequest.Timeout = 5000;                hwRequest.Method = "GET";                hwRequest.ContentType = "application/x-www-form-urlencoded";            }            catch (System.Exception err)            {                WriteErrLog(err.ToString());                return strResult;            }            //get response            try            {                hwResponse = (HttpWebResponse)hwRequest.GetResponse();                StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.ASCII);                strResult = srReader.ReadToEnd();                srReader.Close();                hwResponse.Close();            }            catch (System.Exception err)            {                WriteErrLog(err.ToString());            }            return strResult;        }        private static void WriteErrLog(string strErr)        {            Console.WriteLine(strErr);            System.Diagnostics.Trace.WriteLine(strErr);        }    }}

 

返回結果複製
100

 

擷取餘額提取複寫
/*功能:企業簡訊通 C#  HTTP介面 取餘額修改日期:2014-09-01說明:http://api.cnsms.cn/?ac=gc&uid=使用者帳號&pwd=MD5位32密碼狀態:100 發送成功101 驗證失敗102 簡訊不足103 操作失敗104 非法字元105 內容過多106 號碼過多107 頻率過快108 號碼內容空109 帳號凍結110 禁止頻繁單條發送111 系統暫訂發送112 號碼不正確120 系統升級*/using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using Present.Model;using Present.DAL;using Present.BLL;using System.Data.SqlClient;using System.Text;using System.Net;using System.IO;using System.Globalization;using System.Security.Cryptography;public partial class _Default : System.Web.UI.Page{    #region 簡訊發送    protected void Button2_Click(object sender, EventArgs e)    {string uid="100226";//使用者名稱string pass = "100226";//密碼               StringBuilder sbTemp = new StringBuilder();pass = FormsAuthentication.HashpwdForStoringInConfigFile(pass, "MD5"); //密碼進行MD5加密        //POST 傳值        sbTemp.Append("ac=gc&uid="+uid+"&pwd=" + pass );        byte[] bTemp = System.Text.Encoding.GetEncoding("GBK").GetBytes(sbTemp.ToString());        String postReturn = doPostRequest("http://api.cnsms.cn/", bTemp);        Response.Write("Post response is: " + postReturn);  //測試返回結果    }    //POST方式發送得結果    private static String doPostRequest(string url, byte[] bData)    {        System.Net.HttpWebRequest hwRequest;        System.Net.HttpWebResponse hwResponse;        string strResult = string.Empty;        try        {            hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);            hwRequest.Timeout = 5000;            hwRequest.Method = "POST";            hwRequest.ContentType = "application/x-www-form-urlencoded";            hwRequest.ContentLength = bData.Length;            System.IO.Stream smWrite = hwRequest.GetRequestStream();            smWrite.Write(bData, 0, bData.Length);            smWrite.Close();        }        catch (System.Exception err)        {            WriteErrLog(err.ToString());            return strResult;        }        //get response        try        {            hwResponse = (HttpWebResponse)hwRequest.GetResponse();            StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.ASCII);            strResult = srReader.ReadToEnd();            srReader.Close();            hwResponse.Close();        }        catch (System.Exception err)        {            WriteErrLog(err.ToString());        }        return strResult;    }    private static void WriteErrLog(string strErr)    {        Console.WriteLine(strErr);        System.Diagnostics.Trace.WriteLine(strErr);    }    #endregion}

 

返回結果複製
100||22348

企業簡訊通 C# HTTP介面 傳送簡訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.