176 lines
8.9 KiB
Go
176 lines
8.9 KiB
Go
package apns2
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"go-common/app/service/main/push/model"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
var (
|
|
k = []byte(`-----BEGIN RSA PRIVATE KEY-----
|
|
MIIEpAIBAAKCAQEA3ZDI9NUPfMH0/6DgmeCH/Zl8g3pOlLcMY0p6m8lMe9EDF1vZ
|
|
w3uR05YzbQCmYCwWZLKDTq/0d3RMRow8AON1wMv9ynyk7Z1Pb9C+ByN4GCWsRHjN
|
|
BbEg8jgBYeOoM6PlpDc16D8uPKukRuaq/j1beOn1HD4vnS8KqUzeS6fYbaiPjC7h
|
|
7QZOnNE5NwV6TKPMu/+0aNPNgZDeFtNwcXiiRX6OPfbOOnVr0/6WGorYdGMPLxeZ
|
|
viqZ37z7rDhup/LaiDedO/tm09lmKUbFOHS+qbSYPXztDHhOwTm36E1k2mD5Lq1S
|
|
d5zHRrwzgPTvieFQ+giA9u8pn2wBNDASBDF1pQIDAQABAoIBAQDdNQtdXUa8IQ1R
|
|
FraHCuPa7p2gysCfu22TyC1HUh+ZUqEKdjqg78M1AzXOsyJozDuDR7LPId8qUCND
|
|
IAlcPbw3w7Jbsjwbu74ufbLrf58MRLiMGCthbmndSsseh2NMQ2snm7Onb0Tjb95w
|
|
pyW69VlZDAQasX9qKCg1xTf/QtFTEGbJpkfN7lYYjwwhLFck39SUH254cwmqV8Tj
|
|
AQ9Uj6dQhYvWseSGtsbqkyj0/sUwyzfaUWeNjnYUaVQWxAalnLYiUCzRLR0IMwvM
|
|
cmscwYWrWlPPd8ND4yGyHXqeQH2fVJqEx/aIDSpujNeOm2MH0RFRNBU53d/tJpj8
|
|
XuqE8Yj1AoGBAO5klAY8vScnC3RQ8x3tlJkM3jkD3FmqSJu7erId0T6KgJz0Xmgj
|
|
zHYwvq+V4t0Kmk1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) {
|
|
// unuserd
|
|
_ = hdc
|
|
_ = hdk
|
|
|
|
Convey("test apns", t, func() {
|
|
cert, err := tls.X509KeyPair(c, k)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
apnsClient := NewClient(cert, 10*time.Second).Production()
|
|
aps := Aps{
|
|
Alert: Alert{
|
|
Title: "test",
|
|
Body: "test",
|
|
},
|
|
Badge: 0,
|
|
// Sound: "default", 不加sound没有提醒
|
|
MutableContent: 1,
|
|
}
|
|
var token string
|
|
// token = "140b5f62b3db93bc6a072645d3825c50efa5693f733690542fffa034252c7495"
|
|
scheme := model.Scheme(model.LinkTypeLive, "123", model.PlatformIPhone, 529000)
|
|
payload := &Payload{Aps: aps, URL: scheme, TaskID: "3c9e1eaca2afd373_search_1473317045", Token: token, Image: "https://pic.qiantucdn.com/58pic/12/38/18/13758PIC4GV.jpg"}
|
|
bs, _ := json.Marshal(payload)
|
|
fmt.Printf("payload(%s)", bs)
|
|
apnsClient.BoundID = "tv.danmaku.bilianime"
|
|
resp, err := apnsClient.Push(token, payload, time.Now().Unix())
|
|
So(err, ShouldBeNil)
|
|
fmt.Println("StatusCode:", resp.StatusCode, "ApnsID:", resp.ApnsID, "Reason:", resp.Reason)
|
|
})
|
|
}
|