/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.modules.auth.granter;
|
|
import lombok.AllArgsConstructor;
|
import org.springblade.common.cache.CacheNames;
|
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.redis.cache.BladeRedis;
|
import org.springblade.core.tool.utils.DigestUtil;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.core.tool.utils.StringUtil;
|
import org.springblade.core.tool.utils.WebUtil;
|
import org.springblade.modules.auth.enums.UserEnum;
|
import org.springblade.modules.auth.provider.ITokenGranter;
|
import org.springblade.modules.auth.provider.TokenParameter;
|
import org.springblade.modules.auth.utils.TokenUtil;
|
import org.springblade.modules.system.entity.Tenant;
|
import org.springblade.modules.system.entity.UserInfo;
|
import org.springblade.modules.system.service.ITenantService;
|
import org.springblade.modules.system.service.IUserService;
|
import org.springframework.stereotype.Component;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
/**
|
* 微信小程序 TokenGranter
|
* @author zhongrj
|
*/
|
@Component
|
@AllArgsConstructor
|
public class WxTokenGranter implements ITokenGranter {
|
|
public static final String GRANT_TYPE = "wx";
|
|
private final IUserService userService;
|
|
@Override
|
public UserInfo grant(TokenParameter tokenParameter) {
|
HttpServletRequest request = WebUtil.getRequest();
|
String tenantId = tokenParameter.getArgs().getStr("tenantId");
|
String username = tokenParameter.getArgs().getStr("username");
|
String code = tokenParameter.getArgs().getStr("code");
|
// 校验,获取手机号
|
String phone = "15170720695";
|
// 返回
|
return userService.userInfoByWx(tenantId, phone, UserEnum.WEB);
|
}
|
|
}
|