springboot與微信開發(二)

2021-08-30 10:58:00 字數 2603 閱讀 3958

上一節講述了配置介面,這次看一下關注、接收和傳送訊息。

我們先看效果圖

在上一次的controller裡面加上:

}model裡面則為:

public class basemessage 

public string gettousername()

public void settousername(string tousername)

public string getfromusername()

public void setfromusername(string fromusername)

public long getcreatetime()

public void setcreatetime(long createtime)

public string getmsgtype()

public void setmsgtype(string msgtype)

}

另外乙個model:

package com.xbjs.wechat.model;

public class messagetext extends basemessage

public messagetext(string tousername, string fromusername,

long createtime, string msgtype, string content, string msgid)

public string getcontent()

public void setcontent(string content)

public string getmsgid()

public void setmsgid(string msgid)

}

/**

* @author zxc

* @title: messageutil

* @projectname wechat

* @description: 處理訊息

* @date 2018/10/295:10 pm

*/public class messageutil

} catch (ioexception e) catch (documentexception e) finally catch (ioexception e)

}return map;

}/**

* 將傳送訊息封裝成對應的xml格式

*/public static string messagetoxml(messagetext message)

/*** 封裝傳送訊息物件,封裝時,需要將調換傳送者和接收者的關係

** @param fromusername

* @param tousername

*/public static string initmessage(string fromusername, string tousername)

/*** 封裝傳送訊息物件,封裝時,需要將調換傳送者和接收者的關係

** @param fromusername

* @param tousername

*/public static string subscribemessage(string fromusername, string tousername)

/*** 封裝傳送訊息物件,封裝時,需要將調換傳送者和接收者的關係

** @param fromusername

* @param tousername

* @param content

*/public static string reversalmessage(string fromusername, string tousername, string content)

}

這裡先將收到的訊息轉為了map,使用

dom4j

dom4j

接收訊息

1248861860

789456126411

傳送訊息

816451315

訊息體轉xml用到:

com.thoughtworks.xstream

xstream

1.4.11.1

上一節

微信開發 微信傳送訊息

2,下面說資訊傳送,模擬了單使用者資訊傳送和多使用者訊息批量傳送 1 基礎方法,http方法 http get post 公用方法 請求鏈結 請求引數值 如果是get方式此處為 值,預設為 請求方式 post or get public static string request this stri...

微信開發 微信授權詳解

1關www.cppcns.com於微信授權這塊的流程圖,如下 一些 碎片僅供參考 var mynickname var myheadimgurl var activityid function s edata obj.openid myopenid obj.nickname mynickname 微...

微信開發 二 微信選單建立

在下面的介面除錯中可以立即看到建立的選單。特別需要注意的是選單的url裡面一定不能包含空格不然選單會一直建立不成功,本人就是因為這個問題花了半天的時間。下面附上建立選單的 public static void createmenu string type throws unsupportedenco...