|
|
|
@ -1,15 +1,13 @@
|
|
|
|
|
package com.zh.project0512.controller.wxApp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
import com.zh.project0512.annotation.TokenValid;
|
|
|
|
|
import com.zh.project0512.model.User;
|
|
|
|
|
import com.zh.project0512.service.IUserService;
|
|
|
|
|
import com.zh.project0512.utils.CoderUtil;
|
|
|
|
|
import com.zh.project0512.utils.JwtUtil;
|
|
|
|
|
import com.zh.project0512.utils.MybatisPlusUtil;
|
|
|
|
|
import com.zh.project0512.utils.WeChatUtil;
|
|
|
|
|
import com.zh.project0512.utils.*;
|
|
|
|
|
import com.zh.project0512.utils.result.HttpStatusEnum;
|
|
|
|
|
import com.zh.project0512.utils.result.Result;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
@ -39,7 +37,8 @@ public class UserUController {
|
|
|
|
|
private IUserService userService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private WeChatUtil weChatUtil;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private HttpUtil httpUtil;
|
|
|
|
|
@Operation(summary = "小程序登录", parameters = {@Parameter(name = "code", description = "login返回的code(未使用过!)")})
|
|
|
|
|
@PostMapping("/login")
|
|
|
|
|
public Result login(@RequestBody @Parameter(hidden = true) JSONObject obj) {
|
|
|
|
@ -91,6 +90,23 @@ public class UserUController {
|
|
|
|
|
u.setToken(new JwtUtil().createJWT(openid));
|
|
|
|
|
// u.setToken(new JwtUtils().generateToken(openid, new Date().getTime()));
|
|
|
|
|
u.setCreatAt(LocalDateTime.now());
|
|
|
|
|
|
|
|
|
|
// 用户企业微信信息获取
|
|
|
|
|
String access_token = httpUtil.qywxGetToken();
|
|
|
|
|
JSONObject qywxRes = httpUtil.qywxUserSession(access_token, obj.getString("code"));
|
|
|
|
|
String userid = qywxRes.getString("userid");
|
|
|
|
|
JSONObject res1 = httpUtil.qywxUser(access_token, userid);
|
|
|
|
|
Integer main_department = res1.getInteger("main_department");
|
|
|
|
|
JSONArray department = res1.getJSONArray("department");
|
|
|
|
|
|
|
|
|
|
if (null == userid || null == main_department) {
|
|
|
|
|
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "获取企业用户信息失败");
|
|
|
|
|
}
|
|
|
|
|
Integer sub_department = main_department;
|
|
|
|
|
if (sub_department != null && sub_department != 1 && sub_department != 0) {
|
|
|
|
|
sub_department = httpUtil.qywxDepartmentParentid(access_token, main_department, 0);
|
|
|
|
|
}
|
|
|
|
|
u.setMain_department(main_department).setSub_department(sub_department);
|
|
|
|
|
userService.save(u);
|
|
|
|
|
return Result.success(u);
|
|
|
|
|
}
|
|
|
|
|