1

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

我试图通过创建一个名为 ClickatellCallBack.aspx 的回调页面从 clickatell 接收返回的状态,但未成功这是该页面的代码隐藏:

public partial class ClickatellCallBack : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// 从 QueryString 中检索值。
字符串 apiID = Request.QueryString["api_id"];
字符串来自 = Request.QueryString["from"];
字符串 to = Request.QueryString["to"];
字符串时间戳 = Request.QueryString["timestamp"];
字符串 apiMsgId = Request.QueryString["apiMsgId"];
字符串 cliMsgId = Request.QueryString["cliMsgId"];
字符串状态 = Request.QueryString["status"];
字符串费用 = Request.QueryString["charge"];

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

}
}

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

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

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

唯一的问题是似乎什么都没有发生。Clickatell 似乎无法访问回调 URL。

我错过了什么吗?难道我做错了什么。我是否需要使用 ASP.NET 页面以外的东西来实现这个回调 URL?我缺少一些clickatell设置吗?

任何帮助将不胜感激。

问候

沃尔特

4

1 回答 1

2

我通过将 callback 和 Deliver_ack 参数与 startbatch 命令而不是 quicksend 命令一起解决了这个问题。这似乎有效。所以这是我在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);
}

呸!

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

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

在此过程中,我注意到ASP.NET使用C#.NET.

于 2010-02-09T11:18:14.713 回答