123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package main
- import (
- "encoding/base64"
- "fmt"
- "io/ioutil"
- "net/http"
- "strings"
- )
- const (
- push_url = "https://bjapi.push.jiguang.cn/v3/push"
- appid = "5efa1257867cf5d77d007ce6"
- appSecret = "d7a4e79978cd73cd61a5c7f7"
- )
- //
- func main() {
- bodystr := `{
- "platform": "all",
- "audience": {
- "registration_id": [
- "140fe1da9ea179bd470"
- ]
- },
- "notification": {
- "android": {
- "alert": "剑鱼推送消息,最新的订阅内容",
- "title": "剑鱼招标订阅",
- "builder_id": 1,
- "extras": {
- "newsid": 321
- }
- },
- "ios": {
- "alert": "推送消息",
- "sound": "default",
- "badge": "+1",
- "extras": {
- "newsid": 321
- }
- }
- },
- "message": {
- "msg_content": "Hi,JPush",
- "content_type": "text",
- "title": "msg",
- "extras": {
- "key": "value"
- }
- },
- "options": {
- "time_to_live": 60,
- "apns_production": false,
- "apns_collapse_id":"jiguang_test_201706011100"
- }
- }`
- req, _ := http.NewRequest("POST", push_url, strings.NewReader(bodystr))
- req.Header.Add("Content-Type", "application/json")
- req.Header.Add("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(appid+":"+appSecret)))
- resp, err := http.DefaultClient.Do(req)
- if err != nil {
- fmt.Println(err.Error())
- } else {
- bs, _ := ioutil.ReadAll(resp.Body)
- resp.Body.Close()
- fmt.Println(string(bs))
- }
- }
|