st=>start: 開啓服務
ipop1=>inputoutput: 接收到數據【不肯定是誰發來的】
op1=>operation: 嘗試提取出signature字段,timestamp字段,nonce字段,echostr字段
cd1=>condition: 字段均提取成功?
op2=>operation: token賦值爲基本配置中的信息
op3=>operation: token,timestamp,nonce字段排序獲得字符串list
op4=>operation: 哈希算法加密list獲得hashcode
cd2=>condition: hashcode == signature?
op5=>operation: 肯定該數據源是微信後臺
ipop2=>inputoutput: 把echostr返回給微信後臺,供微信後臺認證Token
ed=>end: 繼續其餘服務
op6=>operation: 肯定該數據源不是微信後臺
ipop3=>inputoutput: 不處理
st->ipop1->op1->cd1->op2->op3->op4->cd2->op5->ipop2->ed
cd1(yes)->op2
cd1(no)->op6->ipop3->ed
cd2(yes)->op5
cd2(no)->op6
@GetMapping("/getToken") @ResponseBody public String getToken(TokenDTO tokenDTO, HttpServletResponse response){ if ((StringUtils.isBlank(tokenDTO.getSignature()) || StringUtils.isBlank(tokenDTO.getTimestamp()) || StringUtils.isBlank(tokenDTO.getNonce()) || StringUtils.isBlank(tokenDTO.getEchostr()))) { return ""; } String[] arr = new String[]{tokenDTO.getTimestamp(), WeixinConstant.token, tokenDTO.getNonce()}; Arrays.sort(arr); StringBuffer sb = new StringBuffer(); sb.append(arr[0]).append(arr[1]).append(arr[2]); String hash = null; try { hash = new String(Hex.encodeHex(MessageDigest.getInstance("SHA-1"). digest(sb.toString().getBytes(Constant.charset)))); } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { e.printStackTrace(); } return (StringUtils.isNoneBlank(hash) && hash.equals(tokenDTO.getSignature())) ? tokenDTO.getEchostr() : ""; }