修改区域公司

dev-discount
袁野 2 years ago
parent 8769b071cc
commit eac9c4008a
  1. 21
      hai-service/src/main/java/com/hai/common/utils/WxUtils.java
  2. 80
      v1/src/main/java/com/v1/controller/WxMsgController.java

@ -543,19 +543,24 @@ public class WxUtils {
/** /**
* 用SHA1算法生成安全签名 * 用SHA1算法生成安全签名
* @param data 数据 * @param data 数据
* @param key key
* @return 安全签名 * @return 安全签名
* @throws Exception * @throws Exception
*/ */
public static String getSHA1(final Map<String, Object> data, String key) throws Exception public static String getSHA1(final Map<String, Object> data) throws Exception
{ {
try { try {
String[] array = new String[] { token, timestamp, nonce}; Set<String> keySet = data.keySet();
StringBuffer sb = new StringBuffer(); String[] keyArray = keySet.toArray(new String[keySet.size()]);
// 字符串排序 Arrays.sort(keyArray);
Arrays.sort(array); StringBuilder sb = new StringBuilder();
for (int i = 0; i < 3; i++) { for (String k : keyArray) {
sb.append(array[i]); if (k.equals(WXPayConstants.FIELD_SIGN) || k.equals("apiKey")) {
continue;
}
if (data.get(k) != null) // 参数值为空,则不参与签名
{
sb.append(k).append("=").append(data.get(k)).append("&");
}
} }
String str = sb.toString(); String str = sb.toString();
// SHA1签名生成 // SHA1签名生成

@ -55,32 +55,32 @@ public class WxMsgController {
@Resource @Resource
private HighMerchantStoreService merchantStoreService; private HighMerchantStoreService merchantStoreService;
@RequestMapping(value = "/verifyWxToken", method = RequestMethod.GET) // @RequestMapping(value = "/verifyWxToken", method = RequestMethod.GET)
@ResponseBody // @ResponseBody
@ApiOperation(value = "验证servlet") // @ApiOperation(value = "验证servlet")
public String verifyWxToken( // public String verifyWxToken(
@RequestParam(name = "signature", required = false) String signature, // @RequestParam(name = "signature", required = false) String signature,
@RequestParam(name = "timestamp", required = false) String timestamp, // @RequestParam(name = "timestamp", required = false) String timestamp,
@RequestParam(name = "nonce", required = false) String nonce, // @RequestParam(name = "nonce", required = false) String nonce,
@RequestParam(name = "echostr", required = false) String echostr // @RequestParam(name = "echostr", required = false) String echostr
) { // ) {
//
try { // try {
//
String signatureStr = WxUtils.getSHA1("RgAWdnR5oEOLBdyEjfr4" , timestamp , nonce); // String signatureStr = WxUtils.getSHA1("RgAWdnR5oEOLBdyEjfr4" , timestamp , nonce);
log.info("signatureStr!!!!!" + signatureStr); // log.info("signatureStr!!!!!" + signatureStr);
log.info("signature!!!!!" + signature); // log.info("signature!!!!!" + signature);
if (signature.equals(signatureStr)) { // if (signature.equals(signatureStr)) {
log.info("验证通过!!!!!"); // log.info("验证通过!!!!!");
return echostr; // return echostr;
} // }
log.info("验证失败!!!!!"); // log.info("验证失败!!!!!");
return null; // return null;
} catch (Exception e) { // } catch (Exception e) {
return null; // return null;
} // }
//
} // }
@RequestMapping(value = "/verifyWxToken", method = RequestMethod.POST) @RequestMapping(value = "/verifyWxToken", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "验证servlet") @ApiOperation(value = "验证servlet")
@ -251,4 +251,32 @@ public class WxMsgController {
} }
@RequestMapping(value = "/verifyWx", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "微信签名")
public String verifyWx() {
try {
Map<String, Object> params = new HashMap<>();
params.put("appid", SysConst.getSysConfig().getWxH5AppId());
params.put("secret", SysConst.getSysConfig().getWxH5AppSecret());
params.put("grant_type", "client_credential");
JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params);
Map<String, Object> map = new HashMap<>();
map.put("noncestr","Wm3WZYTPz0wzccnW");
map.put("jsapi_ticket",accessTokenObject.getString("ticket"));
map.put("timestamp","1414587457");
map.put("url","http://mp.weixin.qq.com?params=value");
return WxUtils.getSHA1(map);
} catch (Exception e) {
return null;
}
}
} }

Loading…
Cancel
Save