golang實現ios推送

來源:互聯網
上載者:User

標籤:

產生pem檔案

開啟Keychain Access 匯出推送認證和私密金鑰

推送認證 cert.p12

私密金鑰 key.p12

匯出.pem檔案

轉換推送認證

openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12

轉換私密金鑰

openssl pkcs12 -nocerts -out key.pem -in key.p12  #輸入2次密碼,後面golang代碼中密碼部分相同

合并推送認證和私密金鑰

cat cert.pem key.pem > push_ck.pem

測試產生的pem

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert cert.pem -key key.pem

輸出大體如下說明成功

  

使用golang的推送庫 ap

package mainimport ("log"apns "github.com/sideshow/apns2""github.com/sideshow/apns2/certificate")func main() {cert, pemErr := certificate.FromPemFile("push_ck.pem", "密碼")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()        //開發環境res, err := client.Development().Push(notification)if err != nil {log.Println("Error:", err)return}log.Println("APNs ID:", res.ApnsID)}

  

  

 

golang實現ios推送

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.