企业短信通 C# HTTP接口 发送短信
/*
功能: 企业短信通 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接口 发送短信的更多相关文章
- Java之HttpClient调用WebService接口发送短信源码实战
摘要 Java之HttpClient调用WebService接口发送短信源码实战 一:接口文档 二:WSDL 三:HttpClient方法 HttpClient方法一 HttpClient方法二 Ht ...
- android 中调用接口发送短信
android中可以通过两种方式发送短信 第一:调用系统短信接口直接发送短信:主要代码如下: //直接调用短信接口发短信 SmsManager smsManager = SmsManager.getD ...
- 通过移动的Mas接口发送短信
1. 首先,需要移动公司提供的用户名.密码.服务ID.接口Url等信息. 2. 将短信信息整理成XML格式的字符串,再转为byte数组,通过POST的方式,将短信发往Mas接口.需要引用"M ...
- 注册登录页面修订-Python使用redis-手机验证接口-发送短信验证
登录页面修订 views.Login.vue <template> <div class="login box"> <img src="@/ ...
- JAVA 调用第三方短信平台接口发送短信
做了几个调用三方短信平台发送短信的例子,大部分需要 携带参数,向指定URL发送请求 回顾对接第一个平台时痛苦的乱码经历,这里放一份代码,算是个模版,再用到的时候过来copy一下就OK. 在进入主题之前 ...
- zabbix3调用接口发送短信告警
一.需求 之前使用的邮件告警,由于经常会忽略邮件,所以有时候告警查看的并不及时,所以增加短信告警的,以便及时处理. 二.zabbix-server端的配置 # 需要在zabbix-server端打开A ...
- java 调用短信 api 接口发送短信
参考: https://blog.csdn.net/u014793522/article/details/59062014 参考 :https://blog.csdn.net/Lu_shilusi ...
- 如何使用微信小程序云函数发送短信验证码
其实微信小程序前端和云端都是可以调用短信平台接口发送短信的,使用云端云函数的好处是无需配置域名,也没有个数限制. 本文使用的是榛子云短信平台(http://smsow.zhenzikj.com) ,S ...
- 发送短信——java
闲来无事研究一下调用第三方接口发送短信的技术 这一次我们使用阿里的短信服务 一.进行平台相关服务的注册和设置 下面请参照阿里的短信服务文档进行设置,只要按照文档步骤来差不多30分钟就能搞定服务注册: ...
随机推荐
- 【sparkStreaming】将DStream保存在MySQL
package SparkDemo import java.sql.{Connection, DriverManager, PreparedStatement} import org.apache.s ...
- 【hive】函数大全
数学函数 Return Type Name (Signature) Description DOUBLE round(DOUBLE a) Returns the rounded BIGINT valu ...
- Python基础学习(第2天)
第三课:序列(sequence) 1.序列是一种有顺序的元素的集合 序列可以包含1个或多个元素,也可以不包括任何元素: 序列中的元素可以是[基础数据类型]中任一种,也可以是[别的序列]. s1 = ( ...
- jsp的运行内幕--Tomcat容器对自定义标签的解析过程
http://blog.sina.com.cn/s/blog_4adc4b090101daqb.html
- 【python】python内存管理摘要
a = 1 id(a) == id(1) 每次退出ipython重新进入,这个Id都会不一样 sys.getrefcount(a) 可以计数某个对象的引用次数,是原来的次数+1 垃圾回收 使用gc包 ...
- 微信oauth2验证
微信公众号进行oauth2验证时的要求: 需要两个地方配置: (1) Oauth2验证链接中的appid.redirecturi (2) 微信公众号授权回调页面域名: Appid为公众号的ap ...
- WEKA运行参数修改(RunWeka.ini文件)
一般使用weka进行数据挖掘的时候会碰到两个问题,一是内存不够,二是libsvm使用不了,这时就需要重新配置RunWeka.ini文件,解决上述问题.查看RunWeka.ini原文如下: # Cont ...
- CentOS 7下sqlite3的问题修复
Centos7下的nltk启动问题 CentOS 7, Python 3.6,ipython 6.0.0 问题描述 ipython 启动ipython命令 import nltk 爆出以下的错误信息: ...
- OpenCV获取RTSP解码播放
#include <opencv2/opencv.hpp> int main(int argc, char **argv){ IplImage *pFrame = NULL, *srcIm ...
- I.MX6 网卡能收不能发
/******************************************************************** * I.MX6 网卡能收不能发 * 说明: * MAC控制器 ...