parent
5fab6f7b6c
commit
b9c3e1e106
@ -0,0 +1,21 @@
|
|||||||
|
package com.cyl.external;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class WechatUtil {
|
||||||
|
public static boolean validParam(String signature, String... arr) {
|
||||||
|
Arrays.sort(arr);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String[] var2 = arr;
|
||||||
|
int var3 = arr.length;
|
||||||
|
|
||||||
|
for(int var4 = 0; var4 < var3; ++var4) {
|
||||||
|
String a = var2[var4];
|
||||||
|
sb.append(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
return signature.equals(DigestUtils.sha1Hex(sb.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
package com.cyl.h5.controller;
|
||||||
|
|
||||||
|
import com.cyl.external.WechatUtil;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* h5/微信
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("")
|
||||||
|
public class WechatController {
|
||||||
|
/**
|
||||||
|
* 微信公众号服务器认证
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/no-auth/wechat-server-auth")
|
||||||
|
public String getHomeConfig(HttpServletRequest request) {
|
||||||
|
String signature = request.getParameter("signature");
|
||||||
|
String nonce = request.getParameter("nonce");
|
||||||
|
String timestamp = request.getParameter("timestamp");
|
||||||
|
String echostr = request.getParameter("echostr");
|
||||||
|
if (WechatUtil.validParam(signature, "BLU9Jo7vo", timestamp, nonce)) {
|
||||||
|
return echostr;
|
||||||
|
}
|
||||||
|
return "err";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue