激情久久久_欧美视频区_成人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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 午夜久久久精品一区二区三区 | 毛片毛片免费看 | 亚洲第一成人在线视频 | 久久夜色精品 | 88xx成人精品视频 | 亚洲视频精品在线 | 久久99国产伦子精品免费 | 在线成人一区 | 1024亚洲天堂 | 亚洲精品久久久久久久久久 | 国产羞羞视频在线观看 | 深夜福利视频绿巨人视频在线观看 | 一级空姐毛片 | 日本精品久久久一区二区三区 | 爱性久久久久久久 | h色在线观看 | 黄视频免费在线观看 | 久综合 | 欧美日韩在线播放 | 色视频在线播放 | 日韩视频中文 | 国产超碰人人做人人爱 | 宅男噜噜噜66国产免费观看 | 国产成人在线播放视频 | 多人乱大交xxxxx变态 | 欧美视频国产精品 | 黄色成人小视频 | 黄色片在线免费播放 | 港台三级在线观看 | 免费在线观看成年人视频 | 黄色大片网站在线观看 | 国产一区二区三区视频在线 | 国产精品一区二区x88av | 特片网久久 | 91羞羞 | 国产免费一区二区三区网站免费 | 香蕉成人在线视频 | 欧美 日韩 亚洲 中文 | 免费看成年人网站 | 国产一级一国产一级毛片 | 特级黄一级播放 |