76 lines
2.5 KiB
C#
76 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
|
|
namespace _1200gFtp
|
|
{
|
|
class SMS
|
|
{
|
|
public static string smsSend(string phone, string content)
|
|
{
|
|
string userid = "1699";//企业ID
|
|
string account = "XDKJ168"; //用户名
|
|
string password = "qwe18601017090"; //密码
|
|
StringBuilder sbTemp = new StringBuilder();
|
|
//POST 传值
|
|
sbTemp.Append("action=send&userid=" + userid + "&account=" + account + "&password=" + password + "&mobile=" + phone + "&content=" + content);
|
|
byte[] bTemp = System.Text.Encoding.GetEncoding("GBK").GetBytes(sbTemp.ToString());
|
|
string postReturn = doPostRequest("http://www.uehyt.com/smsGBK.aspx", bTemp);
|
|
//Response.Write("Post response is: " + postReturn); //测试返回结果
|
|
return postReturn;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
}
|
|
}
|