From 7a234f619e77c57a29e43ab647dff784bdb92621 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com> Date: Fri, 17 Sep 2021 09:22:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=92=8C=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../xkrs/common/config/ConstantConfig.java | 2 + .../xkrs/common/config/WebSecurityConfig.java | 5 +++ .../com/xkrs/controller/WeChatController.java | 38 +++++++++++++++++++ .../java/com/xkrs/dao/WorkHourRecordDao.java | 3 +- .../java/com/xkrs/service/SysUserService.java | 4 +- src/main/java/com/xkrs/utils/Query.java | 1 + src/main/resources/application.properties | 6 +-- 8 files changed, 55 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index db86383..be3c804 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ com.xkrs - xkrs_work + work_management 0.0.1-SNAPSHOT xkrs_work Demo project for Spring Boot diff --git a/src/main/java/com/xkrs/common/config/ConstantConfig.java b/src/main/java/com/xkrs/common/config/ConstantConfig.java index b70a371..ada96d8 100644 --- a/src/main/java/com/xkrs/common/config/ConstantConfig.java +++ b/src/main/java/com/xkrs/common/config/ConstantConfig.java @@ -2,10 +2,12 @@ package com.xkrs.common.config; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; /** * @author XinYi Song */ +@Component public class ConstantConfig implements InitializingBean { @Value("${wx.open.app_id}") diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 170d0f7..bb716cc 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -45,8 +45,13 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.POST,"/importCvProjectExcel").permitAll() .antMatchers(HttpMethod.GET,"/excelOutWork").permitAll() .antMatchers(HttpMethod.GET,"/selectMemberAndWorkHour").permitAll() + .antMatchers(HttpMethod.POST,"/userLogin").permitAll() + .antMatchers(HttpMethod.POST,"/decodePhone").permitAll() .antMatchers(HttpMethod.POST,"/api/user/findUserByOpenId").permitAll() .antMatchers(HttpMethod.POST,"/api/user/updateOpenIdByPhone").permitAll() + .antMatchers(HttpMethod.GET,"/callback").permitAll() + .antMatchers(HttpMethod.GET,"/weChatScanCodeLogin").permitAll() + .antMatchers(HttpMethod.GET,"/api/user/findUserAndWeChatUser").permitAll() // 所有其它请求需要身份认证 .anyRequest().authenticated() .and() diff --git a/src/main/java/com/xkrs/controller/WeChatController.java b/src/main/java/com/xkrs/controller/WeChatController.java index c46bcae..9f31d33 100644 --- a/src/main/java/com/xkrs/controller/WeChatController.java +++ b/src/main/java/com/xkrs/controller/WeChatController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.net.URLEncoder; import java.util.HashMap; import java.util.Locale; @@ -96,4 +97,41 @@ public class WeChatController { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"操作失败!",locale); } } + + /** + * 1.生成微信扫描二维码 + * @return + */ + @GetMapping("/weChatScanCodeLogin") + public String getWxCode(){ + /*第一种方式:固定地址后面拼参数,参数太多,容易拼错 + String url = "https://open.weixin.qq.com/connect/qrconnect?appid="+ ConstantWxUtils.WX_OPEN_APP_ID + +"&response_type=code"; + */ + //第二种方式:%s:相当于一个占位符 + String baseUrl = "https://open.weixin.qq.com/connect/qrconnect" + + "?appid=%s" + + "&redirect_uri=%s" + + "&response_type=code" + + "&scope=snsapi_login" + + "&state=%s" + + "#wechat_redirect"; + + //对redirect_url进行URLEnccode编码 + String redirect_url =ConstantConfig.WX_OPEN_REDIRECT_URL; + try { + redirect_url = URLEncoder.encode(redirect_url, "utf-8"); + } catch (Exception e) { + e.printStackTrace(); + } + String url =String.format( + baseUrl, + ConstantConfig.WX_OPEN_APP_ID, + ConstantConfig.WX_OPEN_APP_SECRET, + redirect_url, + "atguigu" + ); + //请求微信地址 + return url; + } } diff --git a/src/main/java/com/xkrs/dao/WorkHourRecordDao.java b/src/main/java/com/xkrs/dao/WorkHourRecordDao.java index b902a15..92dd5a5 100644 --- a/src/main/java/com/xkrs/dao/WorkHourRecordDao.java +++ b/src/main/java/com/xkrs/dao/WorkHourRecordDao.java @@ -67,7 +67,7 @@ public interface WorkHourRecordDao extends JpaRepository, J * @param userId * @return */ - @Query(value = "select * from work_hour_record where project_number = :projectNumber and user_id = :userId and color != '1'",nativeQuery = true) + @Query(value = "select * from work_hour_record where color != '1' and project_number = :projectNumber and user_id = :userId",nativeQuery = true) List findRecord(@Param("projectNumber") String projectNumber,@Param("userId") Integer userId); /** @@ -85,6 +85,7 @@ public interface WorkHourRecordDao extends JpaRepository, J * @param id */ @Modifying(clearAutomatically=true) + @Query(value = "delete from work_hour_record where id = ?",nativeQuery = true) void deleteById(Integer id); /** diff --git a/src/main/java/com/xkrs/service/SysUserService.java b/src/main/java/com/xkrs/service/SysUserService.java index 43d840e..30d914e 100644 --- a/src/main/java/com/xkrs/service/SysUserService.java +++ b/src/main/java/com/xkrs/service/SysUserService.java @@ -4,6 +4,7 @@ import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.qo.SysUserQo; import com.xkrs.model.vo.SysUserVo; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -107,7 +108,8 @@ public interface SysUserService { /** * 判断小程序账号的绑定 * @param openId + * @param response * @return */ - String findUserByOpenId(String openId); + String findUserByOpenId(String openId, HttpServletResponse response); } diff --git a/src/main/java/com/xkrs/utils/Query.java b/src/main/java/com/xkrs/utils/Query.java index 1068767..ab2df46 100644 --- a/src/main/java/com/xkrs/utils/Query.java +++ b/src/main/java/com/xkrs/utils/Query.java @@ -71,6 +71,7 @@ public class Query { if (userId != null && !"".equals(userId)) { list.add(criteriaBuilder.equal(root.get("userId").as(Integer.class), userId)); } + list.add(criteriaBuilder.notEqual(root.get("color").as(String.class), "1")); if(startTime != null && !"".equals(startTime)){ list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("submitTime").as(String.class), startTime)); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8422f2e..347b22a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -79,8 +79,8 @@ my.MaxLoginErrorCount = 5 my.LoginErrorIntervalTime = 60 # 微信开放平台 appid -wx.open.app_id=你的appid +wx.open.app_id=wx545abff5921505f2 # 微信开放平台 appsecret -wx.open.app_secret=你的appsecret +wx.open.app_secret=9e485c69daa2483981fe35f74c22b5ea # 微信开放平台 重定向url -wx.open.redirect_url=http://你的服务器名称/api/ucenter/wx/callback +wx.open.redirect_url=https://api.earth-rs.com/wh/callback