|
|
@@ -10,6 +10,7 @@ import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
import com.dk.common.response.ResponseCodeEnum;
|
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
|
import com.dk.common.response.ResponseResultVO;
|
|
|
+import com.dk.common.util.DateUtils;
|
|
|
import com.dk.common.util.HttpUtils;
|
|
|
import com.dk.oauth.config.WxConfig;
|
|
|
import com.dk.oauth.dto.AuthAccessTokenDto;
|
|
|
@@ -36,7 +37,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@@ -86,11 +89,11 @@ public class AuthAccessTokenServiceImpl extends ServiceImpl<AuthAccessTokenMappe
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * @desc : 查询用户最新token
|
|
|
+ * @desc : 查询用户最新token
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2022-08-02 17:30
|
|
|
+ * @date : 2022-08-02 17:30
|
|
|
*/
|
|
|
- public String getCurrentToken(Long userId){
|
|
|
+ public String getCurrentToken(Long userId) {
|
|
|
return authAccessTokenMapper.getCurrentToken(userId);
|
|
|
}
|
|
|
|
|
|
@@ -115,11 +118,11 @@ public class AuthAccessTokenServiceImpl extends ServiceImpl<AuthAccessTokenMappe
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * @desc : 获取token
|
|
|
+ * @desc : 获取token
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2024-02-20 14:04
|
|
|
+ * @date : 2024-02-20 14:04
|
|
|
*/
|
|
|
- public ResponseResultVO token(HttpServletRequest request){
|
|
|
+ public ResponseResultVO token(HttpServletRequest request) {
|
|
|
UserLogin userLogin = userMapper.getByPhone(request.getParameter("phone"));
|
|
|
if (userLogin == null || (!userLogin.getUserPwd().equals(request.getParameter("password")))) {
|
|
|
//无用户 或 密码错误
|
|
|
@@ -137,9 +140,9 @@ public class AuthAccessTokenServiceImpl extends ServiceImpl<AuthAccessTokenMappe
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @desc : 小程序通过微信openid登录
|
|
|
+ * @desc : 小程序通过微信openid登录
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2024-02-20 14:04
|
|
|
+ * @date : 2024-02-20 14:04
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public ResponseResultVO wxToken(UserWxLogin userWxLogin) {
|
|
|
@@ -162,16 +165,16 @@ public class AuthAccessTokenServiceImpl extends ServiceImpl<AuthAccessTokenMappe
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @desc : 注册
|
|
|
+ * @desc : 注册
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2024-02-20 13:55
|
|
|
+ * @date : 2024-02-20 13:55
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public ResponseResultVO<?> register(UserWxLogin userWxLogin){
|
|
|
+ public ResponseResultVO<?> register(UserWxLogin userWxLogin) {
|
|
|
UserLogin userLogin = userMapper.getByWxid(userWxLogin.getUserWxid());
|
|
|
|
|
|
//通过openid查到用户,但手机号为空
|
|
|
- if (userLogin != null && userLogin.getUserPhone()==null) {
|
|
|
+ if (userLogin != null && userLogin.getUserPhone() == null) {
|
|
|
//将其他微信用户的相同电话清空
|
|
|
userMapper.cleanPhone(userWxLogin.getUserPhone());
|
|
|
//更新当前手机号
|
|
|
@@ -181,13 +184,13 @@ public class AuthAccessTokenServiceImpl extends ServiceImpl<AuthAccessTokenMappe
|
|
|
if (userLogin == null) {
|
|
|
//openid没查到,用手机号再查一次
|
|
|
userLogin = userMapper.getByPhone(userWxLogin.getUserPhone());
|
|
|
- } else if (userLogin.getUserWxid()==null) {
|
|
|
+ } else if (userLogin.getUserWxid() == null) {
|
|
|
//通过手机号查到了用户,但是openid是空,更新上当前的openid
|
|
|
userMapper.updateWxid(userLogin.getUserId(), userWxLogin.getUserWxid());
|
|
|
}
|
|
|
|
|
|
//用户无法通过openid或手机号查到 或 通过手机号查到了,但openid不同
|
|
|
- if (userLogin == null || !userWxLogin.getUserWxid().equals(userLogin.getUserWxid())){
|
|
|
+ if (userLogin == null || !userWxLogin.getUserWxid().equals(userLogin.getUserWxid())) {
|
|
|
//将其他微信用户的相同电话清空
|
|
|
userMapper.cleanPhone(userWxLogin.getUserPhone());
|
|
|
//注册
|
|
|
@@ -206,9 +209,9 @@ public class AuthAccessTokenServiceImpl extends ServiceImpl<AuthAccessTokenMappe
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @desc : 验证当前扫码登录是否匹配到openid
|
|
|
+ * @desc : 验证当前扫码登录是否匹配到openid
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2024-02-20 14:04
|
|
|
+ * @date : 2024-02-20 14:04
|
|
|
*/
|
|
|
public ResponseResultVO<?> checkLoginOpenId(String uuid) {
|
|
|
String openId = stringRedisTemplate.opsForValue().get(Constant.RedisConstant.REDIS_LOGIN_UUID.getName() + uuid);
|
|
|
@@ -253,9 +256,9 @@ public class AuthAccessTokenServiceImpl extends ServiceImpl<AuthAccessTokenMappe
|
|
|
//当前公司
|
|
|
CompanyResponse company = null;
|
|
|
String accessToken = "";
|
|
|
- if (userLogin.getCurrentCp()!=null) {
|
|
|
+ if (userLogin.getCurrentCp() != null) {
|
|
|
company = companyMapper.getByCpId(userLogin.getCurrentCp());
|
|
|
- if(company != null ){
|
|
|
+ if (company != null) {
|
|
|
JWTGenerator jwtGenerator = new JWTGenerator();
|
|
|
jwtGenerator.setSalt(username);
|
|
|
jwtGenerator.setUsername(username);
|
|
|
@@ -300,15 +303,15 @@ public class AuthAccessTokenServiceImpl extends ServiceImpl<AuthAccessTokenMappe
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @desc : 生成微信临时二维码
|
|
|
+ * @desc : 生成微信临时二维码
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2024-02-20 17:00
|
|
|
+ * @date : 2024-02-20 17:00
|
|
|
*/
|
|
|
- public ResponseResultVO<?> getQrCode(String uuid){
|
|
|
+ public ResponseResultVO<?> getQrCode(String uuid) {
|
|
|
//获取access token
|
|
|
String accessToken = stringRedisTemplate.opsForValue().get(Constant.RedisConstant.REDIS_WECHAT_ACCESS_TOKEN.getName());
|
|
|
if (accessToken == null) {
|
|
|
- ResponseResultVO<JSONObject> tokenRes = HttpUtils.get(config.getAccessToken() + "appid="+config.getOffiAccountAppId()+"&secret="+config.getOffiAccountAppSecret());
|
|
|
+ ResponseResultVO<JSONObject> tokenRes = HttpUtils.get(config.getAccessToken() + "appid=" + config.getOffiAccountAppId() + "&secret=" + config.getOffiAccountAppSecret());
|
|
|
if (tokenRes.getCode() == ResponseCodeEnum.SUCCESS.getCode()) {
|
|
|
stringRedisTemplate.opsForValue().set(Constant.RedisConstant.REDIS_WECHAT_ACCESS_TOKEN.getName(), tokenRes.getData().getString("access_token"), 5, TimeUnit.MINUTES);
|
|
|
accessToken = tokenRes.getData().getString("access_token");
|
|
|
@@ -339,4 +342,64 @@ public class AuthAccessTokenServiceImpl extends ServiceImpl<AuthAccessTokenMappe
|
|
|
|
|
|
return ResponseResultUtil.success(config.getShowQrCode() + ticket);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 生成微信小程序二维码
|
|
|
+ * @author : 姜永辉
|
|
|
+ * @date : 2024-02-20 17:00
|
|
|
+ */
|
|
|
+ public ResponseResultVO<?> getWxQrCode(Map<String, Object> map) {
|
|
|
+ System.out.println("getWxQrCode:" + map);
|
|
|
+ //获取access token
|
|
|
+ String accessToken = stringRedisTemplate.opsForValue().get(Constant.RedisConstant.REDIS_WECHAT_QRCODE_ACCESS_TOKEN.getName());
|
|
|
+ if (accessToken == null) {
|
|
|
+ ResponseResultVO<JSONObject> tokenRes = HttpUtils.get(config.getAccessToken()
|
|
|
+ + "appid=" + config.getAppId()
|
|
|
+ + "&secret=" + config.getAppSecret());
|
|
|
+ if (tokenRes.getCode() == ResponseCodeEnum.SUCCESS.getCode()) {
|
|
|
+ stringRedisTemplate.opsForValue().set(Constant.RedisConstant.REDIS_WECHAT_QRCODE_ACCESS_TOKEN.getName(),
|
|
|
+ tokenRes.getData().getString("access_token"), 5, TimeUnit.MINUTES);
|
|
|
+ accessToken = tokenRes.getData().getString("access_token");
|
|
|
+ } else {
|
|
|
+ return tokenRes;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("page", "pages/welcome/welcome");
|
|
|
+ param.put("scene", "s=" + map.get("openid"));
|
|
|
+ param.put("checkPath", false);
|
|
|
+ String url = config.getUnlimitedQRCode() + accessToken;
|
|
|
+ String filePath = this.createDirByPath("Qr_code") + java.util.UUID.randomUUID().toString() + ".jpeg";
|
|
|
+ ResponseResultVO<String> responseResultVO = HttpUtils.postReturnFile(url, param, filePath);
|
|
|
+ System.out.println("getWxQrCode:" + filePath);
|
|
|
+ return ResponseResultUtil.success(responseResultVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String createDirByPath(String type) {
|
|
|
+ /**
|
|
|
+ * @date_time 2020-07-31 09:42
|
|
|
+ * @author H_x_d
|
|
|
+ * @description 根据类型创建目录文件夹
|
|
|
+ * @param [type]
|
|
|
+ * @return java.lang.String
|
|
|
+ */
|
|
|
+ String path = type + "/" + DateUtils.formatNow("yyyy-MM-dd") + "/";
|
|
|
+ String base = config.getUploadPath();
|
|
|
+ File baseDir = new File(base);
|
|
|
+ if (!baseDir.exists()) {
|
|
|
+ baseDir.mkdir();
|
|
|
+ }
|
|
|
+ String[] paths = path.split("/");
|
|
|
+ for (int i = 0; i < paths.length; i++) {
|
|
|
+ base = base + "/" + paths[i];
|
|
|
+ File dir = new File(base);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return base + "/";
|
|
|
+ }
|
|
|
+
|
|
|
}
|