微信开发——测试账号的配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunhuwh/article/details/68925518

配置位置
进入公众号:https://mp.weixin.qq.com
进入开发者工具:公众号页面左下角
进入公众平台测试账号:开发者工具页面中

下面有张图片,介绍配置:
这里写图片描述

下面来看看Token验证。注意:本次微信开发专栏,全部使用spring boot进行开发。
CODE:servlet

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shw.vote.web.service.AuthService;

public class ServerPortal extends HttpServlet {
    private static final long serialVersionUID = 1L;
    //我们的Token
    private static final String token = "tokensh";

    /**
     * @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);
    }

}

spring boot需要注入servlet:

@Bean  
public ServletRegistrationBean testServletRegistration() {  
    ServletRegistrationBean registration = new ServletRegistrationBean(new ServerPortal());  
    //我们的URL
    registration.addUrlMappings("/portal");  
    return registration;  
}

上面我们设定Token为tokensh:
private static final String token = “tokensh”;

由于Token验证接口URL必须是域名,我这边使用了ngrok来处理域名的问题:
参考http://www.qydev.com/
注意,Token验证的地址一定要用80端口。
假设我们的域名为https://sunhush.tunnel.qydev.com
URL处我们填:https://sunhush.tunnel.qydev.com/portal

Token , URL都设定了,提交,提示提交成功,则配置完毕。

参考资料:http://www.cnblogs.com/janken/p/5593737.html

没有更多推荐了,返回首页