博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
golang实现ios推送
阅读量:7104 次
发布时间:2019-06-28

本文共 1127 字,大约阅读时间需要 3 分钟。

生成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的推送库

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)}

  

  

 

转载于:https://www.cnblogs.com/warrior/p/5886272.html

你可能感兴趣的文章
js 遇到 Permission denied to access property ***
查看>>
杭电1509--Windows Message Queue(优先队列)
查看>>
C#中文转换成拼音
查看>>
C语言程序设计实验第四次作业
查看>>
【转】C#自定义异常类简介
查看>>
hadoop(5)---yarn配置 --常用配置
查看>>
提高博客浏览量的几个小技巧
查看>>
模板Template
查看>>
ios-网络request请求
查看>>
多线程 线程间通信 wait,notify
查看>>
Linux中断(interrupt)子系统之一:中断系统基本原理【转】
查看>>
selenium 页面元素的内置属性
查看>>
ubuntu16.04 离线安装nginx
查看>>
Block、委托、回调函数原理剖析(在Object C语境)——这样讲还不懂,根本不可能!...
查看>>
ubuntu/debian/linux彻底卸载mysql
查看>>
debian彻底清理MYSQL
查看>>
内核编译出错解决
查看>>
SOA会不会造成IT黑洞
查看>>
添加用户到LDAP服务器
查看>>
Application、Session和Cookie
查看>>