|
|
@@ -13,8 +13,10 @@ import com.template.common.constanst.Constanst;
|
|
|
import com.template.common.result.ResponseStatusEnum;
|
|
|
import com.template.common.utils.*;
|
|
|
import com.template.model.evaluate.student.SmartEvaluateStudent;
|
|
|
+import com.template.model.evaluate.student.SmartSubjectManage;
|
|
|
import com.template.model.pojo.SmartAuthority;
|
|
|
import com.template.model.pojo.SmartUser;
|
|
|
+import com.template.model.pojo.SmsCode;
|
|
|
import com.template.model.result.CommonResult;
|
|
|
import com.template.model.result.PageUtils;
|
|
|
import com.template.model.tongji.*;
|
|
|
@@ -22,10 +24,7 @@ import com.template.model.vo.LoginVO;
|
|
|
import com.template.model.weixin.AccessToken;
|
|
|
import com.template.model.weixin.HttpParame;
|
|
|
import com.template.model.weixin.WechatUserUnionID;
|
|
|
-import com.template.services.SmartAuthorGroupService;
|
|
|
-import com.template.services.SmartAuthorityService;
|
|
|
-import com.template.services.SmartUserService;
|
|
|
-import com.template.services.WechatScanLoginService;
|
|
|
+import com.template.services.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
@@ -39,6 +38,7 @@ import java.io.UnsupportedEncodingException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.ParseException;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -61,6 +61,8 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
|
|
|
public SmartAuthorityService smartAuthorityService;
|
|
|
@Autowired
|
|
|
public SmartAuthorGroupService smartAuthorGroupService;
|
|
|
+ @Autowired
|
|
|
+ public SmsCodeService smsCodeService;
|
|
|
|
|
|
/**
|
|
|
* Title: list
|
|
|
@@ -131,11 +133,11 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
|
|
|
*/
|
|
|
@Override
|
|
|
@PassToken
|
|
|
- public String bindUserMac(String cardNo) throws UnsupportedEncodingException {
|
|
|
- if (StringUtils.isBlank(cardNo)){
|
|
|
- return "redirect:"+HttpParame.FRONT_URI+"/#/login?message=" + URLEncoder.encode("请绑定信息", "UTF-8");
|
|
|
+ public String bindUserMac(String phone,String messageCode) throws UnsupportedEncodingException {
|
|
|
+ if (StringUtils.isBlank(phone) || StringUtils.isBlank(messageCode)){
|
|
|
+ return "redirect:"+HttpParame.FRONT_URI+"/#/login?message=" + URLEncoder.encode("请输入信息", "UTF-8");
|
|
|
}
|
|
|
- Map<String, String> wechatLoginUrl = wechatScanLoginService.wechatBindUrl(cardNo);
|
|
|
+ Map<String, String> wechatLoginUrl = wechatScanLoginService.wechatBindUrl(phone,messageCode);
|
|
|
String url = wechatLoginUrl.get("url");
|
|
|
System.out.println(url);
|
|
|
return "redirect:" + url;
|
|
|
@@ -143,8 +145,8 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
|
|
|
|
|
|
@Override
|
|
|
@PassToken
|
|
|
- public String bindcallback(String code, String state, String cardNo) throws UnsupportedEncodingException {
|
|
|
- System.out.println(code+"==="+state+"=="+cardNo);
|
|
|
+ public String bindcallback(String code, String state, String phone,String messageCode) throws UnsupportedEncodingException {
|
|
|
+ System.out.println(code+"==="+state+"=="+messageCode);
|
|
|
if (code != null && state != null) {
|
|
|
// 验证state为了用于防止跨站请求伪造攻击
|
|
|
String decrypt = AesUtil.decrypt(AesUtil.parseHexStr2Byte(state), AesUtil.PASSWORD_SECRET_KEY, 16);
|
|
|
@@ -154,25 +156,31 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
|
|
|
AccessToken access = wechatScanLoginService.getAccessToken(code);
|
|
|
if (access != null) {
|
|
|
String openid = access.getOpenid();
|
|
|
- /*SmartUser user = wechatScanLoginService.selectByOpenid(openid);
|
|
|
- if (user!=null) { *//*不存在*//*
|
|
|
- return "redirect:"+HttpParame.FRONT_URI+"/#/login?message=" + URLEncoder.encode("该卡号已绑定其他用户", "UTF-8");
|
|
|
- }*/
|
|
|
- SmartUser userc = wechatScanLoginService.selectByCardNo(cardNo);
|
|
|
- if (userc==null){
|
|
|
- return "redirect:"+HttpParame.FRONT_URI+"/#/login?message=" + URLEncoder.encode("卡号信息错误", "UTF-8");
|
|
|
+ QueryWrapper<SmsCode> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.eq("deleted", 0);
|
|
|
+ queryWrapper1.eq("is_verify",0);
|
|
|
+ queryWrapper1.eq("phone_number",phone);
|
|
|
+ queryWrapper1.eq("code",code);
|
|
|
+ queryWrapper1.ge("expiration_time", new Date());
|
|
|
+ List<SmsCode> listc = smsCodeService.getSmsCodeByKey(queryWrapper1);
|
|
|
+ if (listc.isEmpty()){
|
|
|
+ return "redirect:"+HttpParame.FRONT_URI+"/#/login?message=" + URLEncoder.encode("验证码已失效", "UTF-8");
|
|
|
}
|
|
|
- if (userc.getOpenId()!=null){
|
|
|
- return "redirect:"+HttpParame.FRONT_URI+"/#/login?message=" + URLEncoder.encode("该卡号已绑定其他用户", "UTF-8");
|
|
|
+ QueryWrapper<SmartUser> queryWrapper2 = new QueryWrapper<>();
|
|
|
+ queryWrapper2.eq("deleted", 0);
|
|
|
+ queryWrapper2.eq("phone", phone);
|
|
|
+ List<SmartUser> userc = smartUserService.list(queryWrapper2);
|
|
|
+ if (userc.isEmpty()){
|
|
|
+ return "redirect:"+HttpParame.FRONT_URI+"/#/login?message=" + URLEncoder.encode("用户不存在", "UTF-8");
|
|
|
}
|
|
|
- userc.setOpenId(openid);
|
|
|
- int m = wechatScanLoginService.updateSmartUser(userc);
|
|
|
+ userc.get(0).setOpenId(openid);
|
|
|
+ int m = wechatScanLoginService.updateSmartUser(userc.get(0));
|
|
|
if (m>0){
|
|
|
- String token = JWTUtil.getToken(userc);
|
|
|
- QueryWrapper<SmartAuthority> queryWrapper1 = new QueryWrapper<>();
|
|
|
- queryWrapper1.eq("deleted", 0);
|
|
|
- queryWrapper1.eq("user_id", userc.getId());
|
|
|
- List<SmartAuthority> query = smartAuthorityService.getAuthorByKey(queryWrapper1);
|
|
|
+ String token = JWTUtil.getToken(userc.get(0));
|
|
|
+ QueryWrapper<SmartAuthority> queryWrapper3 = new QueryWrapper<>();
|
|
|
+ queryWrapper3.eq("deleted", 0);
|
|
|
+ queryWrapper3.eq("user_id", userc.get(0).getId());
|
|
|
+ List<SmartAuthority> query = smartAuthorityService.getAuthorByKey(queryWrapper3);
|
|
|
if (query.size()>0){
|
|
|
return "redirect:"+HttpParame.FRONT_URI+"/#/wanzai/home?token=" + token;
|
|
|
} else {
|
|
|
@@ -324,6 +332,93 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
|
|
|
String token = JWTUtil.getToken(user);
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("token", token);
|
|
|
+ jsonObject.put("user", user);
|
|
|
return CommonResult.ok(jsonObject.toString());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @PassToken
|
|
|
+ public CommonResult sendMessage(String phone){
|
|
|
+ QueryWrapper<SmartUser> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.eq("deleted", 0);
|
|
|
+ queryWrapper1.eq("phone",phone);
|
|
|
+ queryWrapper1.eq("is_cancel",0);
|
|
|
+ List<SmartUser> list = smartUserService.list(queryWrapper1);
|
|
|
+ if (list.isEmpty()){
|
|
|
+ return CommonResult.fail("该手机无权限登录");
|
|
|
+ }
|
|
|
+ QueryWrapper<SmsCode> queryWrapper2 = new QueryWrapper<>();
|
|
|
+ queryWrapper2.eq("deleted", 0);
|
|
|
+ queryWrapper2.eq("is_verify",0);
|
|
|
+ queryWrapper2.eq("phone_number",phone);
|
|
|
+ queryWrapper2.ge("expiration_time", new Date());
|
|
|
+ List<SmsCode> listc = smsCodeService.getSmsCodeByKey(queryWrapper2);
|
|
|
+ if (!listc.isEmpty()){
|
|
|
+ return CommonResult.fail("操作频繁,请稍后再试");
|
|
|
+ }
|
|
|
+ String code = GetVertifyCode.getRandomNumCode(6);
|
|
|
+ SmsCode smsCode = new SmsCode();
|
|
|
+ smsCode.setId(UUIDUtil.generateID());
|
|
|
+ smsCode.setPhoneNumber(phone);
|
|
|
+ smsCode.setCode(code);
|
|
|
+ long time = new Date().getTime() + 60000L;
|
|
|
+ smsCode.setExpirationTime(new Date(time));
|
|
|
+ smsCode.setIsVerify("0");
|
|
|
+ smsCode.setDeleted(0);
|
|
|
+ int m = smsCodeService.insertSmsCode(smsCode);
|
|
|
+ if (m>0){
|
|
|
+ String message = SendSms.sendSms(phone, code);
|
|
|
+ if (message.contains("success")){
|
|
|
+ return CommonResult.ok("发送成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return CommonResult.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @PassToken
|
|
|
+ public CommonResult vertifyMessage(String phone,String code, String wxcode){
|
|
|
+ QueryWrapper<SmsCode> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.eq("deleted", 0);
|
|
|
+ queryWrapper1.eq("is_verify",0);
|
|
|
+ queryWrapper1.eq("phone_number",phone);
|
|
|
+ queryWrapper1.eq("code",code);
|
|
|
+ queryWrapper1.ge("expiration_time", new Date());
|
|
|
+ List<SmsCode> listc = smsCodeService.getSmsCodeByKey(queryWrapper1);
|
|
|
+ if (listc.isEmpty()){
|
|
|
+ return CommonResult.ok("验证码已失效");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(wxcode)){
|
|
|
+ return CommonResult.fail("请传入wxcode");
|
|
|
+ }
|
|
|
+ String url = "https://api.weixin.qq.com/sns/jscode2session?" +
|
|
|
+ "appid=" + PropertiesUtil.getValue(HttpParame.APPID) +
|
|
|
+ "&secret=" + PropertiesUtil.getValue(HttpParame.SECRET) +
|
|
|
+ "&js_code=" + wxcode +
|
|
|
+ "&grant_type=authorization_code";
|
|
|
+
|
|
|
+ String json = HttpClientUtils.getInstance().sendHttpGet(url);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ HashMap<String, String> userMap = gson.fromJson(json.toString(), new TypeToken<HashMap<String, String>>() {}.getType());
|
|
|
+ String openid = "";
|
|
|
+ try {
|
|
|
+ openid = userMap.get("openid").toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ return CommonResult.fail("code异常");
|
|
|
+ }
|
|
|
+ QueryWrapper<SmartUser> queryWrapper2 = new QueryWrapper<>();
|
|
|
+ queryWrapper2.eq("deleted", 0);
|
|
|
+ queryWrapper2.eq("phone", phone);
|
|
|
+ List<SmartUser> user = smartUserService.list(queryWrapper2);
|
|
|
+ if (user.isEmpty()){
|
|
|
+ return CommonResult.fail("该用户不存在");
|
|
|
+ }
|
|
|
+ user.get(0).setOpenId(openid);
|
|
|
+ smartUserService.updateSmartUser(user.get(0));
|
|
|
+ String token = JWTUtil.getToken(user.get(0));
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("token", token);
|
|
|
+ jsonObject.put("user", user.get(0));
|
|
|
+ return CommonResult.ok(jsonObject);
|
|
|
+ }
|
|
|
}
|