國內短信接口權威運營服務商網    電信全網移動信息服務許可證:B2-20150469

7x24小時服務熱線:

400-113-0919

asp.net接口示例

asp.net短信接口示例
using System;
using System.Collections;
using System.Configuration;
using System.Data;
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.Text;
using System.Net;
using System.IO;

public partial class _Default : System.Web.UI.Page
{

/********************************************************************************************************/
//數據發送
/********************************************************************************************************/
#region 數據發送
protected void send()
{
string sendurl="http://api.sms.cn/sms/";
string mobile = "15900008888"; //發送號碼
string strContent = "您好,您的驗證碼是111【云信使】";
StringBuilder sbTemp = new StringBuilder();
string uid="test";
string pwd="test123456";
string Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd+uid, "MD5"); //密碼進行MD5加密
//POST 傳值
sbTemp.Append("ac=send&uid="+uid+"&pwd=" + Pass + "&mobile=" + mobile + "&content=" + strContent);
byte[] bTemp = System.Text.Encoding.GetEncoding("GBK").GetBytes(sbTemp.ToString());
String postReturn = doPostRequest(sendurl, 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
}


ASP.NET短信接口示例
宁夏11选5开奖分布走势图 2019年期期平特精准一肖 查一下甘肃快3开奖结果 融资买入股票的规定 华昌达股票股吧 极速赛车群 联盈策略 河北11选5开奖结果走势图-爱彩乐 理财平台商赢金服 江苏11选5特殊号码遗漏 2019年大盘走势总结