派生自 projectDept/qhighschool

yn147
2023-04-12 f0f58829c5c8dd9b249f594526f01fa957cbdd59
src/main/java/com/qxueyou/scc/sys/action/LoginController.java
@@ -1,5 +1,6 @@
package com.qxueyou.scc.sys.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -9,10 +10,16 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.alibaba.fastjson.JSONObject;
import com.qxueyou.scc.base.util.*;
import com.qxueyou.scc.wx.service.IWechatService;
import freemarker.template.utility.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.common.network.LoginType;
import org.apache.tomcat.util.net.openssl.ciphers.Authentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
@@ -95,8 +102,72 @@
    @Autowired
    private IOrganizationService organizationService;
   /**
    * 小程序appID
    */
   @Value("${wx.appId}")
   private String appId;
   /**
    * 小程序secret
    */
   @Value("${wx.secret}")
   private String secret;
    public static String UUNUMBER="QXYUUNUMBER";
   @Autowired
   IWechatService wechatService;
   /**
    * 微信登录
    *
    * @param uid
    * @throws IOException
    */
   @PostMapping("/wxlogin")
   @ApiOperation("微信登录")
   @ResponseBody
   public Result wechatLogin(String code,String number) {
      JSONObject sessionKeyOrOpenId = wechatService.getSessionKeyOrOpenId(code);
      JSONObject gettoken = wechatService.gettoken(appId, secret);
      Result phone = wechatService.getNumber(gettoken.get("access_token").toString(), number);
      if(phone.getSuccess()){
         String hql = "from User where deleteFlag is false and mobilePhone = ? ";
         System.out.println(phone.getData());
         List<Object> params =  CollectionUtils.newList(phone.getData());
         User user = commonDAO.findUnique(hql,params, User.class);
         if(user==null){
            //新增用户
            User user1=new User();
            user1.setMobilePhone(phone.getData().toString());
            user1.setOpenId(sessionKeyOrOpenId.get("openid").toString());
            commonDAO.save(user1);
            //新增关联学员
            String addUserSql = "from User where deleteFlag is false and mobilePhone = ? ";
            List<Object> newParams =  CollectionUtils.newList(phone.getData());
            User newUser = commonDAO.findUnique(addUserSql,newParams, User.class);
            StuStudent stuStudent=new StuStudent();
            stuStudent.setStatus(StuStudent.STATUS_REGISTER);
            stuStudent.setUserId(newUser.getUserId());
            stuStudent.setMobilePhone(newUser.getMobilePhone());
            commonDAO.save(stuStudent);
         }
         if(StringUtils.isEmpty(user.getOpenId())){
            user.setOpenId(sessionKeyOrOpenId.get("openid").toString());
            commonDAO.saveOrUpdate(user);
         }
         String studentSql = "from StuStudent where deleteFlag is false and userId = ? ";
         List<Object> stuParams =  CollectionUtils.newList(user.getUserId());
         StuStudent stuStudent = commonDAO.findUnique(studentSql, stuParams, StuStudent.class);
         return new Result(true,"授权成功",CollectionUtils.newObjectMap("user",user,"ClassId",stuStudent.getClassId()));
      }
      return phone;
}
   @ApiOperation(value = "登入接口", notes = "")
   @ApiImplicitParams({
         @ApiImplicitParam(name = "account", value = "账号", required = true, paramType="query", dataType = "String"),