定时任务修改文件包与service 冲突

dev
袁野 2 months ago
parent e76b48a450
commit 75f34f6d14
  1. 1
      order/src/main/java/com/order/config/AuthConfig.java
  2. 47
      order/src/main/java/com/order/controller/notify/WxNotifyController.java
  3. 40
      service/src/main/java/com/hfkj/common/utils/WxUtils.java

@ -91,6 +91,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/cqNotify/*")
.excludePathPatterns("/meiTuan/*")
.excludePathPatterns("/orderCinema/queryOrder")
.excludePathPatterns("/wxNotify/verifyWxToken")
;
}

@ -0,0 +1,47 @@
package com.order.controller.notify;
import com.hfkj.common.utils.WxUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping(value = "/wxNotify")
@Api(value = "微信通知")
public class WxNotifyController {
private static Logger log = LoggerFactory.getLogger(WxNotifyController.class);
@RequestMapping(value = "/verifyWxToken", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "验证servlet")
public String verifyWxToken(
@RequestParam(name = "signature", required = false) String signature,
@RequestParam(name = "timestamp", required = false) String timestamp,
@RequestParam(name = "nonce", required = false) String nonce,
@RequestParam(name = "echostr", required = false) String echostr
) {
try {
String signatureStr = WxUtils.getSHA1("PHGWX" , timestamp , nonce);
log.info("signatureStr!!!!!" + signatureStr);
log.info("signature!!!!!" + signature);
if (signature.equals(signatureStr)) {
log.info("验证通过!!!!!");
return echostr;
}
log.info("验证失败!!!!!");
return null;
} catch (Exception e) {
return null;
}
}
}

@ -211,6 +211,46 @@ public class WxUtils {
}
}
/**
* 用SHA1算法生成安全签名
* @param token 票据
* @param timestamp 时间戳
* @param nonce 随机字符串
* @return 安全签名
* @throws Exception
*/
public static String getSHA1(String token, String timestamp, String nonce) throws Exception
{
try {
String[] array = new String[] { token, timestamp, nonce};
StringBuffer sb = new StringBuffer();
// 字符串排序
Arrays.sort(array);
for (int i = 0; i < 3; i++) {
sb.append(array[i]);
}
String str = sb.toString();
// SHA1签名生成
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(str.getBytes());
byte[] digest = md.digest();
StringBuffer hexstr = new StringBuffer();
String shaHex = "";
for (int i = 0; i < digest.length; i++) {
shaHex = Integer.toHexString(digest[i] & 0xFF);
if (shaHex.length() < 2) {
hexstr.append(0);
}
hexstr.append(shaHex);
}
return hexstr.toString();
} catch (Exception e) {
e.printStackTrace();
throw new Exception(String.format("Invalid sign_type: %s"));
}
}
/**
* 拼接签名数据
*

Loading…
Cancel
Save