修改区域公司

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算法生成安全签名
* @param data 数据
* @param key key
* @return 安全签名
* @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 {
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]);
Set<String> keySet = data.keySet();
String[] keyArray = keySet.toArray(new String[keySet.size()]);
Arrays.sort(keyArray);
StringBuilder sb = new StringBuilder();
for (String k : keyArray) {
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();
// SHA1签名生成

@ -55,32 +55,32 @@ public class WxMsgController {
@Resource
private HighMerchantStoreService merchantStoreService;
@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("RgAWdnR5oEOLBdyEjfr4" , 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;
}
}
// @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("RgAWdnR5oEOLBdyEjfr4" , 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;
// }
//
// }
@RequestMapping(value = "/verifyWxToken", method = RequestMethod.POST)
@ResponseBody
@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