5.2. C#
using System;
using System.Web;
using System.Text;
using System.Data;
using System.IO;
using System.Net;
using System.Data.SqlClient;
using System.Security.Cryptography;
namespace DEMO
{
public class SendMessageHelloWorld
{
/// <summary>
/// POST 发送短信返回结果
/// </summary>
/// <returns></returns>
public static string PostSendMessage()
{
string url = "http://120.197.89.51/SmsHttpInterface/smsService/Do-sendSms.action";
string Eid = "qxt"; // 企业账号
string Userid = "admin"; // 用户名
string Password = "123456"; // 密码
string MessageC; // 短信内容
string Mobiles = "13888888888"; // 发送号码,多个号码用 , 隔开
string ExtendAccessNum = ""; // 扩展号
string key = "0000000000000000";// 密钥
StringBuilder sb = new StringBuilder();
sb.Append("eid=" + Encrypt(Eid, key) + "&userid=" + Encrypt(Userid, key) + "&password=" + Encrypt(Password, key) + "&c">Encrypt(MessageContent, key) + "&mobile=" + Encrypt(Mobiles, key) + "&extport=" + Encrypt(ExtendAccessNum, key));
byte[] bData = Encoding.GetEncoding("UTF-8").GetBytes(sb.ToString().Replace("+", "%2b"));
HttpWebRequest hwRequest;
HttpWebResponse hwResponse;
string strResult = string.Empty;
try
{
hwRequest = (HttpWebRequest)WebRequest.Create(url);
hwRequest.Method = "POST";
hwRequest.C;
hwRequest.ContentLength = bData.Length;
Stream smWrite = hwRequest.GetRequestStream();
smWrite.Write(bData, 0, bData.Length);
smWrite.Close();
hwResponse = (HttpWebResponse)hwRequest.GetResponse();
StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
strResult = srReader.ReadToEnd();
if(strResult.StartsWith("0,")){// 判断返回成功后解密
strResult = strResult.Substring(2);
strResult = Decrypt(strResult,key);
}
srReader.Close();
hwResponse.Close();
}
catch
{ ;}
return strResult;
}