|
|
|
@ -69,7 +69,7 @@ public class WeChatAouth2Service {
|
|
|
|
|
public Result getShareToken(String url){
|
|
|
|
|
String ticket = (String)redisTemplate.opsForValue().get("shareTicket");
|
|
|
|
|
if(ticket != null && StringUtils.isNotBlank(ticket))
|
|
|
|
|
return Result.success(sha1Signature(url,ticket));
|
|
|
|
|
return sha1Signature(url, ticket);
|
|
|
|
|
|
|
|
|
|
Aouth2WeChatStableTokenResponse accessToken = getAccessShareToken();
|
|
|
|
|
if(accessToken == null || accessToken.getAccess_token() == null )
|
|
|
|
@ -80,7 +80,7 @@ public class WeChatAouth2Service {
|
|
|
|
|
return Result.failed("分享微信失败");
|
|
|
|
|
|
|
|
|
|
redisTemplate.opsForValue().set("shareTicket",aouth2WeChatJSAPIResponse.getTicket(),6000,TimeUnit.SECONDS);
|
|
|
|
|
return Result.success(sha1Signature(url,aouth2WeChatJSAPIResponse.getTicket()));
|
|
|
|
|
return sha1Signature(url,aouth2WeChatJSAPIResponse.getTicket());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// public Result loginOrRegister(WeChatLoginReq loginReq,String ipAddress){
|
|
|
|
@ -101,9 +101,14 @@ public class WeChatAouth2Service {
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String sha1Signature(String url,String ticket) {
|
|
|
|
|
String signature = "jsapi_ticket=" + ticket + "&noncestr=" + UUID.randomUUID()
|
|
|
|
|
+ "×tamp=" +System.currentTimeMillis() / 1000 + "&url=" + url;
|
|
|
|
|
public Result sha1Signature(String url,String ticket) {
|
|
|
|
|
|
|
|
|
|
Aouth2WeChatShareResponse aouth2WeChatShareResponse = new Aouth2WeChatShareResponse();
|
|
|
|
|
String timestamp = Long.toString(System.currentTimeMillis() / 1000);
|
|
|
|
|
String noncestr = String.valueOf(UUID.randomUUID());
|
|
|
|
|
|
|
|
|
|
String signature = "jsapi_ticket=" + ticket + "&noncestr=" + noncestr
|
|
|
|
|
+ "×tamp=" + timestamp + "&url=" + url;
|
|
|
|
|
try {
|
|
|
|
|
//指定sha1算法
|
|
|
|
|
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
|
|
|
@ -120,13 +125,17 @@ public class WeChatAouth2Service {
|
|
|
|
|
}
|
|
|
|
|
hexString.append(shaHex);
|
|
|
|
|
}
|
|
|
|
|
return hexString.toString().toUpperCase();
|
|
|
|
|
|
|
|
|
|
aouth2WeChatShareResponse.setSignature(hexString.toString().toUpperCase());
|
|
|
|
|
aouth2WeChatShareResponse.setTimestamp(timestamp);
|
|
|
|
|
aouth2WeChatShareResponse.setNonceStr(noncestr);
|
|
|
|
|
return Result.success(aouth2WeChatShareResponse);
|
|
|
|
|
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
return Result.failed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result login(WeChatLoginReq loginReq,String ipAddress){
|
|
|
|
|