服務器配置以下java
package com.dongpeng; import java.security.MessageDigest; import java.util.Arrays; import javax.servlet.http.HttpServletResponse; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @SpringBootApplication public class Application { public static final String TOKEN = "lianghao_token"; @RequestMapping("/") @ResponseBody public void index(String signature, String timestamp, String nonce, String echostr,HttpServletResponse response)throws Exception { System.out.println("signature:" + signature); System.out.println("timestamp:" + timestamp); System.out.println("nonce:" + nonce); System.out.println("echostr:" + echostr); System.out.println("TOKEN:" + TOKEN); String[] params = new String[] { TOKEN, timestamp, nonce }; Arrays.sort(params); // 將三個參數字符串拼接成一個字符串進行sha1加密 String clearText = params[0] + params[1] + params[2]; String algorithm = "SHA-1"; String sign = new String(org.apache.commons.codec.binary.Hex .encodeHex(MessageDigest.getInstance(algorithm).digest((clearText).getBytes()), true)); // 開發者得到加密後的字符串可與signature對比,標識該請求來源於微信 if (signature.equals(sign)) { response.getWriter().print(echostr); } } public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } }
配置服務端後,提交下面信息web
才能成功提交spring