从Go appengine网站发送Apple推送通知

Jes*_*der 17 google-app-engine go push-notification ios

我正在尝试从Go appengine网站发送Apple推送通知.我正在使用apns2库如下:

cert, err := certificate.FromPemFile(pemFile, "")
if err != nil {
    log.Fatalf("cert error: %v", err)
}
client := apns2.NewClient(cert).Development()
n := &apns2.Notification{...}
if res, err := client.Push(n); err != nil { ... }
Run Code Online (Sandbox Code Playgroud)

在本地开发服务器上,它工作正常; 但在生产中我看到:

Post https://api.development.push.apple.com/3/device/995aa87050518ca346f7254f3484d7d5c731ee93c35e3c359db9ddf95d035003:
dial tcp: lookup api.development.push.apple.com on [::1]:53: dial udp [::1]:53: socket: operation not permitted
Run Code Online (Sandbox Code Playgroud)

看起来像appengine希望你在发送出站请求时使用自己的urlfetch库,所以我尝试设置底层HTTPClient使用它:

client.HTTPClient = urlfetch.Client(ctx)
Run Code Online (Sandbox Code Playgroud)

但是,现在Apple服务器的响应

@@?HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: 504f5354202f332f6465766963652f393935616138373035
Run Code Online (Sandbox Code Playgroud)

我认为问题是Apple推送通知需要HTTP/2,但urlfetch只实现HTTP/1.1.

我该如何解决这个问题?有没有办法让appengine应用程序发送HTTP/2请求?

Meh*_*kar -1

我对 go appengine 不太了解,但无论从代码看起来如何,你的client := apns2.NewClient(cert).Development()行似乎有缺陷,我认为对于生产,你不需要开发证书,你需要有分发证书。因此,请检查是否有可用的选项。另外,来自苹果开发站点的证书是由您还是由 go appengine 生成的。如果您手动创建了该证书,那么您必须创建两种类型的证书,一种用于开发,一种用于分发/生产,并且当应用程序在生产模式下运行时,您需要使用该证书。