结构体如下:
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"
}
之后就是请求微信小程序api地址拉!
有疑问加站长微信联系(非本文作者)