一、申请微信测试号
进入网址:微信测试号登录
接下来微信登录,然后进入页面
① 第一点就是接口配置信息,可以使用springmvc或servlet来进行验证,我这里使用springmvc来编写验证代码:
DemoController.java
package com.demo.controller;
import com.demo.util.WxUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Map;
/**
* @author xyd
* @version V1.0
* @Package com.demo.controller
* @Description:
* @date 2018/8/6 17:19
*/
@RestController("demo")
@RequestMapping("/wx")
public class DemoController {
//这里的token要和微信测试号网页填写的token一样
public static final String TOKEN = "okjfdlsf_lsdfjdslkfj_token";
@GetMapping("/get")
public void get(String signature,String timestamp,String nonce,String echostr, HttpServletResponse response) throws IOException, NoSuchAlgorithmException {
// 将token、timestamp、nonce三个参数进行字典序排序
System.out.println("signature:"+signature);
System.out.println("timestamp:"+timestamp);
System.out.println("nonce:"+nonce)