|
|
@ -1,23 +1,38 @@
|
|
|
|
package jnpf.controller;
|
|
|
|
package jnpf.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import jnpf.base.ActionResult;
|
|
|
|
import jnpf.base.ActionResult;
|
|
|
|
|
|
|
|
import jnpf.base.UserInfo;
|
|
|
|
|
|
|
|
import jnpf.entity.RecycleStationStaffEntity;
|
|
|
|
|
|
|
|
import jnpf.exception.LoginException;
|
|
|
|
|
|
|
|
import jnpf.model.LoginVO;
|
|
|
|
|
|
|
|
import jnpf.model.wx.AuthUserDto;
|
|
|
|
|
|
|
|
import jnpf.model.wx.WeChatUtil;
|
|
|
|
import jnpf.model.wx.WxCheckSession;
|
|
|
|
import jnpf.model.wx.WxCheckSession;
|
|
|
|
import jnpf.model.wx.WxLoginParam;
|
|
|
|
import jnpf.service.AuthService;
|
|
|
|
|
|
|
|
import jnpf.service.RecycleStationStaffService;
|
|
|
|
import jnpf.util.wxutil.HttpUtil;
|
|
|
|
import jnpf.util.wxutil.HttpUtil;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
|
import javax.crypto.Cipher;
|
|
|
|
import javax.crypto.spec.IvParameterSpec;
|
|
|
|
import javax.crypto.spec.IvParameterSpec;
|
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.security.AlgorithmParameters;
|
|
|
|
import java.security.AlgorithmParameters;
|
|
|
|
import java.security.Key;
|
|
|
|
import java.security.Key;
|
|
|
|
import java.security.Security;
|
|
|
|
import java.security.Security;
|
|
|
|
import java.util.Base64;
|
|
|
|
import java.util.Base64;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
@ -33,6 +48,10 @@ public class WxController {
|
|
|
|
private String code2Session;
|
|
|
|
private String code2Session;
|
|
|
|
@Value("${wx.checkSession}")
|
|
|
|
@Value("${wx.checkSession}")
|
|
|
|
private String checkSession;
|
|
|
|
private String checkSession;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private RecycleStationStaffService recycleStationStaffService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private AuthService authService;
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "小程序登录-回收员端")
|
|
|
|
@Operation(summary = "小程序登录-回收员端")
|
|
|
|
@GetMapping("/hsyLogin")
|
|
|
|
@GetMapping("/hsyLogin")
|
|
|
@ -43,6 +62,82 @@ public class WxController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "小程序获取绑定的手机号-回收员端")
|
|
|
|
@Operation(summary = "小程序获取绑定的手机号-回收员端")
|
|
|
|
|
|
|
|
@PostMapping(value = "/hsyGetPhone")
|
|
|
|
|
|
|
|
public ActionResult login(@RequestBody AuthUserDto authUserDto, HttpServletRequest request) {
|
|
|
|
|
|
|
|
//String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appid + "&secret=" + appsecret + "&js_code=" + authUserDto.getCode() + "&grant_type=authorization_code";
|
|
|
|
|
|
|
|
String url = code2Session+"?appid="+appid+"&secret="+appsecret+"&js_code="+authUserDto.getCode()+"&grant_type=authorization_code";
|
|
|
|
|
|
|
|
String loginResult = HttpUtil.sendHttpGet(url);
|
|
|
|
|
|
|
|
JSONObject loginResultObject = JSONObject.parseObject(loginResult);
|
|
|
|
|
|
|
|
// 登录失败
|
|
|
|
|
|
|
|
/*if(null != loginResultObject.get("errcode")){
|
|
|
|
|
|
|
|
return loginResult;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
// 登录成功
|
|
|
|
|
|
|
|
//String sessionKey = (String) loginResultObject.get("session_key");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*String str = WeChatUtil.httpRequest(url, "GET", null);
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(str);
|
|
|
|
|
|
|
|
//wxMiniApi.authCode2Session(appId, secret, authUserDto.getCode());
|
|
|
|
|
|
|
|
if (jsonObject == null) {
|
|
|
|
|
|
|
|
throw new RuntimeException("调用微信端授权认证接口错误");
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
String openId = (String) loginResultObject.get("openid");
|
|
|
|
|
|
|
|
String sessionKey = (String) loginResultObject.get("session_key");
|
|
|
|
|
|
|
|
String unionId = (String) loginResultObject.get("union_id");
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(openId)) {
|
|
|
|
|
|
|
|
return ActionResult.fail(loginResultObject.getInteger("errcode"), loginResultObject.getString("errmsg"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
authUserDto.setOpenId(openId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断用户表中是否存在该用户,不存在则进行解密得到用户信息,并进行新增用户
|
|
|
|
|
|
|
|
QueryWrapper<RecycleStationStaffEntity> queryWrapper=new QueryWrapper<>();
|
|
|
|
|
|
|
|
queryWrapper.lambda().eq(RecycleStationStaffEntity::getOpenid,openId);
|
|
|
|
|
|
|
|
RecycleStationStaffEntity recycleStationStaffEntity = recycleStationStaffService.getOne(queryWrapper);
|
|
|
|
|
|
|
|
UserInfo userInfo2 = new UserInfo();
|
|
|
|
|
|
|
|
if(recycleStationStaffEntity == null){
|
|
|
|
|
|
|
|
String userInfo = WeChatUtil.decryptData(authUserDto.getEncryptedData(), sessionKey, authUserDto.getIv());
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(userInfo)) {
|
|
|
|
|
|
|
|
throw new RuntimeException("解密用户信息错误");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject userObject = JSONObject.parseObject(userInfo);
|
|
|
|
|
|
|
|
String phoneNumber = (String) userObject.get("phoneNumber");
|
|
|
|
|
|
|
|
userInfo2.setUserAccount(phoneNumber);
|
|
|
|
|
|
|
|
RecycleStationStaffEntity user = new RecycleStationStaffEntity();
|
|
|
|
|
|
|
|
user.setMobilePhone(phoneNumber);
|
|
|
|
|
|
|
|
user.setStaffsName(phoneNumber);
|
|
|
|
|
|
|
|
user.setOpenid(openId);
|
|
|
|
|
|
|
|
//user.setUnionId(unionId);
|
|
|
|
|
|
|
|
recycleStationStaffService.create(user);
|
|
|
|
|
|
|
|
authUserDto.setUserInfo(user);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
authUserDto.setUserInfo(recycleStationStaffEntity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
|
|
|
map.put("account", "admin");
|
|
|
|
|
|
|
|
map.put("password", "e10adc3949ba59abbe56e057f20f883e");
|
|
|
|
|
|
|
|
map.put("grant_type", "password");
|
|
|
|
|
|
|
|
String token = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ActionResult<LoginVO> loginVOActionResult = authService.login(map);
|
|
|
|
|
|
|
|
token = loginVOActionResult.getData().getToken();
|
|
|
|
|
|
|
|
} catch (LoginException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//创建token
|
|
|
|
|
|
|
|
//StpUtil.login("349057407209541");
|
|
|
|
|
|
|
|
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
|
|
|
|
|
|
|
//String token = StpUtil.login();
|
|
|
|
|
|
|
|
//userInfo.setToken(StpUtil.getTokenValueNotCut());
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(token)) {
|
|
|
|
|
|
|
|
throw new RuntimeException("生成token错误");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
authUserDto.setToken(token);
|
|
|
|
|
|
|
|
return ActionResult.success(authUserDto);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*@Operation(summary = "小程序获取绑定的手机号-回收员端")
|
|
|
|
@PostMapping("/hsyGetPhone")
|
|
|
|
@PostMapping("/hsyGetPhone")
|
|
|
|
public String hsyGetPhone(@RequestBody WxLoginParam wxLoginParam) {
|
|
|
|
public String hsyGetPhone(@RequestBody WxLoginParam wxLoginParam) {
|
|
|
|
// todo
|
|
|
|
// todo
|
|
|
@ -60,7 +155,7 @@ public class WxController {
|
|
|
|
JSONObject decrypt = decrypt(sessionKey,wxLoginParam.getEncryptedData(), wxLoginParam.getIv());
|
|
|
|
JSONObject decrypt = decrypt(sessionKey,wxLoginParam.getEncryptedData(), wxLoginParam.getIv());
|
|
|
|
decrypt.put("sessionKey",sessionKey);
|
|
|
|
decrypt.put("sessionKey",sessionKey);
|
|
|
|
return decrypt.toString();
|
|
|
|
return decrypt.toString();
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "小程序登录态校验-回收员端")
|
|
|
|
@Operation(summary = "小程序登录态校验-回收员端")
|
|
|
|
@GetMapping("/hsyCheckSession")
|
|
|
|
@GetMapping("/hsyCheckSession")
|
|
|
|