添加了扫码登录和获取用户信息的接口
This commit is contained in:
parent
c5dee2529f
commit
7a234f619e
2
pom.xml
2
pom.xml
@ -9,7 +9,7 @@
|
|||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.xkrs</groupId>
|
<groupId>com.xkrs</groupId>
|
||||||
<artifactId>xkrs_work</artifactId>
|
<artifactId>work_management</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>xkrs_work</name>
|
<name>xkrs_work</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
|
@ -2,10 +2,12 @@ package com.xkrs.common.config;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author XinYi Song
|
* @author XinYi Song
|
||||||
*/
|
*/
|
||||||
|
@Component
|
||||||
public class ConstantConfig implements InitializingBean {
|
public class ConstantConfig implements InitializingBean {
|
||||||
|
|
||||||
@Value("${wx.open.app_id}")
|
@Value("${wx.open.app_id}")
|
||||||
|
@ -45,8 +45,13 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.antMatchers(HttpMethod.POST,"/importCvProjectExcel").permitAll()
|
.antMatchers(HttpMethod.POST,"/importCvProjectExcel").permitAll()
|
||||||
.antMatchers(HttpMethod.GET,"/excelOutWork").permitAll()
|
.antMatchers(HttpMethod.GET,"/excelOutWork").permitAll()
|
||||||
.antMatchers(HttpMethod.GET,"/selectMemberAndWorkHour").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/findUserByOpenId").permitAll()
|
||||||
.antMatchers(HttpMethod.POST,"/api/user/updateOpenIdByPhone").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()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
|
@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -96,4 +97,41 @@ public class WeChatController {
|
|||||||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"操作失败!",locale);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public interface WorkHourRecordDao extends JpaRepository<WorkHourRecord,Long>, J
|
|||||||
* @param userId
|
* @param userId
|
||||||
* @return
|
* @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<WorkHourRecord> findRecord(@Param("projectNumber") String projectNumber,@Param("userId") Integer userId);
|
List<WorkHourRecord> findRecord(@Param("projectNumber") String projectNumber,@Param("userId") Integer userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,6 +85,7 @@ public interface WorkHourRecordDao extends JpaRepository<WorkHourRecord,Long>, J
|
|||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
@Modifying(clearAutomatically=true)
|
@Modifying(clearAutomatically=true)
|
||||||
|
@Query(value = "delete from work_hour_record where id = ?",nativeQuery = true)
|
||||||
void deleteById(Integer id);
|
void deleteById(Integer id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ import com.xkrs.model.entity.SysUserEntity;
|
|||||||
import com.xkrs.model.qo.SysUserQo;
|
import com.xkrs.model.qo.SysUserQo;
|
||||||
import com.xkrs.model.vo.SysUserVo;
|
import com.xkrs.model.vo.SysUserVo;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +108,8 @@ public interface SysUserService {
|
|||||||
/**
|
/**
|
||||||
* 判断小程序账号的绑定
|
* 判断小程序账号的绑定
|
||||||
* @param openId
|
* @param openId
|
||||||
|
* @param response
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String findUserByOpenId(String openId);
|
String findUserByOpenId(String openId, HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@ public class Query {
|
|||||||
if (userId != null && !"".equals(userId)) {
|
if (userId != null && !"".equals(userId)) {
|
||||||
list.add(criteriaBuilder.equal(root.get("userId").as(Integer.class), 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)){
|
if(startTime != null && !"".equals(startTime)){
|
||||||
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("submitTime").as(String.class), startTime));
|
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("submitTime").as(String.class), startTime));
|
||||||
}
|
}
|
||||||
|
@ -79,8 +79,8 @@ my.MaxLoginErrorCount = 5
|
|||||||
my.LoginErrorIntervalTime = 60
|
my.LoginErrorIntervalTime = 60
|
||||||
|
|
||||||
# 微信开放平台 appid
|
# 微信开放平台 appid
|
||||||
wx.open.app_id=你的appid
|
wx.open.app_id=wx545abff5921505f2
|
||||||
# 微信开放平台 appsecret
|
# 微信开放平台 appsecret
|
||||||
wx.open.app_secret=你的appsecret
|
wx.open.app_secret=9e485c69daa2483981fe35f74c22b5ea
|
||||||
# 微信开放平台 重定向url
|
# 微信开放平台 重定向url
|
||||||
wx.open.redirect_url=http://你的服务器名称/api/ucenter/wx/callback
|
wx.open.redirect_url=https://api.earth-rs.com/wh/callback
|
||||||
|
Loading…
Reference in New Issue
Block a user