微信登录
微信开放平台接入 官网:https://open.weixin.qq.com,在官网注册并添加应用后即可获得APP_ID和APP_SECRET。
步骤一:创建一个继承AuthService的接口,WeChatAuthService,如下
public interface WeChatAuthService extends AuthService {
public JSONObject getUserInfo(String accessToken, String openId);
}
步骤二:WeChatService的具体实现如下
@Service
public class WeChatAuthServiceImpl extends DefaultAuthServiceImpl implements WeChatAuthService {
private Logger logger = LoggerFactory.getLogger(WeChatAuthServiceImpl.class);
//请求此地址即跳转到二维码登录界面
private static final String AUTHORIZATION_URL =
"https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect";
// 获取用户 openid 和access——toke 的 URL
private static final String ACCESSTOKE_OPENID_URL =
"https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
private static final String REFRESH_TOKEN_URL =