|
@@ -4,12 +4,14 @@ import cn.hutool.core.util.CharsetUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.aliyun.oss.common.utils.StringUtils;
|
|
|
import com.ynfy.app.api.v1.annoation.IgnoreAuth;
|
|
|
+import com.ynfy.app.api.v1.entity.dto.UserInfo;
|
|
|
+import com.ynfy.app.api.v1.entity.dto.WxLoginDTO;
|
|
|
import com.ynfy.app.api.v1.util.ApiUserUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.constant.CommonConstant;
|
|
|
import org.jeecg.common.system.util.JwtUtil;
|
|
@@ -166,14 +168,18 @@ public class ApiAuthController {
|
|
|
*/
|
|
|
@ApiOperation(value = "微信登录")
|
|
|
@IgnoreAuth
|
|
|
- @GetMapping("loginByWx")
|
|
|
- public Result<?> loginByWeixin(@RequestParam String code) {
|
|
|
+ @PostMapping("loginByWx")
|
|
|
+ public Result<?> loginByWeixin(@RequestBody WxLoginDTO dto) {
|
|
|
+ if (StringUtils.isBlank(dto.getCode())) {
|
|
|
+ return Result.error("code不能为空");
|
|
|
+ }
|
|
|
+ UserInfo userInfo = dto.getUserInfo();
|
|
|
//获取openid
|
|
|
- String requestUrl = ApiUserUtils.getWebAccess(code);//通过自定义工具类组合出小程序需要的登录凭证 code
|
|
|
+ String requestUrl = ApiUserUtils.getWebAccess(dto.getCode());//通过自定义工具类组合出小程序需要的登录凭证 code
|
|
|
log.info("》》》组合token为:" + requestUrl);
|
|
|
JSONObject sessionData = JSON.parseObject(HttpUtil.get(requestUrl, CharsetUtil.CHARSET_UTF_8));
|
|
|
|
|
|
- if (Objects.isNull(sessionData) || StringUtils.isNullOrEmpty(sessionData.getString("openid"))) {
|
|
|
+ if (Objects.isNull(sessionData) || StringUtils.isBlank(sessionData.getString("openid"))) {
|
|
|
return Result.error("登录失败");
|
|
|
}
|
|
|
String openId = sessionData.getString("openid");
|
|
@@ -191,7 +197,13 @@ public class ApiAuthController {
|
|
|
wxUser.setStatus(1);
|
|
|
wxUser.setDelFlag(CommonConstant.DEL_FLAG_0);
|
|
|
wxUser.setOpenId(openId);
|
|
|
+ wxUser.setAvatar(!Objects.isNull(userInfo) ? userInfo.getAvatarUrl() : null);
|
|
|
+ wxUser.setRealname(!Objects.isNull(userInfo) ? userInfo.getNickName() : null);
|
|
|
sysUserService.save(wxUser);
|
|
|
+ } else {
|
|
|
+ wxUser.setAvatar(!Objects.isNull(userInfo) ? userInfo.getAvatarUrl() : null);
|
|
|
+ wxUser.setRealname(!Objects.isNull(userInfo) ? userInfo.getNickName() : null);
|
|
|
+ sysUserService.updateById(wxUser);
|
|
|
}
|
|
|
Result<JSONObject> result = new Result<JSONObject>();
|
|
|
Map<String, Object> map = new HashMap();
|