using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SMS.cn.woxp.gateway;
using System.IO;
using System.Xml;
namespace SMS
{
    /*采用web Service接口实现短信收发
     * 本程序适合网关版本v1.0开发
     本演示代码由星幻科技提供.如有其它问题请与我们联系.
     * 如果发送失败原因与通道有关.可能是由于某些原因导致通道关闭.请切换其它通道使用
     * 短信通道发送出现延时比较长.建议切换通道发送.[任何短信网关都会出现短信延时.请谅解]
     * -----------------------------------------------------------------
     * 本演示代码由[星幻科技 www.woxp.cn]提供,最新接口请登陆会员中心查看
     * -----------------------------------------------------------------
     */
    public partial class Form1 : Form
    {
        private cn.woxp.gateway.WebSMS wsms = new SMS.cn.woxp.gateway.WebSMS();
        private string strIdentity = "";
        public Form1()
        {
            InitializeComponent();
        }

private void label7_Click(object sender, EventArgs e)
        {

}

private void Form1_Load(object sender, EventArgs e)
        {          
            this.l_money.Text = "0.00";
        }
        private bool CheckGate()
        {
            int temp = 0;
            if (this.t_eid.Text.ToString().Trim() == "" || this.t_gateid.Text.ToString().Trim() == "" || this.t_pwd.Text.ToString().Trim() == "" || this.t_uid.Text.ToString().Trim() == "")
            {
                MessageBox.Show("网关参数输入不全!请重新输入", "网关参数配置", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            if (!Int32.TryParse(this.t_eid.Text.ToString().Trim(), out temp) || !Int32.TryParse(this.t_gateid.Text.ToString().Trim(),out temp))
            {
                MessageBox.Show("企业代码或者网关通道ID必须为数字!请重新输入.", "网关参数配置", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.button1.Enabled = false;
            if (!CheckGate())
            {
                this.button1.Enabled = true;
                return;
            }
            if (this.t_sendNo.Text.ToString().Trim() == "" || this.t_sendMemo.Text.ToString().Trim() == "")
            {
                MessageBox.Show("请输入目标号码和短信内容", "发送短信", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.t_sendNo.Focus();
                this.button1.Enabled = true;
                return;
            }
            if (this.t_sendTime.Text.ToString().Trim() != "")
            {
                DateTime dt;
                if (!DateTime.TryParse(this.t_sendTime.Text.ToString().Trim(), out dt))
                {
                    MessageBox.Show("定时发送格式不正确!", "发送短信", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.button1.Enabled = true;
                    this.t_sendTime.Focus();
                    return;
                }
                if (dt <= DateTime.Now)
                {
                    MessageBox.Show("定时发送时间必须大于当前时间!", "发送短信", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.button1.Enabled = true;
                    return;
                }
            }
            strIdentity= wsms.GetIdentityMark(Int32.Parse(this.t_eid.Text.ToString().Trim()),this.t_uid.Text.ToString().Trim(),this.t_pwd.Text.ToString().Trim(),Int32.Parse(this.t_gateid.Text.ToString().Trim()));
            if(strIdentity == null || strIdentity =="")
            {
                MessageBox.Show("获取身份标识串失败!", "发送短信", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.button1.Enabled = true;
                return;
            }
            string js="";
            //全速提交短信
            SendResult status = wsms.FastSend(strIdentity,this.t_sendNo.Text.ToString().Trim(),this.t_sendMemo.Text.ToString().Trim(),this.t_sendTime.Text.ToString().Trim(),"");
            if(status.RetCode>0)
            {
                this.l_money.Text = wsms.GetMoney(strIdentity).ToString("0.00");
                js="发送成功!共发送:"+status.RetCode.ToString()+"条";
                MessageBox.Show(js, "发送短信状态", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                js="发送失败,代码:"+status.RetCode.ToString().Trim()+",原因:"+status.ErrorDesc;
                MessageBox.Show(js, "发送短信状态", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
           
            this.button1.Enabled = true;
        }

/// <summary>
        /// 收到的XML转成dataset型
        /// </summary>
        /// <param name="xmlData"></param>
        /// <returns></returns>
        public DataSet ConvertXMLToDataSet(string xmlData)
        {
            StringReader stream = null;
            XmlTextReader reader = null;
            try
            {
                DataSet xmlDS = new DataSet();
                stream = new StringReader(xmlData);
                reader = new XmlTextReader(stream);
                xmlDS.ReadXml(reader);
                return xmlDS;
            }
            catch (Exception ex)
            {
                string strTest = ex.Message;
                return null;
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
        }

private void button2_Click(object sender, EventArgs e)
        {
            this.button2.Enabled = false;
            if (!CheckGate())
            {
                this.button2.Enabled = true;
                return;
            }
            strIdentity = wsms.GetIdentityMark(Int32.Parse(this.t_eid.Text.ToString().Trim()), this.t_uid.Text.ToString().Trim(), this.t_pwd.Text.ToString().Trim(), Int32.Parse(this.t_gateid.Text.ToString().Trim()));
            if (strIdentity == null || strIdentity == "")
            {
                MessageBox.Show("获取身份标识串失败!", "发送短信", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.button1.Enabled = true;
                return;
            }
            string xml = wsms.ReadXml(strIdentity);          
            if (xml == null || xml.ToString().Trim()=="")
            {
                MessageBox.Show("没有收到回复短信!", "接收短信", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.button2.Enabled = true;
                return;
            }
            DataSet ds = new DataSet();          
            try
            {
                int code = 0;
                if (Int32.TryParse(xml, out code))
                {
                    MessageBox.Show("加载短信失败,原因:" +wsms.GetErrorHint(code), "接收短信", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.button2.Enabled = true;
                    return;
                }
                ds = ConvertXMLToDataSet(xml);
            }
            catch(Exception ex)
            {
                MessageBox.Show("加载短信异常,原因:"+ex.Message, "接收短信", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.button2.Enabled = true;
                return;
            }
            this.dgv_receive.DataSource = ds.Tables[0];
            this.button2.Enabled = true;
        }

private void button3_Click(object sender, EventArgs e)
        {
            this.t_sendMemo.Text = "";
            this.t_sendNo.Text = "";
            this.t_sendTime.Text = "";
            this.button1.Enabled = true;
            this.button2.Enabled = true;
            this.button3.Enabled = true;
        }
    }
}

调用WebServices接口实现短信收发相关推荐

  1. java+调用飞信_java调用飞信接口发短信

    java调用飞信接口发短信,看到挺好的,有利于大家做毕业设计加亮点,就发给大家了(新人发帖,不会发多个文件名,测试类就放这了) 需要这3个jar包: commons-codec-1.4.jar com ...

  2. JAVA飞信_java调用飞信接口发短信 - 贪吃蛇学院-专业IT技术平台

    java调用飞信接口发短信,看到挺好的,有利于大家做毕业设计加亮点,就发给大家了(新人发帖,不会发多个文件名,测试类就放这了) 需要这3个jar包: commons-codec-1.4.jar com ...

  3. 短信发送:webservice调用第三方接口发送短信

    1 原博客地址:http://blog.csdn.net/sxdtzhaoxinguo/article/details/34437591 2 demo地址:http://download.csdn.n ...

  4. SAP中用json数据格式调用http接口发送短信邮件案例

    在系统 VL02N 交货过账后触发发送邮件.短信的功能,短信邮件接口是经过第三方系统封装,然后开发出的API接口. 请求地址: http://180.167.01.01/ns/sends 请求方式: ...

  5. Python调用飞信接口发送短信

    主要参考了两篇文章:(对原作者表示感谢~) 发送飞信的Python脚本:http://www.cnblogs.com/fatway/archive/2009/08/07/1693813.html 中国 ...

  6. python飞信api_Python调用飞信接口发送短信

    # -*- coding:utf-8 -*- # file: SendFetion.py # by Lee 2013-9-18 """------------------ ...

  7. python飞信api_Python调用飞信接口发送短信 | 学步园

    主要参考了两篇文章:(对原作者表示感谢~) 2013年9月18日亲测可用. 下面是代码:[使用前将账号密码换为自己的] # -*- coding:utf-8 -*- # file: SendFetio ...

  8. java实现调用短信接口发送短信

    如何调用java接口,进行短信的发送呢?现在几乎每一个平台都需要进行验证码短信或者通知类短信的发送,下面提供java接口的DEMO供大家下载: Java短信接口JDK点击下载 或者直接进入官网测试页面 ...

  9. php 请求第三方接口发送短信验证码及注册手机号码

    1:为什么要用短信验证码: 防范XSS和CSRF 2:php中怎样调用第三方接口(短信宝/京东万象/阿里云/容连云):post请求使用Curl();get请求使用file_get_contents() ...

最新文章

  1. 2016全国大学生计算机设计大赛,2016年“第9届中国大学生计算机设计大赛”闭幕...
  2. android 北斗定位代码_大牛三步教你解决,BAT资深APP性能优化系列-卡顿定位问题,收藏哦
  3. python 占位符_5分钟让你用Python作出最精美的Powerpoint
  4. Eating Soup
  5. 养成这6个编程好习惯,助你减少90%BUG
  6. 2017/06/23 linux软件管理构建本地源
  7. ffmpeg简单使用小记
  8. Visual Studio 选择相同变量高亮
  9. 干货 | 中国的支付清算体系是怎么玩的?
  10. linux shell期末测试,LINUX期末复习---SHELL编程
  11. 2. Linear Model
  12. 如何解决同花顺软件打开时,出现 “无法与服务器建立连接” 的问题
  13. 用html制作的蚂蜂窝旅游网页设计,蚂蜂窝扩大移动布局 旅游攻略全面HTML5
  14. 「docker实战篇」python的docker爬虫技术-python脚本app抓取(13)
  15. 技巧:如何提高git下载速度
  16. outlook服务器邮件满了怎么办,outlook邮箱满了怎么清理
  17. linux中 . .bash_profile是什么意思
  18. 解决 primordials is not defined 问题
  19. 使用IDEA写程序时,运行忽然报错,提示:在类*** 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args)
  20. wp后台页面切换慢,打开速度慢:jquery-ui.min.css加载失败——在国外

热门文章

  1. 查看树莓派中python安装路径
  2. upnp协议简介(二)
  3. 深入浅出解析阿里成熟的微前端框架 qiankun 源码【图文并茂】
  4. INGame体素大乱斗
  5. 清华大学 计算机课程,清华大学超算队再获双料世界冠军!首位女队长被教授称为绝对学霸,数学系课程全部4分还是跆拳道高手...
  6. 医学影像领域内的3D转4D数据
  7. APP渠道评估用户,用户质量指标是怎么衡量的?
  8. win7系统服务器无法局域网访问,win7系统局域网无法访问怎么办?win7系统无法访问局域网两种解决方法...
  9. vue组件之间传值的几种方式
  10. 时间间隔感测试器2.0