|
|
@ -31,6 +31,9 @@ import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -63,10 +66,10 @@ public class WeChatAouth2Service {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
|
|
|
|
|
|
|
|
public Result getShareToken(){
|
|
|
|
public Result getShareToken(String url){
|
|
|
|
String ticket = (String)redisTemplate.opsForValue().get("shareTicket");
|
|
|
|
String ticket = (String)redisTemplate.opsForValue().get("shareTicket");
|
|
|
|
if(ticket != null && StringUtils.isNotBlank(ticket))
|
|
|
|
if(ticket != null && StringUtils.isNotBlank(ticket))
|
|
|
|
return Result.success(ticket);
|
|
|
|
return Result.success(sha1Signature(url,ticket));
|
|
|
|
|
|
|
|
|
|
|
|
Aouth2WeChatStableTokenResponse accessToken = getAccessShareToken();
|
|
|
|
Aouth2WeChatStableTokenResponse accessToken = getAccessShareToken();
|
|
|
|
if(accessToken == null || accessToken.getAccess_token() == null )
|
|
|
|
if(accessToken == null || accessToken.getAccess_token() == null )
|
|
|
@ -77,7 +80,7 @@ public class WeChatAouth2Service {
|
|
|
|
return Result.failed("分享微信失败");
|
|
|
|
return Result.failed("分享微信失败");
|
|
|
|
|
|
|
|
|
|
|
|
redisTemplate.opsForValue().set("shareTicket",aouth2WeChatJSAPIResponse.getTicket(),6000,TimeUnit.SECONDS);
|
|
|
|
redisTemplate.opsForValue().set("shareTicket",aouth2WeChatJSAPIResponse.getTicket(),6000,TimeUnit.SECONDS);
|
|
|
|
return Result.success(aouth2WeChatJSAPIResponse.getTicket());
|
|
|
|
return Result.success(sha1Signature(url,aouth2WeChatJSAPIResponse.getTicket()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// public Result loginOrRegister(WeChatLoginReq loginReq,String ipAddress){
|
|
|
|
// public Result loginOrRegister(WeChatLoginReq loginReq,String ipAddress){
|
|
|
@ -97,6 +100,35 @@ public class WeChatAouth2Service {
|
|
|
|
// return Result.success(token);
|
|
|
|
// return Result.success(token);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String sha1Signature(String url,String ticket) {
|
|
|
|
|
|
|
|
String signature = "jsapi_ticket=" + ticket + "&noncestr=" + UUID.randomUUID()
|
|
|
|
|
|
|
|
+ "×tamp=" +System.currentTimeMillis() / 1000 + "&url=" + url;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
//指定sha1算法
|
|
|
|
|
|
|
|
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
|
|
|
|
|
|
|
digest.update(signature.getBytes());
|
|
|
|
|
|
|
|
//获取字节数组
|
|
|
|
|
|
|
|
byte messageDigest[] = digest.digest();
|
|
|
|
|
|
|
|
// Create Hex String
|
|
|
|
|
|
|
|
StringBuffer hexString = new StringBuffer();
|
|
|
|
|
|
|
|
// 字节数组转换为 十六进制 数
|
|
|
|
|
|
|
|
for (int i = 0; i < messageDigest.length; i++) {
|
|
|
|
|
|
|
|
String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
|
|
|
|
|
|
|
|
if (shaHex.length() < 2) {
|
|
|
|
|
|
|
|
hexString.append(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
hexString.append(shaHex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return hexString.toString().toUpperCase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Result login(WeChatLoginReq loginReq,String ipAddress){
|
|
|
|
public Result login(WeChatLoginReq loginReq,String ipAddress){
|
|
|
|
|
|
|
|
|
|
|
|
Aouth2WeChatTokenResponse accessToken = getAccessToken(loginReq.getCode());
|
|
|
|
Aouth2WeChatTokenResponse accessToken = getAccessToken(loginReq.getCode());
|
|
|
|