如何使用golang签署manifest.json for safari推送通知?

时间:2014-06-29 03:24:52

标签: go push-notification apple-push-notifications safari-push-notifications

签署用于safari推送通知包的manifest.json文件的正确方法是什么?

func servePushPackage() func(w http.ResponseWriter, r *http.Request) {
    return func(w http.ResponseWriter, r *http.Request) {
        body, _ := ioutil.ReadAll(r.Body)
        fmt.Printf("servePushPackage() %s %s %s %s %v\n", r.Method, r.RequestURI, r.RemoteAddr, body, r.FormValue)

        buf := new(bytes.Buffer)

        // Create a new zip archive.
        z := zip.NewWriter(buf)

        // Build the website.json file
        websiteJson :=
`{
    "websiteName": "Test",
    "websitePushID": "web.example.test",
    "allowedDomains": ["https://example.com"],
    "urlFormatString": "https://example.com/%@",
    "authenticationToken": "19f8d7a6e9fb8a7f6d9330dabe",
    "webServiceURL": "https://example.com"
}`

        // Build the manifest.json
        manifestJson := "{"

        // Add the icon files to the archive and to the manifest
        .... snip ....

        // Complete the manifest
        manifestJson = fmt.Sprintf("%s\n\t\"website.json\":\"%x\"\n}", manifestJson, sha1.Sum([]byte(websiteJson)) )

        addFileToArchive(z, "website.json", []byte([]byte(websiteJson)))
        addFileToArchive(z, "manifest.json", []byte([]byte(manifestJson)))
        addFileToArchive(z, "signature", []byte([]byte("test test test")))

        // Make sure to check the error on Close.
        err := z.Close()
        if err != nil {
            panic(err)
        }

        // Successfully built the push package
        w.Header().Set("Content-type", "application/zip")
        w.Write(buf.Bytes())
    }
}

请注意,这一切都正常,唯一的问题是safari报告以下内容:

{"logs":["Signature verification of push package failed"]}

apple documentation indicates这是PHP的内置功能,但没有这样的运气在go中找到一个等价物:

  

在PHP中,您可以使用openssl_pkcs7_sign函数...

执行此操作

0 个答案:

没有答案