|
@@ -265,6 +265,62 @@ public class LoginController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/logWeChatGetPhone")
|
|
|
+ public Result logWeChatGetPhone(HttpServletRequest req, @RequestParam String jsCode) {
|
|
|
+ String remoteHost = req.getRemoteHost();
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("appid", "wxa28e45fe5cb10ff1");
|
|
|
+ paramsMap.put("secret", "c16e584ec6e69fd35edd98ec21ec5e94");
|
|
|
+
|
|
|
+ paramsMap.put("grant_type", "grant_type");
|
|
|
+ String result = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", paramsMap);
|
|
|
+ System.out.println(result);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ System.out.println(jsonObject);
|
|
|
+ String openid = (String) jsonObject.get("openid");
|
|
|
+ String sessionKey = (String) jsonObject.get("session_key");
|
|
|
+ System.out.println("拿到了openid" + openid);
|
|
|
+ System.out.println("拿到了sessionKey" + sessionKey);
|
|
|
+ QueryWrapper<SysAccountMultilevel> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("wechat_id", openid);
|
|
|
+ SysAccountMultilevel data = accountMultilevelService.getOne(queryWrapper);
|
|
|
+ WeCahtVo weCahtVo = new WeCahtVo();
|
|
|
+ weCahtVo.setOpenId(openid);
|
|
|
+ weCahtVo.setSessionKey(sessionKey);
|
|
|
+ if (ObjectUtil.isEmpty(data)) {
|
|
|
+ return new Result(ResultCode.FAIL, weCahtVo);
|
|
|
+ } else {
|
|
|
+ AccessToken accessToken = new AccessToken();
|
|
|
+ accessToken.setSysAccountMultilevel(data);
|
|
|
+ accessToken.setAccountName(data.getAccount());
|
|
|
+ accessToken.setUserName(data.getUserName());
|
|
|
+ accessToken.setFarmId(data.getFarmIds());
|
|
|
+ accessToken.setType(data.getType());
|
|
|
+ accessToken.setId(data.getId());
|
|
|
+ String token = TokenSign.sign(data.getUserName(), data.getId(), data.getFarmIds(), data.getWorkLocationType(), 7);
|
|
|
+ accessToken.setToken(token);
|
|
|
+ Integer lastFarmId = data.getLastFarmId();
|
|
|
+ if (ObjectUtil.isEmpty(lastFarmId)) {
|
|
|
+ lastFarmId = Integer.parseInt(data.getFarmIds().split(",")[0]);
|
|
|
+ }
|
|
|
+ accessToken.setLastFarmId(lastFarmId);
|
|
|
+ accessToken.setLoginIp(remoteHost);
|
|
|
+ return new Result(ResultCode.SUCCESS, accessToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+
|
|
|
+ paramsMap.put("appid", "wxa28e45fe5cb10ff1");
|
|
|
+ paramsMap.put("secret", "c16e584ec6e69fd35edd98ec21ec5e94");
|
|
|
+
|
|
|
+ paramsMap.put("grant_type", "grant_type");
|
|
|
+ String result = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", paramsMap);
|
|
|
+ System.out.println(result);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/register")
|
|
|
public Result addAdmission(HttpServletRequest req, @RequestParam("userName") String userName,
|
|
|
@RequestParam("phone") String phone,
|