|
@@ -7,12 +7,13 @@ import ( |
|
|
"errors" |
|
|
"errors" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"github.com/syyongx/php2go" |
|
|
"github.com/syyongx/php2go" |
|
|
|
|
|
"github.com/tidwall/gjson" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func Send(appKey, appSecret string, param md.PushParam) (interface{}, error) { |
|
|
|
|
|
|
|
|
func Send(appKey, appSecret string, param md.PushParam) (string, error) { |
|
|
|
|
|
|
|
|
if appKey == "" || appSecret == "" { |
|
|
if appKey == "" || appSecret == "" { |
|
|
return nil, errors.New("配置未设置") |
|
|
|
|
|
|
|
|
return "", errors.New("配置未设置") |
|
|
} |
|
|
} |
|
|
url := "https://api.jpush.cn/v3/push" |
|
|
url := "https://api.jpush.cn/v3/push" |
|
|
var iosAlert = md.PushIosAlert{Title: param.Title, Body: param.Content} |
|
|
var iosAlert = md.PushIosAlert{Title: param.Title, Body: param.Content} |
|
@@ -54,12 +55,16 @@ func Send(appKey, appSecret string, param md.PushParam) (interface{}, error) { |
|
|
} |
|
|
} |
|
|
b, err := json.Marshal(req) |
|
|
b, err := json.Marshal(req) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
|
|
|
|
|
|
return "", err |
|
|
} |
|
|
} |
|
|
res, err := jg_push_utils.CurlPost(url, b, headers) |
|
|
res, err := jg_push_utils.CurlPost(url, b, headers) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
|
|
|
|
|
|
return "", err |
|
|
} |
|
|
} |
|
|
fmt.Println(res) |
|
|
|
|
|
return res, nil |
|
|
|
|
|
|
|
|
fmt.Println(string(res)) |
|
|
|
|
|
msgId := gjson.Get(string(res), "msg_id").String() |
|
|
|
|
|
if msgId == "0" || msgId == "" { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
return msgId, nil |
|
|
} |
|
|
} |