使用C#.NET在ASP.NET中强制使用Clickatell CallBack

我正在使用C#.NET在ASP.NET中构建一个Web应用程序,它使用clickatell发送一个SMS。

我试图通过创建一个名为ClickatellCallBack.aspx的CallBack页面来尝试从clickatell接收状态,这是以下代码的后台:

public partial class ClickatellCallBack:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
//从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); 

}
}

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

我已经注册了以下回调url: http ://www.mydomain.com/ClickatellCallBack.aspx with clickatell并选择了回拨类型:HTTP GET

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

唯一的问题是似乎没有发生任何事情。 Clickatell似乎没有达到CallBack URL。

我错过了什么吗? 难道我做错了什么。 我是否需要使用ASP.NET页面以外的其他方式实现此回调URL? 我缺少一些clickatell设置吗?

任何帮助将不胜感激。

问候

沃尔特

我通过使用startbatch命令而不是quicksend命令放置callback和deliver_ack参数来解决问题。 这似乎有效。 这就是我在C#.NET函数中启动批处理的内容:

 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); } 

唷!

所以我还设法使用C#.NET在ASP.NET中成功编写了以下function:

  1. 向单个收件人发送邮件;
  2. 将相同的消息发送给多个收件人;
  3. 向单个收件人发送个性化邮件;
  4. 向多个收件人发送个性化邮件;

一路走来,我注意到在使用C#.NET ASP.NET中没有太多的cliackatell代码示例。