{"record":{"id":"0937ee4436cfb81e","repo":"justauth/JustAuth","slug":"url-qq-login-code","errorCode":null,"errorMessage":"不支持获取授权 url，请使用小程序内置函数 qq.login() 登录获取 code","messagePattern":"不支持获取授权 url，请使用小程序内置函数 qq\\.login\\(\\) 登录获取 code","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java","lineNumber":1476,"sourceCode":"        public String userInfo() {\n            // 参见 https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html 文档\n            throw new UnsupportedOperationException(\"不支持获取用户信息 url，请使用小程序内置函数 wx.getUserProfile() 获取用户信息\");\n        }\n\n        @Override\n        public Class<? extends AuthDefaultRequest> getTargetClass() {\n            return AuthWechatMiniProgramRequest.class;\n        }\n    },\n\n    /**\n     * QQ小程序授权登录\n     */\n    QQ_MINI_PROGRAM {\n        @Override\n        public String authorize() {\n            // 参见 https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_userinfo.html 文档\n            throw new UnsupportedOperationException(\"不支持获取授权 url，请使用小程序内置函数 qq.login() 登录获取 code\");\n        }\n\n        @Override\n        public String accessToken() {\n            // 参见 https://q.qq.com/wiki/develop/miniprogram/server/open_port/port_login.html 文档\n            // 获取 openid, unionId , session_key 等字段\n            return \"https://api.q.qq.com/sns/jscode2session\";\n        }\n\n        @Override\n        public String userInfo() {\n            // 参见 https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_userinfo.html 文档\n            throw new UnsupportedOperationException(\"不支持获取用户信息 url，请使用小程序内置函数 qq.getUserInfo() 获取用户信息\");\n        }\n\n        @Override\n        public Class<? extends AuthDefaultRequest> getTargetClass() {\n            return null;","sourceCodeStart":1458,"sourceCodeEnd":1494,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java#L1458-L1494","documentation":"QQ_MINI_PROGRAM.authorize() throws UnsupportedOperationException telling you to use the mini-program built-in qq.login() to get the code. QQ mini programs have no OAuth authorize URL; the code comes from qq.login() on the client and is exchanged server-side via https://api.q.qq.com/sns/jscode2session (this source's accessToken()).","triggerScenarios":"Calling authorize(state) / getAuthorizeUrl(...) on a request built for QQ_MINI_PROGRAM; a generic provider-iteration login page that generates authorize URLs for every configured source.","commonSituations":"Copy-pasting the WeChat web-OAuth flow for QQ mini programs; shared login controllers that do not special-case mini-program sources. Note also that QQ_MINI_PROGRAM.getTargetClass() returns null, so building an AuthRequest via AuthRequestBuilder for it fails separately (error 2).","solutions":["Call qq.login() in the mini-program client and send the code to your server, then hit the jscode2session endpoint yourself (or via a custom AuthSource).","Exclude QQ_MINI_PROGRAM from authorize-URL generation branches.","Because getTargetClass() is null, do not route this source through AuthRequestBuilder.build(); implement a custom AuthSource with a real target class if you need the standard request API."],"exampleFix":"// before\nString url = request.authorize(state); // UnsupportedOperationException for QQ_MINI_PROGRAM\n\n// after\n// client: qq.login({ success: r => POST /auth/qq-mini?code=r.code })\n// server: GET https://api.q.qq.com/sns/jscode2session?appid=..&secret=..&js_code=..&grant_type=authorization_code","handlingStrategy":"validation","validationCode":"if (\"qq_mini_program\".equalsIgnoreCase(sourceName)) {\n    // no authorize URL and getTargetClass() is null: call jscode2session yourself\n    return qqMiniLogin(code); // GET https://api.q.qq.com/sns/jscode2session?...\n}","typeGuard":"boolean isMiniProgramSource(AuthSource s) {\n    try { s.authorize(); return false; }\n    catch (UnsupportedOperationException e) { return true; }\n}","tryCatchPattern":"catch (UnsupportedOperationException e) { /* QQ mini program: use qq.login() code + jscode2session directly */ }","preventionTips":["Do not route QQ_MINI_PROGRAM through AuthRequestBuilder (target class is null).","Exclude mini-program sources from authorize-URL generation endpoints.","Catch UnsupportedOperationException in generic provider handlers."],"tags":["justauth","qq","mini-program","unsupported-operation","provider-quirk"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}