Recently I saw the V2 version to be deactivated from the Aurora push official online and had to re-write the V3 version. HTTP Basic authentication is used here.
Http://www.cnblogs.com/pingming/p/4165057.html
1. first, you need to register your app on the Aurora official website, get a apikey, a apimastersecret (password), and save both values in the configuration file (app/ Web. config), what needs to be done by the specific mobile phone developer our. NET platform regardless
< appsettings > < add key = "ApiKey" = "**********" /> < add key = "Apimastersecret" Span style= "color: #ff0000;" > value = "*******" /> </ appsettings >
2. read the values in the configuration
Private ReadOnly stringApiKey ="";Private ReadOnly stringApimastersecret =""; ApiKey= configurationmanager.appsettings["ApiKey"]. ToString ();//Android ApiKeyApimastersecret = configurationmanager.appsettings["Apimastersecret"]. ToString ();//Android Password
3. Start Push Method
/// <summary> ///Aurora Push V3 version/// </summary> /// <param name= "content" ></param> Public stringPushV3 (stringcontent) { stringApp_key =ApiKey; stringMastersecret =Apimastersecret; stringU_ = App_key +":"+ Mastersecret;//corresponding push-u stringbase64_ = EncodeBase64 (u_);//Code u_ stringPostData =""; PostData+="{"; PostData+="\ "platform\": \ "All\","; PostData+="\ "audience\": \ "All\""; PostData+=","; PostData+="\ "notification\": {"; PostData+="\ "android\": {"; PostData+="\ "alert\": \ ""+ content +"\","; PostData+="\ "title\": \ "Send to android\","; PostData+="\ "builder_id\": 1,"; PostData+="\ "Extras\": {\ "newsid\": 321}"; PostData+="}, "; PostData+="\ "Ios\": {"; PostData+="\ "alert\": \ ""+ content +"\","; PostData+="\ "sound\": \ "Default\","; PostData+="\ "badge\": \ "+1\","; PostData+="\ "Extras\": {\ "newsid\": 321}"; PostData+="}"; PostData+="},"; PostData+="\ "Options\": {"; PostData+="\ "time_to_live\": 60,\ "apns_production\": false"; PostData+="}"; PostData+="}"; byte[] data =Encoding.UTF8.GetBytes (postdata); //access authorization using HTTP Basic authentication
//http Post method to invoke Aurora's push service
Uri URL =NewUri ("Https://api.jpush.cn/v3/push"); CredentialCache Mycache=NewCredentialCache (); Mycache. Add (URL,"Basic",NewNetworkCredential (App_key, Mastersecret)); HttpWebRequest Myrequest= (HttpWebRequest) webrequest.create (URL);//Myrequest.method="POST";//Aurora HTTP Request mode is postMyrequest.contenttype ="Application/json";////According to Aurora requirementsMyrequest.contentlength =data. Length; Myrequest.credentials=Mycache; Myrequest.keepalive=true; MYREQUEST.HEADERS.ADD ("Authorization","Basic"+BASE64_);//HTTP Header AdditionsStream newstream =Myrequest.getrequeststream (); //Send the data.Newstream.write (data,0, data. Length); Newstream.close (); //Get Response varResponse =(HttpWebResponse) myrequest.getresponse (); stringstacode= Response. Statuscode.tostring ();//Return Status code: OK using(varReader =NewStreamReader (response. GetResponseStream (), Encoding.GetEncoding ("UTF-8"))) { stringresult =Reader. ReadToEnd (); Reader. Close (); Response. Close (); returnStacode; } }
. NET platform with third-party push service in push Android,ios messages (Aurora push _V3 version) latest