• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

Java实现微信的自动回复总是报错

是按照天盟网的教程抄的代码,可是不知道为什么总是报错

Servlet.service() for servlet [weixinServlet] in context with path [/One] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: javax/jms/TextMessage
错误出现在这一行
我把weixinservlet类和checkutil还有messageutil类发在下面了,求大牛指点错在哪里了
080004e2jlkbu3uyy2u22b.jpg



↓↓下面是WeixinServlet类的dopost方法
protected void doPost(HttpServletRequest req,HttpServletResponse resp)
                        throws ServletException,IOException{
                        req.setCharacterEncoding("UTF-8");
                        resp.setCharacterEncoding("UTF-8");
                        PrintWriter out  = resp.getWriter();
                        try {
                        Map map = MessageUtil.xmlToMap(req);
                                String fromUserName = map.get("FromUserName");
                                String toUserName = map.get("ToUserName");
                                String msgType = map.get("MsgType");
                                String content = map.get("Content");
                                String message = null;
                                if("text".equals(msgType)){
                                        TextMassage text  = new TextMassage();
                                text.setFromUserName(toUserName);
                                text.setToUserName(fromUserName);
                                text.setMsgType("text");
                                text.setContent("您发送的消息是"+content);
                                message = MessageUtil.textMessageToXml(text);
                                }
                                out.print(message);
                        } catch (DocumentException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }finally{
                                out.close();
                               
                        }
                       
                }
↓↓这是checkutil类
package com.imooc.util;


import java.security.MessageDigest;
import java.util.Arrays;


public class CheckUtil {
        public static final String token = "imooc";
                public static boolean checkSignature(String signature,String timestamp,String nonce){
                        String[] arr=new String[]{token,timestamp,nonce};
                        Arrays.sort(arr);
                        StringBuffer content = new StringBuffer();
                        for(int i = 0;i>> 4 & 0xf];
                       buf[k++] = hexDigits[byte0 & 0xf];      
                   }
                   return new String(buf);
               } catch (Exception e) {
                   // TODO: handle exception
                   return null;
               }


        }
        }
↓↓这是messageutil类
package com.imooc.util;


import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import javax.jms.TextMessage;
import javax.servlet.http.HttpServletRequest;


import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


import com.immoc.po.TextMassage;
import com.thoughtworks.xstream.XStream;


public class MessageUtil {
        public static MapxmlToMap(HttpServletRequest request)throws IOException,DocumentException{
                Mapmap=new HashMap();
                SAXReader reader = new SAXReader();
               
                InputStream ins = request.getInputStream();
               
                Document doc = reader.read(ins);
               
                Element root = doc.getRootElement();
               
                List list = root.elements();
                for(Element e:list){
                       
                        map.put(e.getName(),e.getText());
                       
                }
                ins.close();
               
                return map;
               
               
               
        }
        public static String textMessageToXml(TextMassage text){
                XStream xstream = new XStream();
                xstream.alias("xml", text.getClass());
                return  xstream.toXML(text);
               
               
               
        }
       


};

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031168位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!