猫史档案馆


不会代码的鲨鲨

用户:一只鲨鱼吖一只鲨鱼吖查看:75 回复:7 评论:16 创建时间:2022-12-05T15:25:41


RequestMapping(value="/api",method=RequestMethod.POST)
public void initPostAPI(HttpServletRequest request, HttpServletResponse response)
{
String Event = "";
String MsgType = "";
String Content = "";
String strJson = new String();
// 将请求、响应的编码均设置为UTF-8(防止中文乱码)
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// 调用核心业务类接收消息、处理消息
User user = new User();

String respMessage = "";//反馈信息
Map<String, String> map = new HashMap<String, String>();
try {
map = parseXml(request);
} catch (Exception e) {
e.printStackTrace();
}

Event = map.get("Event");
MsgType = map.get("MsgType");
Content = map.get("Content");

System.out.println("Content = " + Content);
System.out.println("MsgType = " + MsgType);
System.out.println("Event = " + Event);
System.out.println("EventKey = " + map.get("EventKey"));
if(Event == null){//Event为null 则为用户输入信息被动回复
//自动回复用户信息
if(MsgType.equals("text")){
strJson = sendMess(map,strJson, Content);
}
}
SendUserMess.sendMess(strJson);
}

这是回复信息内容的处理(文本信息,图文信息)
public String sendMess(Map map,String strJson,String Content){

//根据用户输入的关键字查询对应响应
AutoReply autoReply = new AutoReply();
autoReply.setKeyName(Content);
List<AutoReply> list = this.replyService.findByKeyname(autoReply);
System.out.println("list size = "+list.size());

//向用户回复消息
if(list.size() != 0){
autoReply = list.get(0);
System.out.println("KeyValue-----"+autoReply.getKeyValue()+"--");

if(!autoReply.getKeyValue().equals("")){
strJson = "{\"touser\" :\""+map.get("FromUserName")+"\",";
strJson += "\"msgtype\":\"text\",";
strJson += "\"text\":{";
strJson += "\"content\":\""+autoReply.getKeyValue()+"\"";
strJson += "}}";
}else if(!autoReply.getGraphic().equals("")){
String newsinfo = "";
String[] strs = autoReply.getGraphic().split(",");
strJson = "{\"touser\" :\""+map.get("FromUserName")+"\",";
strJson += "\"msgtype\":\"news\",";
strJson += "\"news\":";
String news = "{\"articles\": [";
System.out.println(news);

for(String str:strs){
Graphic graphic = graphicService.loadByPK(Integer.valueOf(str));
String url = graphic.getPicurl();
//url = saveUrl + url.substring(24);

newsinfo += "{\"title\":\""+graphic.getTitle()+"\"," +
"\"description\":\""+graphic.getDescription()+"\",\"url\":\""+graphic.getUrl()+"\"," +
"\"picurl\":\""+url+"\""+
"},";
}

news = news + newsinfo.substring(0, (newsinfo.length()-1));
news = news + "]}";
strJson += news;
strJson += "}";
System.out.println("news-------"+news);
}
}else{//如果在数据库中找不到对应回复用户的信息则回复默认消息
autoReply.setKeyName("未知");
List<AutoReply> list_ = this.replyService.findByKeyname(autoReply);
autoReply = list_.get(0);

/*StringBuffer content = new StringBuffer();
content.append("感谢您!").append("\n");
content.append("再次感谢您").append("\n");
content.append("再次再次感谢您");*/
//拼装需要发送的消息
strJson = "{\"touser\" :\""+map.get("FromUserName")+"\",";
strJson += "\"msgtype\":\"text\",";
strJson += "\"text\":{";
strJson += "\"content\":\""+autoReply.getKeyValue()+"\"";
strJson += "}}";
}
————————————————
版权声明;是鲨鱼吖


回复

上一页第 1 页 / 共 1 页下一页
一只鲨鱼吖一只鲨鱼吖

可以看看,我不太会,请指教

点赞0


评论


一只鲨鱼吖一只鲨鱼吖

沙发

点赞0


评论

抢沙发

二二二

你干嘛

抢回来

不是说了么,抢沙发啊

去你丫的现在心情不好

额,额

我电脑被

誓死包围沙发


云裳ovo云裳ovo

html?

点赞0


评论

你这代码没缩进啊

不太会awa

啊这

az


请设置昵称请请设置昵称请

可以用'插入代码'

就是这样子的

点赞0


评论


迷茫的章鱼迷茫的章鱼

do

msgbox("🐂逼")

loop

点赞0


评论

无限弹出喵?

啊对对对


DL1DL1

这是你写的么

点赞0


评论

是啊


活泼的皮卡丘4pMh活泼的皮卡丘4pMh

这是什么,我看不懂555

点赞0


评论