. NET platform with third-party push service in push Android,ios messages (Aurora push _V3 version) latest

Source: Internet
Author: User
Tags http post

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.