近端时间接了个需求在原来的OA办公系统中添加一个发送短信功能。(既然需要发送短信那肯定要申请一个发送短信的账号,我这里是以移动mas为列子)

c#的weserver需要选协议WS。其他的基本不用怎么填写直接提交就可以了。

在vs项目中添加服务器引用

其中需要选择高级中的web引用

添加完成后样式

调用就简单了

  CmsLsMac.WsSmsServiceService cms=new CmsLsMac.WsSmsServiceService ();//短信接口

            myContent mycontent = new myContent();
string md5= UserMd5("加密信息"); mycontent.ecName = "企业名称";
mycontent.apId = "账号";
mycontent.secretKey = "密码";
//mycontent.mobiles = "电话";
mycontent.content = "今天有雷阵雨";
mycontent.sign = "签名";
mycontent.addSerial = "";//可以为null
List<string> list = new List<string>();
list.Add("电话");//具体有哪些电话号码
string mobezz = "";
foreach (var item in list)
{
mobezz += item;
}
//md5加密
mycontent.mac = UserMd5(mycontent.ecName + mycontent.apId + mycontent.secretKey + mobezz + mycontent.content + mycontent.sign); string str="<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<WsSubmitReq>" + " <apId>" + mycontent.apId + "</apId>" + " <secretKey>" + mycontent.secretKey + "</secretKey>"
+ " <ecName>" + mycontent.ecName + "</ecName>" + " <mobiles>" + GetMobiles(list)
+ " </mobiles>" + " <content>" + mycontent.content + "</content>" + " <sign>" + mycontent.sign + "</sign>" + " <addSerial>" + mycontent.addSerial + "</addSerial>"
+ " <mac>" + mobezz + "</mac>" + "</WsSubmitReq>";
       var returnz= cms.sendSms(str);//发送短信方法 根据返回值查看是否发送成功。

最主要的是需要知道接口那个方法是发送短信的。

MD5加密

public  string UserMd5(string str)
{
string cl = str;
string pwd = "";
MD5 md5 = MD5.Create();//实例化一个md5对像
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
for (int i = 0; i < s.Length; i++)
{
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
pwd = pwd + s[i].ToString("x2");
}
return pwd;
}

电话号码循环的---可群发

        public string GetMobiles(List<string> list)
{
StringBuilder soap = new StringBuilder();
foreach (var item in list)
{
soap.Append("<string>" + item + "</string>");
}
return soap.ToString(); }

最新文章

  1. 排序算法总结------选择排序 ---javascript描述
  2. Spring JDBC常用方法详细示例
  3. 22Mybatis_订单商品数据模型_多对多查询以及对多对多查询的总结
  4. LoadRunner中响应时间与事物时间详解
  5. C语言学习笔记(1):Hello World!
  6. c#序列化反序列化工具(json,binary,xml)
  7. java 对map排序
  8. linux驱动---字符设备的注册register_chrdev说起
  9. hdu 5600 BestCoder Round #67 (div.2)
  10. @SuppressWarnings(&quot;resource&quot;)
  11. you have mixed tabs and spaces.Fix This屏蔽
  12. 处理Task引发的异常
  13. Linux学习之文件系统常用命令(七)
  14. ZooKeeper分布式过程协同技术详解2——了解ZooKeeper
  15. spring-AOP框架(基于配置文件的方式配置AOP)
  16. 2019.01.02 洛谷P4512 【模板】多项式除法
  17. Bzoj2694/Bzoj4659:莫比乌斯反演
  18. logback.xml常用配置详解
  19. redis参数AOF参数的bug
  20. canvas时钟demo

热门文章

  1. mysql密码设置为空怎么办?
  2. Flask中路由参数
  3. springboot之activemq安装与实践
  4. springboot之JWT实现权限认证
  5. [Scikit-learn] *2.3 Clustering - DBSCAN: Density-Based Spatial Clustering of Applications with Noise
  6. Oracle查询序列和函数方法封装
  7. Django -- DateTimeField
  8. JDK1.8新特性之Optional
  9. Burp_Suite_Pro_v1.7.*激活
  10. appium+python教程1