|
@@ -13,6 +13,7 @@ import com.miaxis.common.enums.StudentLoginTypeEnum;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.common.utils.ServletUtils;
|
|
|
+import com.miaxis.common.utils.http.HttpUtils;
|
|
|
import com.miaxis.framework.web.service.SysLoginService;
|
|
|
import com.miaxis.framework.web.service.SysPermissionService;
|
|
|
import com.miaxis.framework.web.service.TokenService;
|
|
@@ -33,13 +34,17 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
/**
|
|
@@ -212,21 +217,28 @@ public class SysLoginController
|
|
|
@ApiOperation("抖音用户授权码模式登录")
|
|
|
public Response<TokenDTO> loginByDyAuthorizationCode(String authorizationCode ){
|
|
|
DyTokenDTO dyTokenDTO = new DyTokenDTO();
|
|
|
- dyTokenDTO.setGrantType("authorization_code");
|
|
|
- dyTokenDTO.setClientKey(dyappid);
|
|
|
- dyTokenDTO.setClientSecret(dyappSecret);
|
|
|
- dyTokenDTO.setCode(authorizationCode);
|
|
|
- String dyResultStr = dyService.getDyToken(dyTokenDTO);
|
|
|
+ MultiValueMap<String,Object> paramsMap = new LinkedMultiValueMap<String,Object>();
|
|
|
+ paramsMap.add("grant_type","authorization_code");
|
|
|
+ paramsMap.add("client_secret",dyappSecret);
|
|
|
+ paramsMap.add("code",authorizationCode);
|
|
|
+ paramsMap.add("client_key",dyappid);
|
|
|
+// dyTokenDTO.setGrantType("authorization_code");
|
|
|
+// dyTokenDTO.setClientKey(dyappid);
|
|
|
+// dyTokenDTO.setClientSecret(dyappSecret);
|
|
|
+// dyTokenDTO.setCode(authorizationCode);
|
|
|
+ String dyResultStr = dyService.getDyToken1(dyappSecret,authorizationCode,"authorization_code",dyappid);
|
|
|
+ //HttpUtils.sendPost()
|
|
|
+ // String dyResultStr = dyService.getDyToken1(dyappSecret,authorizationCode,"authorization_code",dyappid);
|
|
|
logger.info("抖音授权码登录返回值:"+dyResultStr);
|
|
|
DyResult dyResult = JSONObject.parseObject(dyResultStr,DyResult.class);
|
|
|
|
|
|
// 生成令牌
|
|
|
- if (dyResult.getDyToken().getError_code() != 0){
|
|
|
- throw new CustomException("抖音授权登录无效,错误原因:"+dyResult.getDyToken().getDescription());
|
|
|
+ if (dyResult.getData().getError_code() != 0){
|
|
|
+ throw new CustomException("抖音授权登录无效,错误原因:"+dyResult.getData().getDescription());
|
|
|
}
|
|
|
DyUserInfoDTO dyUserInfoDTO= new DyUserInfoDTO();
|
|
|
- dyUserInfoDTO.setOpenid(dyResult.getDyToken().getOpen_id());
|
|
|
- dyUserInfoDTO.setAccessToken(dyResult.getDyToken().getAccess_token());
|
|
|
+ dyUserInfoDTO.setOpen_id(dyResult.getData().getOpen_id());
|
|
|
+ dyUserInfoDTO.setAccess_token(dyResult.getData().getAccess_token());
|
|
|
String userInfoStr = dyService.getUserInfo(dyUserInfoDTO);
|
|
|
DyUserInfoResult dyUserInfoResult = JSONObject.parseObject(userInfoStr,DyUserInfoResult.class);
|
|
|
|
|
@@ -234,7 +246,7 @@ public class SysLoginController
|
|
|
ServletUtils.getRequest().setAttribute("headImage",dyUserInfoResult.getData().getAvatar());
|
|
|
ServletUtils.getRequest().setAttribute("nickName",dyUserInfoResult.getData().getNickname());
|
|
|
ServletUtils.getRequest().setAttribute("openid",dyUserInfoResult.getData().getOpen_id());
|
|
|
- String token = loginService.login(dyResult.getDyToken().getOpen_id(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_DY_LOGIN.getCode());
|
|
|
+ String token = loginService.login(dyUserInfoResult.getData().getUnion_id(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_DY_LOGIN.getCode());
|
|
|
TokenDTO tokenDTO = new TokenDTO();
|
|
|
tokenDTO.setToken(token);
|
|
|
tokenDTO.setThirdResult(dyUserInfoResult);
|