|
@@ -10,10 +10,10 @@ import ( |
|
|
"github.com/tidwall/gjson" |
|
|
"github.com/tidwall/gjson" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func Send(appKey, appSecret string, param md.PushParam) (string, error) { |
|
|
|
|
|
|
|
|
func Send(appKey, appSecret string, param md.PushParam) (string, string, error) { |
|
|
|
|
|
|
|
|
if appKey == "" || appSecret == "" { |
|
|
if appKey == "" || appSecret == "" { |
|
|
return "", 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} |
|
@@ -55,16 +55,16 @@ func Send(appKey, appSecret string, param md.PushParam) (string, error) { |
|
|
} |
|
|
} |
|
|
b, err := json.Marshal(req) |
|
|
b, err := json.Marshal(req) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return "", 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 "", err |
|
|
|
|
|
|
|
|
return "", "", err |
|
|
} |
|
|
} |
|
|
fmt.Println(string(res)) |
|
|
fmt.Println(string(res)) |
|
|
msgId := gjson.Get(string(res), "msg_id").String() |
|
|
msgId := gjson.Get(string(res), "msg_id").String() |
|
|
if msgId == "0" || msgId == "" { |
|
|
if msgId == "0" || msgId == "" { |
|
|
return "", err |
|
|
|
|
|
|
|
|
return "", string(res), err |
|
|
} |
|
|
} |
|
|
return msgId, nil |
|
|
|
|
|
|
|
|
return msgId, string(res), nil |
|
|
} |
|
|
} |