zhangjinkun 7 лет назад
Родитель
Сommit
e9a2c6d24f
2 измененных файлов с 26 добавлено и 25 удалено
  1. 2 2
      golang/src/jgpush.json
  2. 24 23
      golang/src/jgpush/jgpush.go

+ 2 - 2
golang/src/jgpush.json

@@ -2,8 +2,8 @@
     "pushurl": "https://bjapi.push.jiguang.cn/v3/push",
     "appid": "5efa1257867cf5d77d007ce6",
     "appSecret": "d7a4e79978cd73cd61a5c7f7",
-    "titlelen": 20,
-    "alter": {
+    "alertlen": 20,
+    "title": {
         "bid": "剑鱼推送消息,最新的订阅内容",
         "project": "剑鱼推送消息,我关注的项目",
         "entname": "剑鱼推送消息,我关注的企业",

+ 24 - 23
golang/src/jgpush/jgpush.go

@@ -17,9 +17,9 @@ import (
 
 type jgconfig struct {
 	Pushurl, Appid, AppSecret string
-	Alter                     map[string]interface{}
+	Title                     map[string]interface{}
 	Config                    config
-	Titlelen                  int
+	Alertlen                  int
 }
 type config struct {
 	Platform     string
@@ -43,20 +43,21 @@ func init() {
 
 /**
 *通知推送
-alert:通知栏,空默认配置
-title:通知标题,空默认配置
+alert:通知内容
+title:通知标题
 infotype:推送信息类型(bid,project,entname)
 ids:极光id组
 extras:自定义字段
 broadcast:是否广播,广播ids作废
 */
-func JgpushNc(title, infotype string, ids []string, extras map[string]interface{}, isbroadcast bool) {
+func JgpushNc(alter, infotype string, ids []string, extras map[string]interface{}, isbroadcast bool) {
 	temp := &Jgconfig.Config
 	temp.Audience["registration_id"] = ids
 	android := temp.Notification["android"]
 	if tmp, ok := android.(map[string]interface{}); ok {
-		tmp["alert"] = Jgconfig.Alter[infotype]
-		tmp["title"] = shorTitle(title, Jgconfig.Titlelen)
+		tmp["title"] = Jgconfig.Title[infotype]
+		tmp["alert"] = shorAlert(alter, Jgconfig.Alertlen)
+		//extras["descript"] = tmp["alter"]
 		tmp["extras"] = map[string]interface{}{
 			"type": infotype,
 			"info": extras,
@@ -64,7 +65,7 @@ func JgpushNc(title, infotype string, ids []string, extras map[string]interface{
 	}
 	ios := temp.Notification["ios"]
 	if tmp, ok := ios.(map[string]interface{}); ok {
-		tmp["alert"] = Jgconfig.Alter[infotype]
+		tmp["alert"] = shorAlert(alter, Jgconfig.Alertlen)
 		tmp["extras"] = map[string]interface{}{
 			"type": infotype,
 			"info": extras,
@@ -91,13 +92,13 @@ func JgpushNc(title, infotype string, ids []string, extras map[string]interface{
 }
 
 //直接推送,非队列
-func JgpushD_Nc(title, infotype string, ids []string, extras map[string]interface{}, isbroadcast bool) map[string]interface{} {
+func JgpushD_Nc(alert, infotype string, ids []string, extras map[string]interface{}, isbroadcast bool) map[string]interface{} {
 	temp := &Jgconfig.Config
 	temp.Audience["registration_id"] = ids
 	android := temp.Notification["android"]
 	if tmp, ok := android.(map[string]interface{}); ok {
-		tmp["alert"] = Jgconfig.Alter[infotype]
-		tmp["title"] = shorTitle(title, Jgconfig.Titlelen)
+		tmp["title"] = Jgconfig.Title[infotype]
+		tmp["alert"] = shorAlert(alert, Jgconfig.Alertlen)
 		tmp["extras"] = map[string]interface{}{
 			"type": infotype,
 			"info": extras,
@@ -105,7 +106,7 @@ func JgpushD_Nc(title, infotype string, ids []string, extras map[string]interfac
 	}
 	ios := temp.Notification["ios"]
 	if tmp, ok := ios.(map[string]interface{}); ok {
-		tmp["alert"] = Jgconfig.Alter[infotype]
+		tmp["alert"] = shorAlert(alert, Jgconfig.Alertlen)
 		tmp["extras"] = map[string]interface{}{
 			"type": infotype,
 			"info": extras,
@@ -139,7 +140,7 @@ func JgpushMsg(msg_title, msg_con, msg_type string, ids []string, extras map[str
 	message := temp.Message
 	message["msg_content"] = msg_con
 	message["content_type"] = msg_type
-	message["title"] = shorTitle(msg_title, Jgconfig.Titlelen)
+	message["title"] = msg_title
 	message["extras"] = extras
 
 	sendcon := map[string]interface{}{
@@ -168,7 +169,7 @@ func JgpushD_Msg(msg_title, msg_con, msg_type string, ids []string, extras map[s
 	message := temp.Message
 	message["msg_content"] = msg_con
 	message["content_type"] = msg_type
-	message["title"] = shorTitle(msg_title, Jgconfig.Titlelen)
+	message["title"] = msg_title
 	message["extras"] = extras
 
 	sendcon := map[string]interface{}{
@@ -207,13 +208,13 @@ func pushD(data map[string]interface{}) map[string]interface{} {
 }
 
 //通知、消息推送、广播
-func JgpushNcAndMsg(title, infotype string, msg_title, msg_con, msg_type string, ids []string, extras, msg_extras map[string]interface{}, isbroadcast bool) {
+func JgpushNcAndMsg(alert, infotype string, msg_title, msg_con, msg_type string, ids []string, extras, msg_extras map[string]interface{}, isbroadcast bool) {
 	temp := Jgconfig.Config
 	temp.Audience["registration_id"] = ids
 	android := temp.Notification["android"]
 	if tmp, ok := android.(map[string]interface{}); ok {
-		tmp["alert"] = Jgconfig.Alter[infotype]
-		tmp["title"] = shorTitle(title, Jgconfig.Titlelen)
+		tmp["title"] = Jgconfig.Title[infotype]
+		tmp["alert"] = shorAlert(alert, Jgconfig.Alertlen)
 		tmp["extras"] = map[string]interface{}{
 			"type": infotype,
 			"info": extras,
@@ -221,7 +222,7 @@ func JgpushNcAndMsg(title, infotype string, msg_title, msg_con, msg_type string,
 	}
 	ios := temp.Notification["ios"]
 	if tmp, ok := ios.(map[string]interface{}); ok {
-		tmp["alert"] = Jgconfig.Alter[infotype]
+		tmp["alert"] = shorAlert(alert, Jgconfig.Alertlen)
 		tmp["extras"] = map[string]interface{}{
 			"type": infotype,
 			"info": extras,
@@ -231,7 +232,7 @@ func JgpushNcAndMsg(title, infotype string, msg_title, msg_con, msg_type string,
 	message := temp.Message
 	message["msg_content"] = msg_con
 	message["content_type"] = msg_type
-	message["title"] = shorTitle(msg_title, Jgconfig.Titlelen)
+	message["title"] = msg_title
 	message["extras"] = extras
 
 	sendcon := map[string]interface{}{
@@ -290,12 +291,12 @@ func JPush() {
 	time.AfterFunc(30*time.Second, JPush)
 }
 
-func shorTitle(title string, l int) string {
-	lg := len([]rune(title))
+func shorAlert(alert string, l int) string {
+	lg := len([]rune(alert))
 	if lg > l {
-		return string([]rune(title)[:l])
+		return string([]rune(alert)[:l])
 	} else {
-		return title
+		return alert
 	}
 }