企业短信通 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分钟就能搞定服务注册: ...
随机推荐
- 2——FFMPEG之协议(文件)操作----AVIOContext, URLContext, URLProtocol
协议操作对象结构: 协议(文件)操作的顶层结构是AVIOContext,这个对象实现了带缓冲的读写操作:FFMPEG的输入对象AVFormat的pb字段指向一个AVIOContext. AVIOCon ...
- Android代码混淆及项目发布方法记录
Android代码混淆及项目发布步骤记录 本来整理了一份Android项目混淆与发布的文档,突然想到何不写篇博客,分享一下呢,如是便有了本文. Android代码混淆及项目发布步骤记录 一.清理 ...
- mysql的5.6版本支持分区吗?
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/72291698 本文出自[我是干勾鱼的博客] 我们知道,查看mysql是否支持分区 ...
- TCP服务器端口数,最大连接数以及MaxUserPort的关系辨真
原文连接:http://www.jianshu.com/p/4a58761d758f 关于TCP服务器最大并发连接数有一种误解就是"因为端口号上限为65535,所以TCP服务器理论上的可承载 ...
- Delphi XE4 Upate1 更新升级记录.
一直没时间,这两天折腾了一下 升级了. 其实也可能修了老bug 引入新bug. 呵呵. 看看Emb 都修了什么吧. 我干脆是重新安装的. 虽然官方也有一个单独的update.exe. 从这些bu ...
- Spring中的c3p0配置
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/51162560 今天,我们就来详细谈谈Spring中的c3p0配置问题,好了,不耽搁 ...
- LA3218 Find the Border
题意 PDF 分析 虽然只找外轮廓,但是时间复杂度不比PSLG优秀,所以可以当做联系PSLG的题做. PSLG框架 找出所有交点 交点按序连边 把边按极角序排序 逆时针找圈 然后何以会顺时针找出无限区 ...
- 一般在cmd中报不是合法的命令啥的,都是环境变量没有配置好
在配置cnpm的时候一定要将环境变量先配置好,配置如下: C:\Program Files\nodejs; C:\Program Files\nodejs\node_global; C:\Progra ...
- fn project k8s 集成
具体部署还是比较简单的,以下为官方参考,只是有一个service type 为 loadBlancer 实际使用需要修改为NodePort Prerequisite 1: working Kuber ...
- docker 命令记录
从 Docker 镜像仓库获取镜像的命令是 docker pull.其命令格式为: docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签] 具体的选项 ...