Golang对ios推送

  • 推送证书制作
  1. 打开证书助理

  2. 导出 推送debug/release 证书为 p12

  3. 点开该证书箭头 导出私钥 为 p12

//生成推送证书pem

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

//生成私钥的pem

  1. openssl pkcs12 -nocerts -out key.pem -in key.p12
  • 先输入key.p12的密码

  • 输入生成的key.pem的密码

  • 重复输入密码

//去掉key.pem的密码

  1. openssl rsa -in key.pem -out key.unencrypted.pem -passin pass:123456

  2. cert.pem 和 key.unencrypted.pem放入项目


 cert, pemErr = tls.LoadX509KeyPair("cert.pem", "key.unencrypted.pem")

 client = apns.NewClient(cert).Development()

notification := &apns.Notification{}

notification.DeviceToken = msg.DeviceToken

notification.Topic = msg.TopicName

notification.Payload = []byte(fmt.Sprintf(`

{

"aps" : {

"content-available": 1,

"alert" : {

"title" : "%s",

"subtitle" : "",

"body" : "%s"

},

"badge" : 1,

"sound" : "default"

},

"body" : "%s"

  }`, msg.Title, msg.Body, m))

client.Push()



你可能感兴趣的:(Golang对ios推送)