国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - java微信公眾號發送消息模板

java微信公眾號發送消息模板

2021-05-26 13:02堆棧 Java教程

這篇文章主要為大家詳細介紹了java微信公眾號發送消息模板,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java微信公眾號發送消息模板的具體代碼,供大家參考,具體內容如下

這段時間接觸公眾號開發,寫下向用戶發送消息模板的接口調用

先上接口代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public static jsonobject sendmodelmessage(servletcontext context,jsonobject jsonmsg) {
    system.out.println("消息內容:"+jsonmsg);
    boolean result = false;
    try {
      getwx_accesstoken(context);
    } catch (exception e) {
      // todo auto-generated catch block
      e.printstacktrace();
    }
    // 拼接請求地址
    string requesturl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=access_token";
    requesturl = requesturl.replace("access_token", context.getattribute(contexttokenname).tostring());
    // 發送客服消息
    jsonobject jsonobject = getjsonbywx(requesturl, context, "post",jsonmsg, false);
 
    if (null != jsonobject) {
      int errorcode = jsonobject.getint("errcode");
      string errormsg = jsonobject.getstring("errmsg");
      if (0 == errorcode) {
        result = true;
        system.out.println("模板消息發送成功 errcode:{} "+errorcode+"----"+errormsg);
      } else {
        system.out.println("模板消息發送失敗 errcode:{} "+errorcode+"----"+errormsg);
      }
    }
 
    return null;
  }

15行那段getjsonbywx是統一調用微信接口的方法,每個項目都有自己的調用方法,我這里就不貼了。接口調用鏈接:https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=access_token

接下來就是建個bean類,里面寫入一下顏色及值

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private string value;
  private string color;
  
  public string getvalue() {
    return value;
  }
 
  public void setvalue(string value) {
    this.value = value;
  }
 
  public string getcolor() {
    return color;
  }
 
  public void setcolor(string color) {
    this.color = color;
  
 
}

在公眾號里填寫模板消息的對應格式

java微信公眾號發送消息模板

之后就是有個觸發點,我選擇發貨后把發貨信息發送給用戶

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pagedata wechattemplate = new pagedata();
    wechattemplate.put("template_id", "填寫你的模板id");
    wechattemplate.put("touser", userinfo.get("openid"));//獲取用戶的openid
  
    map<string,templatemessageutil> mapdata = new hashmap<>();
    
    templatemessageutil first = new templatemessageutil();   
    first.setcolor("#173177");
    first.setvalue("發貨通知");
    mapdata.put("first", first);
    
    templatemessageutil text1 = new templatemessageutil(); 
    text1.setcolor("#173177");
    text1.setvalue("您好,您所購買的商品已發貨。");
    mapdata.put("text1", text1);
    
    templatemessageutil text2 = new templatemessageutil(); 
    text2.setcolor("#173177");
    text2.setvalue(expresser_name);
    mapdata.put("text2", text2);
    
    templatemessageutil text3 = new templatemessageutil(); 
    text3.setcolor("#173177");
    text3.setvalue(expresser_phone);
    mapdata.put("text3", text3);
    
    templatemessageutil remark = new templatemessageutil();   
    remark.setcolor("#173177");
    remark.setvalue("請保持電話暢通>>");
    mapdata.put("remark", remark);
 
    jsonobject json = new jsonobject();
    json.put("data",mapdata);
    json.putall(wechattemplate);//轉為json
        
    wxinterface.sendmodelmessage(context,json);

之后手機就會收到信息了

java微信公眾號發送消息模板

整體思路是這樣,也是參照百度而來,因為每個人的項目里方法都不一樣,我就不詳細貼上,既然做到發送模板消息了,統一調用微信接口的方法應每個人該也早寫在工具類里了,每個人都不同,當應該都有,調用這個方法,把微信模板消息連接的條件access_token寫進去就請求了,剩下的就是傳入你要發送的消息,消息存入集合,集合轉json才行,jsonobject類相信也都有,我也不貼了,每個人項目都不一樣,沒必要照搬過去,就照著自己原先已有的類改進。

原文鏈接:https://www.cnblogs.com/lisiping/archive/2018/08/18/9496216.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 天天澡天天狠天天天做 | 久久精品国产亚洲一区二区三区 | 99久久精品国产毛片 | 精品久久精品久久 | 欧美日韩成人在线 | 日韩免费 | 亚洲一区观看 | 中文字幕av网 | 欧美亚洲一区 | 欧洲成人午夜免费大片 | 亚洲蜜桃妇女 | 黄色av免费 | 97成人在线 | 久久人人爽人人爽人人片亚洲 | 久久久久中文字幕 | 日韩影院一区 | 欧美国产日韩精品 | 中国大陆一级毛片 | 成人午夜精品久久久久久久网站 | 日韩免费| 国产精品成人3p一区二区三区 | 成人网免费看 | 亚洲一区二区中文 | 国产亚洲精品美女久久久久久久久久 | 久久人人爽人人爽 | 午夜视频网站 | 久久99深爱久久99精品 | 欧美在线视频a | 免费视频一区二区 | 黄色av网 | www伊人 | www.久久| 日韩欧美中文字幕在线视频 | 婷婷激情五月 | 国产99久久| 日本中文字幕在线播放 | 做视频免费观看网站 | 欧美精品一区在线 | 综合二区 | 久久精品成人 | 国产精品自产拍在线观看 |