Golang implementing iOS Push

Source: Internet
Author: User

Generate PEM File

Open Keychain Access Export a push certificate and private key

Push Certificate CERT.P12

Private key KEY.P12

Export A. Pem file

Convert a push certificate

OpenSSL pkcs12-clcerts-nokeys-out cert.pem-in CERT.P12

Convert private key

OpenSSL pkcs12-nocerts-out key.pem-in key.p12  #输入2次密码, followed by the same password section in Golang code

Merging push certificates and private keys

Cat Cert.pem Key.pem > Push_ck.pem

Test the generated PEM

OpenSSL s_client-connect Gateway.sandbox.push.apple.com:2195-cert Cert.pem-key Key.pem

The output is broadly described as successful

  

Push Library APS using Golang

Package Mainimport ("Log" APNs "Github.com/sideshow/apns2" "Github.com/sideshow/apns2/certificate") func main () {cert, Pemerr: = certificate. Frompemfile ("Push_ck.pem", "password") if Pemerr! = Nil {log. Println ("Cert Error:", pemerr)}notification: = &apns. Notification{}notification. Devicetoken = "6970FC6ECDDA0FA32F48E920B4657149F394EB2C3F03B7517F11F450A8BA2B41" notification. Topic = "Com.yghc.property" notification. Payload = []byte (' {  "" APs ": {" alert ":" Hello! "  }} ') Client: = APNs. Newclient (CERT). Production ()        //Development environment res, ERR: = client. Development (). Push (notification) if err! = Nil {log. Println ("Error:", err) Return}log. Println ("APNs ID:", Res.) APNSID)}

  

  

Golang implementing iOS Push

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.