|
@@ -5,6 +5,7 @@ import cn.hutool.http.HttpUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.extension.api.R;
|
|
import com.huimv.receive.common.exception.ExceptionEnum;
|
|
import com.huimv.receive.common.exception.ExceptionEnum;
|
|
import com.huimv.receive.common.exception.MiException;
|
|
import com.huimv.receive.common.exception.MiException;
|
|
import com.huimv.receive.common.token.TokenSign;
|
|
import com.huimv.receive.common.token.TokenSign;
|
|
@@ -267,59 +268,27 @@ public class LoginController {
|
|
|
|
|
|
@GetMapping("/logWeChatGetPhone")
|
|
@GetMapping("/logWeChatGetPhone")
|
|
public Result logWeChatGetPhone(HttpServletRequest req, @RequestParam String jsCode) {
|
|
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);
|
|
|
|
|
|
+ String access_token ="";
|
|
|
|
+ if ( !redisTemplate.hasKey("weChatGetPhone") || redisTemplate.getExpire("weChatGetPhone") ==null || redisTemplate.getExpire("weChatGetPhone") <=0){
|
|
|
|
+ String result = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token?appid=wxa28e45fe5cb10ff1&secret=c16e584ec6e69fd35edd98ec21ec5e94&grant_type=client_credential");
|
|
|
|
+ System.out.println(result);
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
|
+ access_token = (String) jsonObject.get("access_token");
|
|
|
|
+ redisTemplate.opsForValue().set("weChatGetPhone",access_token);
|
|
|
|
+ redisTemplate.expire("weChatGetPhone",7200,TimeUnit.SECONDS);
|
|
|
|
+ }else {
|
|
|
|
+ access_token = redisTemplate.opsForValue().get("weChatGetPhone");
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
|
|
|
- paramsMap.put("appid", "wxa28e45fe5cb10ff1");
|
|
|
|
- paramsMap.put("secret", "c16e584ec6e69fd35edd98ec21ec5e94");
|
|
|
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
+ paramsMap.put("code", jsCode);
|
|
|
|
+ String resultPhone = HttpUtil.post("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+access_token, paramsMap);
|
|
|
|
+ System.out.println(resultPhone);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,JSON.parseObject(resultPhone));
|
|
|
|
+ }
|
|
|
|
|
|
- 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")
|
|
@PostMapping("/register")
|
|
public Result addAdmission(HttpServletRequest req, @RequestParam("userName") String userName,
|
|
public Result addAdmission(HttpServletRequest req, @RequestParam("userName") String userName,
|