加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

调用WebServices接口实现短信收发

发布时间:2020-12-17 02:03:29 所属栏目:安全 来源:网络整理
导读: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 SM

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必须为数字!请重新输入.",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("请输入目标号码和短信内容","发送短信",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("定时发送格式不正确!",MessageBoxIcon.Error);
??????????????????? this.button1.Enabled = true;
??????????????????? this.t_sendTime.Focus();
??????????????????? return;
??????????????? }
??????????????? if (dt <= DateTime.Now)
??????????????? {
??????????????????? MessageBox.Show("定时发送时间必须大于当前时间!",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("获取身份标识串失败!",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,"发送短信状态",MessageBoxIcon.Information);
??????????? }
??????????? else
??????????? {
??????????????? js="发送失败,代码:"+status.RetCode.ToString().Trim()+",原因:"+status.ErrorDesc;
??????????????? MessageBox.Show(js,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()),Int32.Parse(this.t_gateid.Text.ToString().Trim()));
??????????? if (strIdentity == null || strIdentity == "")
??????????? {
??????????????? MessageBox.Show("获取身份标识串失败!",MessageBoxIcon.Error);
??????????????? this.button1.Enabled = true;
??????????????? return;
??????????? }
??????????? string xml = wsms.ReadXml(strIdentity);??????????
??????????? if (xml == null || xml.ToString().Trim()=="")
??????????? {
??????????????? MessageBox.Show("没有收到回复短信!","接收短信",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),MessageBoxIcon.Information);
??????????????????? this.button2.Enabled = true;
??????????????????? return;
??????????????? }
??????????????? ds = ConvertXMLToDataSet(xml);
??????????? }
??????????? catch(Exception ex)
??????????? {
??????????????? MessageBox.Show("加载短信异常,原因:"+ex.Message,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;??????? }??? }}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读