发送短信使用way2sms API [英] Send Sms Using way2sms api

查看:196
本文介绍了发送短信使用way2sms API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用的 way2sms 以发送短信。我曾尝试以下code

I want to send SMS using way2sms. I have tried following code

login.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
  public partial class Login : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnconnect_Click(object sender, EventArgs e)
    {
        Session["id"] = txtmobileno.Text;
        Session["pw"] = txtpw.Text;
        Response.Redirect("/send.aspx");
    }
  }
 }

send.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace WebApplication1
{
  public partial class send : System.Web.UI.Page
  {
    string mbno, mseg, ckuser, ckpass;
    private HttpWebRequest req;
    private CookieContainer cookieCntr;
    private string strNewValue;
    public static string responseee;
    private HttpWebResponse response;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["id"] == null && Session["pw"] == null)
        {
            Server.Transfer("login.aspx");
        }
        connect();

        try
        {

            lblError.Text = "";
            lblError.Visible = false;
            if (!(IsPostBack))
            {
                btnSend.Attributes.Add("onclick", "return Validate('" + txtTo.ClientID + "','" + txtMessage.ClientID + "');");
                txtMessage.Attributes.Add("onchange", "TextChange('" + txtMessage.ClientID + "','" + lblLeft.ClientID + "');");
                txtMessage.Attributes.Add("onkeyup", "TextChange('" + txtMessage.ClientID + "','" + lblLeft.ClientID + "');");
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
            lblError.Visible = true;
        }
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
            mbno = txtTo.Text;
            mseg = txtMessage.Text;

            sendSms(mbno, mseg);
            txtTo.Text = "";
            txtMessage.Text = "";
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
            lblError.Visible = true;
        }
    }

    public void connect()
    {
        ckuser = Session["id"].ToString();
        ckpass = Session["pw"].ToString();

        try
        {
            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com/auth.cl");

            this.req.CookieContainer = new CookieContainer();
            this.req.AllowAutoRedirect = false;
            this.req.Method = "POST";
            this.req.ContentType = "application/x-www-form-urlencoded";
            this.strNewValue = "username=" + ckuser + "&password=" + ckpass;
            this.req.ContentLength = this.strNewValue.Length;
            StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
            writer.Write(this.strNewValue);
            writer.Close();
            this.response = (HttpWebResponse)this.req.GetResponse();
            this.cookieCntr = this.req.CookieContainer;
            this.response.Close();
            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//jsp/InstantSMS.jsp?val=0");
            this.req.CookieContainer = this.cookieCntr;
            this.req.Method = "GET";
            this.response = (HttpWebResponse)this.req.GetResponse();
            responseee = new StreamReader(this.response.GetResponseStream()).ReadToEnd();
            int index = Regex.Match(responseee, "custf").Index;
            responseee = responseee.Substring(index, 0x12);
            responseee = responseee.Replace("\"", "").Replace(">", "").Trim();
            this.response.Close();

            pnlsend.Visible = true;
            lblErrormsg.Text = "connected";
        }
        catch (Exception ex)
        {
            lblErrormsg.Text = "Error connecting to the server...";
            Session["error"] = "Error connecting to the server...";
            lblError.Text = ex.ToString();

            lblError.Text= ex.ToString();
            //Server.Transfer("login.aspx");
        }
    }
    public void sendSms(string mbno, string mseg)
    {
        if ((mbno != "") && (mseg != ""))
        {
            try
            {
                this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//FirstServletsms?custid=");
                this.req.AllowAutoRedirect = false;
                this.req.CookieContainer = this.cookieCntr;
                this.req.Method = "POST";
                this.req.ContentType = "application/x-www-form-urlencoded";
                this.strNewValue = "custid=undefined&HiddenAction=instantsms&Action=" + responseee + "&login=&pass=&MobNo=" + this.mbno + "&textArea=" + this.mseg;

                string msg = this.mseg;
                string mbeno = this.mbno;

                this.req.ContentLength = this.strNewValue.Length;
                StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
                writer.Write(this.strNewValue);
                writer.Close();
                this.response = (HttpWebResponse)this.req.GetResponse();

                this.response.Close();
                lblErrormsg.Text = "Message Sent..... " + mbeno + ": " + msg;
            }
            catch (Exception)
            {
                lblErrormsg.Text = "Error Sending msg....check your connection...";
            }
        }
        else
        {
            lblErrormsg.Text = "Mob no or msg missing";
        }
    }

    protected void btnLogOut_Click(object sender, EventArgs e)
    {
        Session["id"] = null;
        Session["pw"] = null;
        Session["error"] = null;
        Server.Transfer("login.aspx");
    }

  }
}

但它不工作。有没有在这个code,我做任何的改变?
请告诉我从桌面任何其他方式为发送短信 应用程序或网​​站应用

推荐答案

我用这个: GSM通信库(GSMComm)

这篇关于发送短信使用way2sms API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆