首先说明,本帮助文档是利用javaweb的Servlet来进行“接口配置信息配置信息”认证的。

在学习微信公众号开发的时候,读到填写服务器配置的帮助部分,总是不能理解为啥按照他的步骤做总是设置失败(吐槽:这个帮助写的太简略,原理讲了一般,对不了解PHP的人简直就是歧视)。

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

如果读到这里你还不能理解,就请看以下的截图和源代码:

1、首先我搭建了一个将局域网内我的电脑发布到intetnet上的环境,利用ngrok,如果想了解如何搭建,请查看我的另一篇博客:ngrok使用命令帮助

 @WebServlet("/portal")
public class ServerPortal extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final String token = "janken"; /**
* @see HttpServlet#HttpServlet()
*/
public ServerPortal() {
super();
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, 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 = response.getWriter();
pw.append(echostr);
pw.flush();
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
} }

4、根据ngrok提供的url和我们创建的servlet填写微信的url和token

5、点击提交,这是微信会主动访问我们写的servlet,获得我们返回的参数中的echostr的内容即可认证通过。

认证过程原理分析:

最新文章

  1. 1ms引发的问题
  2. 第二次团队作业——预则立&&他山之石
  3. python 函数的参数定义及调用
  4. 上传文件大于 2G以上
  5. 现在, Delphi 的多线程已经非常易用了!
  6. C#中jQuery Ajax实例(二)
  7. Be a person
  8. XCode 项目配置说明
  9. cell的循环使用
  10. Oracle中的单引号问题
  11. 在C++程序中自动加入svn版本号
  12. iOS 开发笔记 - 开发中如何实现自动检测更新APP
  13. HDFS 的垃圾回收配置
  14. javascript性能优化之使用对象、数组直接量代替典型的对象创建和赋值
  15. JS拖拽元素原理及实现代码
  16. 3.配置Spring+SpringMvc+Mybatis(分库or读写分离)--Intellij IDAE 2016.3.5
  17. windows批处理命令
  18. SQL Server 调优系列进阶篇 - 如何维护数据库索引
  19. 【无图慎入】Link Cut Tree 总结
  20. 【洛谷】1494:[国家集训队]小Z的袜子【莫队】

热门文章

  1. JS的checkbox状态切换dom无变化
  2. CSS Ul(列表样式)
  3. Python3.x:pytesseract识别率提高(样本训练)
  4. [pixhawk笔记]6-uORB流程及关键函数解析
  5. python之subprocess
  6. Job流程:决定map个数的因素
  7. cmd中如何查看环境变量
  8. kill me heal me的链接
  9. mybatis映射文件select_resultMap_关联查询_collection定义关联集合
  10. saga+.net core 分布式事务处理