首先阅读开发文档开始开发内容 https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html
其中验证token方法 Java版 附上
@RequestMapping(produces = "text/html;charset=utf-8",method = RequestMethod.GET) public String checkToken(@RequestParam("signature") String signature, @RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce, @RequestParam("echostr") String echostr) throws Exception { //排序 String[] arr = {TOKEN, timestamp, nonce}; Arrays.sort(arr); StringBuilder content = new StringBuilder(); for (int i = 0; i < arr.length; i++) { content.append(arr[i]); } //sha1Hex 加密 MessageDigest md = null; String temp = null; try { md = MessageDigest.getInstance("SHA-1"); byte[] digest = md.digest(content.toString().getBytes()); temp = byteToStr(digest); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } if ((temp.toLowerCase()).equals(signature)){ return echostr; } return null; } private static String byteToStr(byte[] byteArray){ String strDigest = ""; for (int i = 0; i < byteArray.length; i++) { strDigest += byteToHexStr(byteArray[i]); } return strDigest; } private static String byteToHexStr(byte mByte){ char[] Digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A','B', 'C', 'D', 'E', 'F' }; char[] tempArr = new char[2]; tempArr[0] = Digit[(mByte >>> 4)& 0X0F]; tempArr[1] = Digit[mByte & 0X0F]; String s = new String(tempArr); return s; }