在ASP.NET中使用C#.NET的Imagmenting Clickatell CallBack [英] Impementing Clickatell CallBack in ASP.NET using C#.NET

查看:177
本文介绍了在ASP.NET中使用C#.NET的Imagmenting Clickatell CallBack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET中使用C#.NET构建一个web应用程序,使用clickatell发送短信。



我尝试从clickatell接收状态失败通过创建一个称为ClickatellCallBack.aspx的CallBack页面这是页面的代码后端:


public partial class ClickatellCallBack:System.Web.UI。页面

{

protected void Page_Load(对象发件人,EventArgs e)

{

//从QueryString检索值。

string apiID = Request.QueryString [api_id];

string from = Request.QueryString [from];

string to =请求。 QueryString [to];

string timestamp = Request.QueryString [timestamp];

string apiMsgId = Request.QueryString [apiMsgId];

string cliMsgId = Request.QueryString [cliMsgId];

string status = Request.QueryString [status];

string charge = Request.QueryString [charge ];

  //将SMS状态值插入数据库。 
int smsStatusID = SMSManager.InsertSMSStatus(apiID,从,到,
timestamp,apiMsgId,cliMsgId,status,charge);

}

}


基本上,此页面检索从clickatell发送的Query String值,并将它们插入到数据库表中。



以下回呼网址: http://www.mydomain.com/ClickatellCallBack.aspx with clickatell和选择回调类型:HTTP GET



在我的'sendmsg'命令中,我设置传递确认和回调请求如下:deliv_ack = 1 and callback = 3



唯一的问题是没有发生任何事情。 CallBack网址似乎未被clickatell触及。



我错过了什么?我做错了。我需要使用除ASP.NET页面之外的其他东西来实现此回调URL吗?



任何帮助都将非常感激。



尊敬的

p>

Walter

解决方案

我通过将回调和deliver_ack参数使用startbatch命令而不是quicksend命令。这似乎工作。所以这里是我在 C#.NET 函数内启动批处理:

  protected string get_batch_id(string session_id,string message_body)
{
//声明一个WebClient。
WebClient client = new WebClient();

//添加用户代理头。
client.Headers.Add(user-agent,Mozilla / 4.0(compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;));

//将session_id添加到查询字符串。
client.QueryString.Add(session_id,session_id);

//将模板添加到查询字符串。
client.QueryString.Add(template,message_body);

//将回调添加到查询字符串。
client.QueryString.Add(callback,3);

//将deliv_ack添加到查询字符串。
client.QueryString.Add(deliv_ack,1);

//声明baseurl。
string baseurl =http://api.clickatell.com/http_batch/startbatch;

//打开baseurl。
Stream data = client.OpenRead(baseurl);

//声明并实例化StreamReader以检索执行startbatch命令的结果。
StreamReader reader = new StreamReader(data);

//解析并将返回的字符串拆分为returned_strings数组。
string [] returned_strings = reader.ReadToEnd()。Split('');

//从return_strings数组的第二个元素中检索batch_id。
string batch_id = returned_strings [1] .ToString();

//关闭流。
data.Close();

//关闭阅读器。
reader.Close();

//返回batch_id。
return(batch_id);
}

Phew!



因此,我还设法使用 C#.NET 在ASP.NET中成功编码以下功能:


  1. 向单个收件人发送邮件;

  2. 将同一邮件发送给多个收件人;

  3. 发送个性化邮件

  4. 方式我注意到,在 ASP.NET 中使用 C#.NET 没有太多的cliackatell代码示例。


    I am building a web application in ASP.NET using C#.NET which sends a SMS using clickatell.

    I am trying unsuccessfully to receive a status back from clickatell by creating a CallBack Page called ClickatellCallBack.aspx Here is the codebehind of the Page:

    public partial class ClickatellCallBack : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    // Retrieve the values from the QueryString.
    string apiID = Request.QueryString["api_id"];
    string from = Request.QueryString["from"];
    string to = Request.QueryString["to"];
    string timestamp = Request.QueryString["timestamp"];
    string apiMsgId = Request.QueryString["apiMsgId"];
    string cliMsgId = Request.QueryString["cliMsgId"];
    string status = Request.QueryString["status"];
    string charge = Request.QueryString["charge"];

       // Insert the SMS Status values into the database.  
       int smsStatusID = SMSManager.InsertSMSStatus(apiID, from, to,
          timestamp, apiMsgId, cliMsgId, status, charge);  
    

    }
    }

    Basically, this Page retrieves the Query String values sent from clickatell and inserts them into a database table.

    I have registered the following Callback URL: http://www.mydomain.com/ClickatellCallBack.aspx with clickatell and selected the Callback Type: HTTP GET

    In my 'sendmsg' command I set delivery acknowledgement and callback request as follows: deliv_ack=1 and callback=3

    The only problem being that nothing appears to be happening. The CallBack URL doesn't appear to be reached by clickatell.

    Am I missing something? Am I doing something wrong. Do I need to implement this Callback URL using something other than an ASP.NET Page? Is there some clickatell setting I'm missing?

    Any help would be greatly appreciated.

    Regards

    Walter

    解决方案

    I solved the problem by placing the callback and deliver_ack parameters with the startbatch command and not the quicksend command. This seems to work. So here is what I have inside the C#.NET function that starts the batch:

    protected string get_batch_id(string session_id, string message_body)
    {
        // Declare a WebClient.
        WebClient client = new WebClient();
    
        // Add a User Agent Header.
        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)");
    
        // Add the session_id to the Query String.
        client.QueryString.Add("session_id", session_id);
    
        // Add the template to the Query String.
        client.QueryString.Add("template", message_body);
    
        // Add the callback to the Query String.
        client.QueryString.Add("callback", "3");
    
        // Add the deliv_ack to the Query String.
        client.QueryString.Add("deliv_ack", "1");
    
        // Declare the baseurl.
        string baseurl = "http://api.clickatell.com/http_batch/startbatch";
    
        // Open the baseurl.
        Stream data = client.OpenRead(baseurl);
    
        // Declare and instantiate a StreamReader to retrieve the results of executing the startbatch command.
        StreamReader reader = new StreamReader(data);
    
        // Parse and split the returned string into the returned_strings array.
        string[] returned_strings = reader.ReadToEnd().Split(' ');
    
        // Retrieve the batch_id from the (second element of the) returned_strings array.
        string batch_id = returned_strings[1].ToString();
    
        // Close the Stream.
        data.Close();
    
        // Close the Reader.
        reader.Close();
    
        // Return the batch_id.
        return (batch_id);
    }
    

    Phew!

    So I've also managed to get the following functionality successfully coded up in ASP.NET using C#.NET:

    1. Send a message to a single recipient;
    2. Send the same message to multiple recipients;
    3. Send a personalised message to a single recipient;
    4. Send a personalised message to multiple recipients;

    Along the way I've noticed that there aren't too many cliackatell code samples in ASP.NET using C#.NET.

    这篇关于在ASP.NET中使用C#.NET的Imagmenting Clickatell CallBack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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