2015-05-14 61 views

回答

0

您可以在http://docs.pushwoosh.com/docs/createmessage

using System; 
using System.IO; 
using System.Net; 
using Newtonsoft.Json.Linq; 

namespace WebApplication1 
{ 
    public partial class Default : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      string pwAuth = "YOUR_AUTH_TOKEN"; 
      string pwApplication = "PW_APPLICATION_CODE"; 
      JObject json = new JObject(
       new JProperty("application", pwApplication), 
       new JProperty("auth", pwAuth), 
       new JProperty("notifications", 
        new JArray(
         new JObject(
          new JProperty("send_date", "now"), 
          new JProperty("content", "test"), 
          new JProperty("wp_type", "Toast"), 
          new JProperty("wp_count", 3), 
          new JProperty("data", 
           new JObject(
            new JProperty("custom", "json data"))), 
          new JProperty("link", "http://pushwoosh.com/"), 
          new JProperty("conditions", 
           new JArray(
            (object)new JArray("Color", "EQ", "black"))))))); 
      PWCall("createMessage", json); 
     } 
     private void PWCall(string action, JObject data) 
     { 
      Uri url = new Uri("https://cp.pushwoosh.com/json/1.3/" + action); 
      JObject json = new JObject(new JProperty("request", data)); 
      DoPostRequest(url, json); 
     } 
     private void DoPostRequest(Uri url, JObject data) 
     { 
      HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); 
      req.ContentType = "text/json"; 
      req.Method = "POST"; 
      using (var streamWriter = new StreamWriter(req.GetRequestStream())) 
      { 
       streamWriter.Write(data.ToString()); 
      } 
      HttpWebResponse httpResponse; 
      try 
      { 
       httpResponse = (HttpWebResponse)req.GetResponse(); 
      } 
      catch (Exception exc) 
      { 
       throw new Exception(string.Format("Problem with {0}, {1}", url, exc.Message)); 
      } 
      using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) 
      { 
       var responseText = streamReader.ReadToEnd(); 
       Page.Response.Write(responseText); 
      } 
     } 
    } 
} 
找到例子