結構體如下:
type WxPushContent struct { Push_record_id int `json:"push_record_id"` Template_id string `json:"template_id"` Page string `json:"page"` Data Data `json:"data"` Emphasis_keyword string `json:"emphasis_keyword"` } type Data struct { Keyword1 WxKeyword `json:"keyword1"` Keyword2 WxKeyword `json:"keyword2"` Keyword3 WxKeyword `json:"keyword3"` } type WxKeyword struct { Value string `json:"value"` } 實際代碼如下: func ExecutePush_WX(ctx *gin.Context) { var json_iterator = jsoniter.ConfigCompatibleWithStandardLibrary jsonWxPushContent, _ := json_iterator.Marshal(models.WxPushContent{ Push_record_id: note.Id, Template_id: setting.MINITemplateId, Page: "/pages/detail?isShare=true&isFromPush=" + strconv.Itoa(note.Id) + "&id=" + strconv.FormatInt(note.NewsId, 10), Data: models.Data{ Keyword1:models.WxKeyword{Value: "熱點新聞"}, Keyword2:models.WxKeyword{Value: news.Title}, Keyword3:models.WxKeyword{Value: tt[0].Summary}, }, Emphasis_keyword: "keyword1.DATA"}) } |
log.Println("小程序-加密前的參數: ", string(jsonWxPushContent))
返回結果:
{ "push_record_id":33, "template_id":"3OviTbpRI-7t8GJxlaoKtyQM6SuOXnROVk-jwj-T-GI", "page":"/pages/detail?isShare=true&isFromPush=33&id=63688", "data":{ "keyword1":{ "value":"熱點新聞" }, "keyword2":{ "value":"人工智能是否會顛覆傳統電視行業?" }, "keyword3":{ "value":"據了解,近日長虹再次與人工智能領先企業達觀數據達成合作,將電視內容的個性化推薦引入智能電視,為用戶更好的打造智慧家庭體系" } } "emphasis_keyword":"keyword1.DATA" }