小程序模板網(wǎng)

golang+json-iterator(微信小程序推送通知實(shí)例)

發(fā)布時(shí)間:2018-09-11 15:48 所屬欄目:小程序開(kāi)發(fā)教程

結(jié)構(gòu)體如下:

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"`
}
實(shí)際代碼如下:

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: "熱點(diǎn)新聞"},
      Keyword2:models.WxKeyword{Value: news.Title},
      Keyword3:models.WxKeyword{Value: tt[0].Summary},
    },
    Emphasis_keyword: "keyword1.DATA"})
  }
  log.Println("小程序-加密前的參數(shù): ", string(jsonWxPushContent))

返回結(jié)果:

{
    "push_record_id":33,
    "template_id":"3OviTbpRI-7t8GJxlaoKtyQM6SuOXnROVk-jwj-T-GI",
    "page":"/pages/detail?isShare=true&isFromPush=33&id=63688",
    "data":{
        "keyword1":{
            "value":"熱點(diǎn)新聞"
        },
        "keyword2":{
            "value":"人工智能是否會(huì)顛覆傳統(tǒng)電視行業(yè)?"
        },
        "keyword3":{
            "value":"據(jù)了解,近日長(zhǎng)虹再次與人工智能領(lǐng)先企業(yè)達(dá)觀數(shù)據(jù)達(dá)成合作,將電視內(nèi)容的個(gè)性化推薦引入智能電視,為用戶(hù)更好的打造智慧家庭體系"
        }
    }
    "emphasis_keyword":"keyword1.DATA"
}


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://22321a.com/wxmini/doc/course/24794.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢(xún):800182392 點(diǎn)擊咨詢(xún)
QQ在線(xiàn)咨詢(xún)