美文网首页javaJavaEE 学习专题
微信测试号接口配置token(servlet)

微信测试号接口配置token(servlet)

作者: 城东那个小丑 | 来源:发表于2016-12-11 19:10 被阅读2663次

    利用javaweb的Servlet来进行“接口配置信息配置信息”认证的。

    在学习微信公众号开发的时候,读到填写服务器配置的帮助部分,总是不能理解为啥按照他的步骤做总是设置失败

    设置失败的一个重要原因:url的请求相应没有返回echostr这个参数。

    URL:

    代码:

    packagecom.bs.util;

    importjavax.servlet.ServletException;

    importjavax.servlet.annotation.WebServlet;

    importjavax.servlet.http.HttpServlet;

    importjavax.servlet.http.HttpServletRequest;

    importjavax.servlet.http.HttpServletResponse;

    importjava.io.IOException;

    importjava.io.PrintWriter;

    @WebServlet("/portal")

    public classServerPortalextendsHttpServlet {

    private static final longserialVersionUID=1L;

    private static finalStringtoken="djp";

    /**

    *@seeHttpServlet#HttpServlet()

    */

    publicServerPortal() {

    super();

    }

    /**

    *@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

    */

    protected voiddoGet(HttpServletRequest request,HttpServletResponse response)throwsServletException,IOException {

    String signature = request.getParameter("signature");

    String timestamp = request.getParameter("timestamp");

    String nonce = request.getParameter("nonce");

    String echostr = request.getParameter("echostr");

    System.out.println("signature:"+ signature);

    System.out.println("timestamp:"+ timestamp);

    System.out.println("nonce:"+ nonce);

    System.out.println("echostr:"+ echostr);

    PrintWriter pw =null;

    try{

    pw = response.getWriter();

    }catch(IOException e) {

    e.printStackTrace();

    }

    pw.append(echostr);

    pw.flush();

    }

    /**

    *@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

    */

    protected voiddoPost(HttpServletRequest request,HttpServletResponse response)throwsServletException,IOException {

    doGet(request,response);

    }

    }

    相关文章

      网友评论

      本文标题:微信测试号接口配置token(servlet)

      本文链接:https://www.haomeiwen.com/subject/yfspmttx.html