CINXE.COM
API文档 - 开放平台 - OSCHINA 社区
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang='zh-CN' xml:lang='zh-CN' xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <!-- 此meta用于腾讯验证我们网址的有效性 --> <meta property="qc:admins" content="2554550177673301616654" /> <!-- 此meta用于百度站长工具 --> <meta name="baidu-site-verification" content="kerGDpToCx" /> <meta name="referrer" content="always"/> <link rel="shortcut icon" type="image/x-icon" href="/img/favicon.ico?t=1670143215000" /> <title>API文档 - 开放平台 - OSCHINA 社区</title> <meta itemprop="name" content="API文档 - 开放平台- OSCHINA 社区"/> <meta itemprop="image" content="https://www.oschina.net/img/logo_s2.png" /> <meta name="Description" itemprop="description" content="API文档 - 开放平台- OSCHINA 社区"/> <link rel="stylesheet" href="/css/channel.css?t=1670143214000" type="text/css" media="screen" /> <link rel="stylesheet" type="text/css" href="/js/2011/fancybox/jquery.fancybox-1.3.4.css?t=1670143215000" media="screen" /> <link rel="alternate" type="application/rss+xml" title="最新开源项目" href="https://www.oschina.net/project/rss" /> <link rel="alternate" type="application/rss+xml" title="最新开源资讯" href="https://www.oschina.net/news/rss" /> <link rel="alternate" type="application/rss+xml" title="最新问题列表" href="https://www.oschina.net/question/rss" /> <link rel="alternate" type="application/rss+xml" title="最新翻译列表" href="https://www.oschina.net/translate/rss" /> <link rel="alternate" type="application/rss+xml" title="最新博客列表" href="https://www.oschina.net/blog/rss" /> <link rel="alternate" type="application/rss+xml" title="推荐博客列表" href="https://www.oschina.net/blog/rss?show=more" /> <link rel="alternate" type="application/rss+xml" title="推荐软件列表" href="https://www.oschina.net/project/rss?show=recomms" /> <link rel="alternate" type="application/rss+xml" title="最新代码分享列表" href="https://www.oschina.net/code/rss" /> <link rel="stylesheet" href="/jobs/dist/css/jobV.css?t=1670143215000" /> <link rel="stylesheet" type="text/css" href="https://static.oschina.net/build/oschina/components/stylesheets/leeui_layout.css?t=1743650652000"> <link rel="alternate" type="application/rss+xml" title="OSCHINA - 源码列表" href="https://www.oschina.net/code/source_rss" /> <!--添加emoji支持--> <link rel="stylesheet" type="text/css" href="/js/team/grunt/dist/emoji/emoji.min.css?t=1670143216000"> <script type="text/javascript" src="/js/2012/jquery-2.1.4.min.js?t=1670143215000"></script> <script type="text/javascript" src="/js/2012/jquery-migrate-1.4.1.min.js?t=1670143215000"></script> <script type="text/javascript" src="/js/2012/jquery.form.js?t=1670143215000"></script> <script type="text/javascript" src="/js/2011/fancybox/jquery.fancybox-fixed.js?t=1670143215000?2014031702"></script> <link rel="stylesheet" href="/js/poshytip/tip-yellowsimple/tip-yellowsimple.css?t=1670143216000" type="text/css" /> <script type="text/javascript" src="/js/poshytip/jquery.poshytip.min.js?t=1670143216000"></script> <script type="text/javascript"> g_user = { id:0, name:'', login:false}; </script> <script type="text/javascript" src="/js/2011/oschina.js?t=1670143215000"></script> <script type="text/javascript" src="/js/utils.js?t=1670143216000"></script> <script type="text/javascript" src="/js/channel.js?t=1670143215000?2014022501"></script> <style type="text/css"> </style> </head> <body> <div id='OSC_NavTop'> <div class="wp998"> <div id="OSC_Channels"> <ul> <li class="item"><a href="https://www.oschina.net/" class='home'>首页</a></li> <li class="item control_select"><a href="https://www.oschina.net/project" class='project'>开源项目</a> <ul class="cs_content"> <li><a href='https://www.oschina.net/project/zh'>国产开源项目</a></li> <li><a href='https://www.oschina.net/project/tags'>项目分类</a></li> <li><a href='https://www.oschina.net/project/list?sort=time'>最新收录项目</a></li> <li class='split'></li> <li><a href="https://www.oschina.net/project/lang/19/java">Java 开源软件</a></li> <li><a href="https://www.oschina.net/project/lang/194/csharp">C# 开源软件</a></li> <li><a href="https://www.oschina.net/project/lang/22/php">PHP 开源软件</a></li> <li><a href="https://www.oschina.net/project/lang/21/c">C/C++ 开源软件</a></li> <li><a href="https://www.oschina.net/project/lang/26/ruby">Ruby 开源软件</a></li> <li><a href="https://www.oschina.net/project/lang/25/python">Python 开源软件</a></li> <li><a href="https://www.oschina.net/project/lang/358/go">Go开源软件</a></li> <li><a href="https://www.oschina.net/project/lang/28/javascript">JS开源软件</a></li> </ul> </li> <li class="item control_select"> <a href="https://www.oschina.net/question" class='question'>问答</a> <ul class="cs_content"> <li><a href="https://www.oschina.net/question?catalog=1"> 技术问答 » </a></li> <li><a href="https://www.oschina.net/question?catalog=2"> 技术分享 » </a></li> <li><a href="https://www.oschina.net/question?catalog=3"> IT大杂烩 » </a></li> <li><a href="https://www.oschina.net/question?catalog=100"> 职业生涯 » </a></li> <li><a href="https://www.oschina.net/question?catalog=4"> 站务/建议 » </a></li> <li><a href="https://www.oschina.net/alipay"> 支付宝专区 » </a></li> <li><a href="https://www.oschina.net/mopaas"> MoPaaS专区 » </a></li> <li><a href="https://www.oschina.net/hardware"> 开源硬件专区 » </a></li> </ul> </li> <li class="item"><a href="https://www.oschina.net/blog" class='blog'>博客</a></li> <li class="item"><a href="https://www.oschina.net/translate" class='tran'>翻译</a></li> <li class="item"><a href="https://www.oschina.net/news" class='news'>资讯</a></li> <li class="item control_select"> <a href="https://www.oschina.net/android" class='mobile'>专题</a> <ul class="cs_content cs_mobile"> <li><a href='https://www.oschina.net/event/ych' style='color:#c00'>源创会</a> <a href='/video'>视频</a></li> <li><a href='http://www.oschina.net/question/tag/%E9%AB%98%E6%89%8B%E9%97%AE%E7%AD%94'>高手问答</a> <a href='http://www.oschina.net/question/tag/%E5%BC%80%E6%BA%90%E8%AE%BF%E8%B0%88'>访谈</a></li> <li><a href='https://my.oschina.net/editorial-story/blog'>周刊</a> <a href='http://my.oschina.net/xxiaobian/blog'>乱弹</a></li> <li><a href="https://www.oschina.net/company">公司开源导航页</a></li> <li class='split'></li> <li class="android_"><a href="https://www.oschina.net/android">Android开发专区</a></li> <li class="ios_"><a href="https://www.oschina.net/ios/home">iOS开发专区</a></li> <li class="ios_"><a href="https://www.oschina.net/ios/codingList">iOS代码库</a></li> <li class="wp7_"><a href="https://www.oschina.net/wp">Windows Phone</a></li> </ul> </li> <li class="item"><a href="https://www.oschina.net/event" class='event'>活动</a></li> </ul> </div> <div id="OSC_Userbar"> 当前访客身份:游客 [ <a href="https://www.oschina.net/home/login?goto_page=https%3A%2F%2Fwww.oschina.net%2Fopenapi">登录</a> | <a href="https://www.oschina.net/home/reg">加入 OSCHINA</a> ] </div> <div class='clear'></div> </div> </div> <div id='OSC_Banner'><div class="wp998"><a href='https://www.oschina.net/' class='Logo' title='OSChina'>OSCHINA</a> <h1><a href='/openapi'>API 文档</a></h1> <div class="header-menu"> <ul> <li class="current"> <a href="/openapi/docs">OpenAPI 文档</a> </li> <li> <a href="/openapi/client">应用管理</a> </li> </ul> </div> <div style="text-align:right;line-height: 48px;height: 48px;"> <a href="/openapi/client/edit" class="header-button create">创建应用</a> </div> <div class='clear'></div></div></div> <div id="OSC_Screen"> <div id="OSC_Content" class='CenterDiv'> <script type="text/javascript" src="/js/baidutemplate/baidutemplate.js?t=1670143215000"></script> <style type="text/css"> .header-menu{font-size: 14pt;margin: 9px 0 0px 15px;float: left;width: 380px;} .header-menu ul li {font-size: 10pt;margin: 0 10px 0 4px;float: left;} .header-menu ul li a {display: block;text-decoration: none;background: #999;padding: 5px 8px;color: #FFF;} .header-menu ul li.current a {background: #40AA53;font-weight: bold;} .header-button{padding: 5px 27px;margin-left:10px;color:#FFF;text-decoration:none;} .header-button.create{background-color:#3B94CF;} .menu { float: left; background-color: #F5F5F5; padding: 15px; } .menu li{ margin: 3px; -o-text-overflow: ellipsis;/*兼容opera*/ text-overflow: ellipsis;/*这就是省略号喽*/ overflow: hidden;/*设置超过的隐藏*/ white-space: nowrap;/*设置不折行*/ width:175px;/*设置宽度*/ } .menu a{ text-decoration: none; font-size: 15px; line-height: 30px; margin-left: 15px; } .menu p{ background:url("/img/api_icon.gif?t=1670143215000") no-repeat left; padding-left: 18px; font-size: 18px; } .context { float: right; width: 770px; } .BTN{ float: left; font-size: 10.5pt; color: #FFF; background: #40AA53; border: 0; height: 32px; padding: 0 10px; cursor: pointer; } .desc{ padding: 3px 0 3px 15px; } .title{background-color: #EDF3F9;padding: 5px 0 5px 20px;margin: 10px 0;font-weight: bold;font-size: 15px;} .example{border: 1px solid #E3E3E3;padding-left: 30px;background-color: #f6fcfc;font-size: 13px;overflow: hidden;line-height: 1.1em; margin: 0 20px;} .returnType{font-weight: bold;font-size: 14px;padding-left: 30px; } .url{font-weight: bold;margin: 0 0 8px 10px;} .return table { font-size: 14px; margin: 0 20px; } .return table th{ background-color: #dbf1f2; padding: 3px 0 3px 8px; font-weight: normal; } .return table td{ padding: 3px 0 3px 5px; } .menu .highline{ background-color: #EDF3F9; font-weight: bold; } </style> <div class="menu"> <p>认证接口</p> <ul> <li ><a href="/openapi/docs/oauth2_authorize">oauth2_authorize</a></li> <li ><a href="/openapi/docs/oauth2_token">oauth2_token</a></li> </ul> <p>个人信息</p> <ul> <li ><a href="/openapi/docs/openapi_user">openapi_user</a></li> <li ><a href="/openapi/docs/user_information">user_information</a></li> <li ><a href="/openapi/docs/my_information">my_information</a></li> <li ><a href="/openapi/docs/portrait_update">portrait_update</a></li> <li ><a href="/openapi/docs/friends_list">friends_list</a></li> <li ><a href="/openapi/docs/active_list">active_list</a></li> <li ><a href="/openapi/docs/update_user_relation">update_user_relation</a></li> </ul> <p>新闻</p> <ul> <li ><a href="/openapi/docs/news_list">news_list</a></li> <li ><a href="/openapi/docs/news_detail">news_detail</a></li> </ul> <p>帖子</p> <ul> <li ><a href="/openapi/docs/post_list">post_list</a></li> <li ><a href="/openapi/docs/post_pub">post_pub</a></li> <li ><a href="/openapi/docs/post_detail">post_detail</a></li> </ul> <p>动弹</p> <ul> <li ><a href="/openapi/docs/tweet_list">tweet_list</a></li> <li ><a href="/openapi/docs/tweet_detail">tweet_detail</a></li> <li ><a href="/openapi/docs/tweet_pub">tweet_pub</a></li> <li ><a href="/openapi/docs/tweet_delete">tweet_delete</a></li> </ul> <p>博客</p> <ul> <li ><a href="/openapi/docs/blog_pub">blog_pub</a></li> <li ><a href="/openapi/docs/blog_list">blog_list</a></li> <li ><a href="/openapi/docs/blog_recommend_list">blog_recommend_list</a></li> <li ><a href="/openapi/docs/blog_detail">blog_detail</a></li> <li ><a href="/openapi/docs/user_blog_list">user_blog_list</a></li> <li ><a href="/openapi/docs/blog_catalog_list">blog_catalog_list</a></li> </ul> <p>评论</p> <ul> <li ><a href="/openapi/docs/blog_comment_list">blog_comment_list</a></li> <li ><a href="/openapi/docs/blog_comment_pub">blog_comment_pub</a></li> <li ><a href="/openapi/docs/blog_comment_reply">blog_comment_reply</a></li> <li ><a href="/openapi/docs/user_blog_delete">user_blog_delete</a></li> <li ><a href="/openapi/docs/comment_list">comment_list</a></li> <li ><a href="/openapi/docs/comment_pub">comment_pub</a></li> <li ><a href="/openapi/docs/comment_reply">comment_reply</a></li> <li ><a href="/openapi/docs/comment_delete">comment_delete</a></li> </ul> <p>收藏</p> <ul> <li ><a href="/openapi/docs/favorite_list">favorite_list</a></li> <li ><a href="/openapi/docs/favorite_add">favorite_add</a></li> <li ><a href="/openapi/docs/favorite_remove">favorite_remove</a></li> </ul> <p>软件</p> <ul> <li ><a href="/openapi/docs/project_detail">project_detail</a></li> <li ><a href="/openapi/docs/project_catalog_list">project_catalog_list</a></li> <li ><a href="/openapi/docs/project_list">project_list</a></li> <li ><a href="/openapi/docs/project_tag_list">project_tag_list</a></li> </ul> <p>私信</p> <ul> <li ><a href="/openapi/docs/message_list">message_list</a></li> <li ><a href="/openapi/docs/message_delete">message_delete</a></li> </ul> <p>搜索</p> <ul> <li ><a href="/openapi/docs/search_list">search_list</a></li> </ul> <p>通知</p> <ul> <li ><a href="/openapi/docs/user_notice">user_notice</a></li> <li ><a href="/openapi/docs/clear_notice">clear_notice</a></li> </ul> </div> <div class="context"> <link rel="stylesheet" type="text/css" href="https://static.oschina.net/css/reset_y.css"> <style type="text/css"> .platform-intro ul li{margin:5px 0;line-height:23px;} .platform-intro ul li em{color:#A00;font-weight:bold;font-style:normal;} .platform-intro ul.apis{display:block;} .platform-intro ul.apis li{float:left;margin:10px 10px 0 0;} .platform-intro sup{font-weight:normal;font-size:12px;margin-left:5px;color:#A00;} .platform-intro table{border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;} .platform-intro table td{border-left: 1px solid #CCC;border-top: 1px solid #CCC;padding:3px;} .demos th{border:1px solid #DDD;padding:10px;background:#F5F5F5;} .demos td{border:1px solid #DDD;padding:10px;} .demos a{text-decoration:none;} </style> <div class="platform-intro"> <h2 style="margin:10px 0;font-size:20px;">OSCHINA 开放平台<sup>Beta</sup></h2> <ul style="margin-left:10px;"> <li> 一、采用 <a href="/p/oauth" target="_blank">OAuth2 协议</a> 认证 </li> <li> 二、开放 <a href="/app" target="_blank">osc 移动 app</a> 版本所有接口 <ul class="apis" style="margin-left:25px;"> <li>1、认证接口</li> <li>2、个人信息</li> <li>3、新闻</li> <li>4、帖子</li> <li>5、动弹</li> <li>6、博客</li> <li>7、评论</li> <li>8、收藏</li> <li>9、软件</li> <li>10、私信</li> <li>11、搜索</li> <li>12、通知</li> </ul> </li> </ul> <br/> <br/> <br/> <br/> <h2 style="margin:10px 0;font-size:20px;">API 使用条款</h2> <ul style="margin-left:10px;"> <li>1、OSCHINA 用户是资源的拥有者,需尊重和保护用户的权益。</li> <li>2、不能在应用中使用 OSCHINA 的名称。</li> <li>3、未经用户允许,不准爬取或存储用户的资源。</li> <li>4、禁止滥用 API,请求频率过快将导致请求终止。</li> <li>最终解释权归 OSCHINA 所有</li> </ul> <br/> <h2 style="margin:10px 0;font-size:20px;"><strong>OAuth</strong>2 认证基本流程</h2> <img src="/img/openapi-oauth2-flow.png?t=1670143215000"/> <ul style="margin-left:10px;"> <li>图(2) OAuth2 获取 AccessToken 步骤说明:</li> <li style="margin:10px 0 0 20px;"><em>(A)</em>:应用通过 浏览器 或 Webview 将用户引导到 OSChina <a href="http://www.oschina.net/openapi/docs/oauth2_authorize" target="_blank">三方认证页面</a> 上<br>https://www.oschina.net/action/oauth2/authorize?response_type=code&client_id=<em>{client_id}<sup>①</sup></em>&redirect_uri=<em>{redirect_uri}<sup>②</sup></em></li> <li style="margin:10px 0 0 20px;"><em>(B)</em>:用户对应用进行授权</li> <li style="margin:10px 0 0 20px;"><em>(C)</em>:OSChina 认证服务器 通过 回调地址(redirect_uri)将 用户授权码 传递给 应用服务器 或者直接在 Webview 中跳转到携带 用户授权码的回调地址上,Webview 直接获取code即可(<em>redirect_uri</em>?code=abc&state=xyz)</li> <li style="margin:10px 0 0 20px;"><em>(D)</em>:应用服务器 或 Webview 使用 <a href="/openapi/docs/oauth2_token">oauth2_token</a> API 向 OSChina 认证服务器发送 用户授权码 以及 回调地址</li> <li style="margin:10px 0 10px 20px;"><em>(E)</em>: OSChina 认证服务器返回 AccessToken</li> <li> 标注说明: </li> <li style="margin:10px 0 0 20px;"> <em>① client_id</em>:<a href="/openapi/client" target="_blank">应用管理</a> 应用列表中的 <em>应用ID</em><br/> </li> <li style="margin:10px 0 10px 20px;"> <em>② redirect_uri</em>:<a href="/openapi/client" target="_blank">应用管理</a> 应用列表中的 <em>回调地址</em> </li> <li> 应用通过 AccessToken 访问 OpenApi 使用用户数据。 </li> </ul> <br/> <div class="demos"> <h2 style="margin:10px 0;font-size:20px;">Demo 应用</h2> <div> <p style="margin-bottom:10px;">下面将介绍使用 OpenAPI 开发的两个示例应用:</p> <table> <thead> <tr> <th> <a target="_blank" href="http://my.oschina.net/dtec/blog/194801">开源软件信息预览 ProjectTips</a> </th> <th> <a target="_blank" href="http://my.oschina.net/oscfox/blog/194507">OSChina.Net 博客搬家</a> </th> </tr> </thead> <tbody> <tr> <td> <a target="_blank" href="http://my.oschina.net/dtec/blog/194801"> <img src="/img/openapi/openapi_demo_project_tips.png?t=1670143215000" width="404px"/> </a> </td> <td> <a target="_blank" href="http://my.oschina.net/oscfox/blog/194507"> <img src="/img/openapi/openapi_demo_move_blog.png?t=1670143215000" width="404px" style="border:1px solid #CCC;"/> </a> </td> </tr> </tbody> </table> </div> </div> </div> </div> <div class='clear'></div></div> </div> <footer class="ant-layout-footer footer"> <div class="footer"> <div class="container"> <div class="logo"> <div class="box-center"> <img src="/img/images/LOGO.svg" alt="" style="width: 262px; height: 91px;" /> </div> </div> <div class="title"> <div class="overline"></div> <h4>OSCHINA社区</h4> <div class="list"> <a class="item" href="https://www.oschina.net/home/aboutosc" target="_blank"> 关于我们 </a> <a class="item" href="https://www.oschina.net/home/aboutosc" target="_blank"> 帮助中心 </a> <a class="item" href="https://www.oschina.net/home/aboutosc#partners" target="_blank"> 商务合作 </a> <a class="item" href="https://www.oschina.net/openapi" target="_blank"> Open API </a> </div> </div> <div class="title br"> <div class="overline"></div> <h4>在线工具</h4> <div class="list"> <a class="item" href="https://copycat.gitee.com/?utm_source=oschina&utm_medium=link-bottom&utm_campaign=copycat" target="_blank"> CopyCat-代码克隆检测 </a> <a class="item" href="https://tool.oschina.net" target="_blank"> 实用在线工具 </a> <a class="item">开源/AI软件库</a> <a class="item">Awesome 软件</a> </div> </div> <div class="title br"> <div class="overline"></div> <h4>攻略</h4> <div class="list"> <a class="item">造物发布</a> <a class="item">新闻投递</a> <a class="item">软件投递</a> <a class="item" href="https://www.oschina.net/question/2918182_2319406" target="_blank"> 项目运营 </a> </div> </div> <div class="title"> <h4>OSC开源社区APP</h4> <div class="scan-qr-code"> <div class="box"> <div class="ant-image css-quj94o"> <img alt="微信公众号" width="90" class="ant-image-img" src="/img/images/wechat_qrcode.webp"> </div> <span>Android / iOS</span> </div> </div> </div> </div> <div class="miit"> <div class="left"> <span>©OSCHINA(OSChina.NET)</span> <span>工信部</span> <span>开源软件推进联盟</span> <span>指定官方社区</span> <span>社区规范</span> </div> <div class="right"> <span><span class="right-none">深圳市奥思网络科技有限公司版权所有</span> 粤ICP备12009483</span> </div> </div> </div> </footer> <script type="text/javascript"> function escapeHtml(unsafe) { // 检查 unsafe 是否为 null 或 undefined if (unsafe == null) { return ''; } // 确保转换为字符串 unsafe = String(unsafe); return unsafe .replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } $('.media-matrix').hover(function(){ $('.media-matrix-mask').show() },function(){ $('.media-matrix-mask').hide() }) $('.osc-app').hover(function(){ $('.osc-app-mask').show() },function(){ $('.osc-app-mask').hide() }) $('.oper-user').hover(function(){ $('.oper-user-box').show() },function(){ $('.oper-user-box').hide() }) $(document).on('click','#userMess',function(e){ $("#user_box").show(); }) $(document).on('click','.ant-drawer-mask',function(e){ $("#user_box").hide(); }) $(document).on('click','.nav-bar-h5',function(e){ $("#navBarH5Menu").show(); e.stopPropagation(); }) $(document).on('click', function(e){ if($("#navBarH5Menu").is(":visible")){ $("#navBarH5Menu").hide(); } if($("#user_popover").is(":visible")){ $("#user_popover").hide(); } }) $(document).on('click','#user_popover .ant-tabs-tab',function(e){ if( $(this).hasClass('ant-tabs-tab-active')){ return false; }else{ $(this).siblings('.ant-tabs-tab').removeClass('ant-tabs-tab-active') $(this).addClass('ant-tabs-tab-active') let textValue = $(this).find('span').text(); $('.ant_tabs_content').hide(); if(textValue == '评论'){ getHandleComment(); $('#user_comment').show(); }else if(textValue == '点赞'){ getHandleLke(); $('#user_like').show(); }else if(textValue == '私信'){ //findAllMsgCount(); $('#user_content').show(); }else if(textValue == '@我'){ getMessageMe(); $('#user_my').show(); } } e.stopPropagation(); }) $(document).on('click','#message',function(e){ getHandleComment(); $("#user_popover").show(); e.stopPropagation(); }) $(function(){ getHnadleTopMenu(); getHandleMenu(); }); window.onload = function(){ getHandleToken(); getPrivateMsg(); } //获取token function getHandleToken(){ let time_data = Date.parse(new Date())/1000; let url_formal = "https://www.oschina.net/ApiSso/mobileToken" let queryParem = {timestamp:time_data}; $.ajax({ url: url_formal, method: "get", dataType: "json", data: queryParem, success: function (res) { } }) }; //获取web_v2_header_top菜单接口 function getHnadleTopMenu(){ let url_formal = "https://www.oschina.net/action/ajax/get_tool_ad?ident=web_v2_header_top" $.ajax({ url: url_formal, method: "get", dataType: "json", success: function (result) { let header_html = JSON.parse(result.html); let nav_BarTabs = header_html.navBarTabs; let nav_mediaMatrix = header_html.mediaMatrix; let nav_app = header_html.app; let nav_devOps = header_html.devOps; let html_navBarTabs = ''; let html_mediaMatrix = ''; let html_app = ''; let html_devOps = ''; //头部navBarTabs导航 for(let i=0; i<nav_BarTabs.length;i++){ if(nav_BarTabs[i].target){ html_navBarTabs += '<a href="'+nav_BarTabs[i].href+'" class="left-item" target="'+nav_BarTabs[i].target+'" style="'+nav_BarTabs[i].style+'">'+nav_BarTabs[i].text+'</a>' }else{ html_navBarTabs += '<a href="'+nav_BarTabs[i].href+'" class="left-item" target="_blank" style="'+nav_BarTabs[i].style+'">'+nav_BarTabs[i].text+'</a>' } } $('#nav_top_BarTabs').html(html_navBarTabs); //DevOps研发效能 for(let i=0; i<nav_devOps.length; i++){ html_devOps += '<a class="dev-ops-item" href="'+nav_devOps[i].href+'" target="_blank">'; html_devOps += ' <div class="dev-ops-img">'; html_devOps += '<img src="'+nav_devOps[i].imgUrl+'" alt="'+nav_devOps[i].text+'" />'; html_devOps += '</div>'; html_devOps += '<div class="dev-ops-title-des">'; html_devOps += '<div class="dev-ops-title">'+nav_devOps[i].text+'</div>'; html_devOps += '<div class="dev-ops-des">'+nav_devOps[i].description+'</div>'; html_devOps += '</div>'; html_devOps += '</a>'; } $('#devops_box').html(html_devOps); //头部媒体矩阵 for(let i=0; i<nav_mediaMatrix.length; i++){ html_mediaMatrix += '<div class="media-matrix-item">'; html_mediaMatrix += '<div class="item-img">'; html_mediaMatrix += '<img src="'+nav_mediaMatrix[i].imgUrl+'" alt="'+nav_mediaMatrix[i].title+'">'; html_mediaMatrix += '</div>'; html_mediaMatrix += '<div class="item-title">'+nav_mediaMatrix[i].title+'</div>'; html_mediaMatrix += '<div class="item-description">'+nav_mediaMatrix[i].description+'</div>'; html_mediaMatrix += '</div>'; } $('#media-box-mask').html(html_mediaMatrix); //头部开源中国APP html_app += '<div class="app-img">'; html_app += '开源中国社区APP,探索开源与AI的边界'; html_app += '</div>'; for(let i=0; i<nav_app.qrCode.length; i++){ html_app += '<div class="media-matrix-item">'; html_app += '<div class="item-img">'; html_app += '<img src="'+nav_app.qrCode[i].imgUrl+'" alt="'+nav_app.qrCode[i].title+'">'; html_app += '</div>'; html_app += '<div class="item-description">'+nav_app.qrCode[i].title+'</div>'; html_app += '</div>'; } $('#osc-app-box').html(html_app); } }); } //获取web_v2_header_bottom菜单接口 function getHandleMenu(){ let url_formal = "https://www.oschina.net/action/ajax/get_tool_ad?ident=web_v2_header_bottom" let html_menu_h5=""; $.ajax({ url: url_formal, method: "get", dataType: "json", success: function (result) { let html_menu=""; let header_menu = JSON.parse(result.html); let menu_html = header_menu.navBarTabs for(let i=0; i< menu_html.length; i++){ if(menu_html[i].showHotIcon){ html_menu += '<a href="'+menu_html[i].href+'" class="nav-bar-tag" target="'+menu_html[i].target+'" style="'+menu_html[i].style+'">'+menu_html[i].text+'🔥</a>' html_menu_h5 += '<div class="menu_h5_item"><a href="'+menu_html[i].href+'" class="nav-bar-tag" target="'+menu_html[i].target+'" style="'+menu_html[i].style+'">'+menu_html[i].text+'🔥</a></div>' }else{ html_menu += '<a href="'+menu_html[i].href+'" class="nav-bar-tag" target="'+menu_html[i].target+'" style="'+menu_html[i].style+'">'+menu_html[i].text+'</a>' html_menu_h5 += '<div class="menu_h5_item"><a href="'+menu_html[i].href+'" class="nav-bar-tag" target="'+menu_html[i].target+'" style="'+menu_html[i].style+'">'+menu_html[i].text+'</a></div>' } } $("#nav-bar-menu").html(html_menu); $("#navBarH5Menu .nav-bar-h5-item").html(html_menu_h5); } }); } //退出登录接口 function getHandleLogout(){ let url_formal = "https://www.oschina.net/user/logout" let user_code = {"session":""} $.ajax({ url: url_formal, method: "POST", dataType: "json", data: user_code, success: function (result) { $("#user_box").hide(); } }); } //拼接header头像连接赋值 function getAvatarUrl(){ let user_avatar = "$g_user.LargePortrait()"; let user_url; if(user_avatar){ if(user_avatar.indexOf("up")!== -1){ let url_formal = "https://www.oschina.net/oscnet/" user_url = url_formal + "$g_user.LargePortrait()" }else{ let url_formal = "https://www.oschina.net/uploads/user/" user_url = url_formal + "$g_user.LargePortrait()" } }else{ if("https://www.oschina.net/" == "http://www.oschina.com/"){ user_url = "http://www.oschina.com/new-osc/img/portrait.gif" }else if("https://www.oschina.net/" == "http://www.oschina.osc/"){ user_url = "http://www.oschina.osc/new-osc/img/portrait.gif" }else{ user_url = "https://www.oschina.net/new-osc/img/portrait.gif" } } let user_name = "${g_user.name}" // $("#userMess_avatarLogo").html('<img src="'+user_url+'" width="34" height="34" alt="'+user_name+'" title="'+user_name+'">') // $("#user_avatarLogo").html('<img src="'+user_url+'" width="40" height="40" alt="'+user_name+'" title="'+user_name+'">') } function getImgAvatarLoad(){ let user_name = "${g_user.name}" $("#userMess_avatarLogo img").on("load",function(){ }).on('error', function(){ let user_url; if("https://www.oschina.net/" == "http://www.oschina.com/"){ user_url = "http://www.oschina.com/new-osc/img/portrait.gif" }else if("https://www.oschina.net/" == "http://www.oschina.osc/"){ user_url = "http://www.oschina.osc/new-osc/img/portrait.gif" }else{ user_url = "https://www.oschina.net/new-osc/img/portrait.gif" } $("#userMess_avatarLogo").html('<img src="'+user_url+'" width="34" height="34" alt="'+user_name+'" title="'+user_name+'">') $("#user_avatarLogo").html('<img src="'+user_url+'" width="40" height="40" alt="'+user_name+'" title="'+user_name+'">') }) } //获取私信数量 function getPrivateMsg(){ let url_formal; if("https://www.oschina.net/" == "http://www.oschina.com/"){ url_formal = "http://apiv1.oschina.com/oschinapi/message/remind/all/count" url_user_id=" http://my.oschina.com/u_beta/" }else if("https://www.oschina.net/" == "http://www.oschina.osc/"){ url_formal = "http://apiv1.oschina.osc/oschinapi/message/remind/all/count" url_user_id=" http://my.oschina.osc/u_beta/" }else{ url_formal = "https://apiv1.oschina.net/oschinapi/message/remind/all/count" url_user_id=" https://my.oschina.net/u_beta/" } let user_id = ""; let user_code = ""; $.ajax({ url: url_formal, method: "post", dataType: "json", xhrFields: { withCredentials: true }, crossDomain: true, success: function (res) { if(res.code == '200'){ let messageTypeCount = getMessageCounts(res.result.messageTypes); if(messageTypeCount.allCount == 0){ $('#user_content').html("<div class='user_mess_nodata'></div>") }else{ $("#message .notice_count").html(messageTypeCount.allCount); $("#message .notice_count").show(); if(messageTypeCount.counts.mentionCount > 0){ $('#user_my_num').html(messageTypeCount.counts.mentionCount); $('#user_my_num').show(); } if(messageTypeCount.counts.commentCount > 0){ $('#user_comment_num').html(messageTypeCount.counts.commentCount); $('#user_comment_num').show(); } if(messageTypeCount.counts.likeCount > 0){ $('#user_like_num').html(messageTypeCount.counts.likeCount); $('#user_like_num').show(); } if(messageTypeCount.counts.privateMsgCount > 0){ let user_html = ''; user_html += "<div class='user_message'>有 <span>"+messageTypeCount.counts.privateMsgCount+"</span> 个用户私信了您!!</div>" user_html += "<div class='mess_btnbox'><a href='"+url_user_id+""+user_id+"?key=message' class='mess_btn_more'>查看更多</a></div>" $('#user_content').html(user_html) $('#user_content_num').html(messageTypeCount.counts.privateMsgCount); $('#user_content_num').show(); }else{ $('#user_content').html("<div class='user_mess_nodata'></div>") } } } } }) } function getMessageCounts(messageTypes) { const counts = { mentionCount: 0, commentCount: 0 }; let allCount = 0; messageTypes.forEach(item => { if (item.messageType === 2) { counts.likeCount = item.count; allCount += item.count; } else if (item.messageType === 8) { counts.commentCount = item.count; allCount += item.count; } else if (item.messageType === 1) { counts.atMeCount = item.count; allCount += item.count; } else if (item.messageType === 9) { counts.privateMsgCount = item.count; allCount += item.count; } }); return { counts, allCount }; } //@我 function getMessageMe(){ let url_formal; let url_user_formal; let url_user_id; let url_user_blog; if("https://www.oschina.net/" == "http://www.oschina.com/"){ url_formal = "http://apiv1.oschina.com/oschinapi/message/content/at" url_user_formal = "http://www.oschina.com/" url_user_id=" http://my.oschina.com/u_beta/" url_user_blog = "http://my.oschina.com/" }else if("https://www.oschina.net/" == "http://www.oschina.osc/"){ url_formal = "http://apiv1.oschina.osc/oschinapi/message/content/at" url_user_formal = "http://www.oschina.osc/" url_user_id=" http://my.oschina.osc/u_beta/" url_user_blog = "http://my.oschina.osc/" }else{ url_formal = "https://apiv1.oschina.net/oschinapi/message/content/at" url_user_formal = "https://www.oschina.net/" url_user_id=" https://my.oschina.net/u_beta/" url_user_blog = "http://my.oschina.net/" } let user_id = ""; let queryParem = {pageNum:1,pageSize:5} $.ajax({ url: url_formal, method: "post", dataType: "json", xhrFields: { withCredentials: true }, crossDomain: true, data:queryParem, success: function (res) { let html_me = ''; if(res.code == 200){ if(res.result.length > 0){ let json_array = res.result; for(let i=0; i<json_array.length; i++){ let url_comment; if(json_array[i].objType == 3){ url_comment = url_user_blog+"u/"+json_array[i].userVo.id+"/blog_beta/"+json_array[i].linkObjId }else if(json_array[i].objType == 18){ url_comment = url_user_blog+"u/"+json_array[i].userVo.id+"/blog_beta/"+json_array[i].linkObjId+"#comment" }else if(json_array[i].objType == 4){ if(json_array[i].ident){ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId+'/'+json_array[i].ident }else{ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId } }else if(json_array[i].objType == 16){ if(json_array[i].ident){ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId+'/'+json_array[i].ident+"#comment" }else{ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId+"#comment" } }else if(json_array[i].objType == 40){ url_comment = url_user_formal+"aiCreation/details/"+json_array[i].linkObjId }else if(json_array[i].objType == 100){ url_comment = url_user_formal+"oscTweet/"+json_array[i].linkObjId }else if(json_array[i].objType == 101){ url_comment = url_user_formal+"oscTweet/"+json_array[i].linkObjId }else{ console.warn("类型错误") } html_me += '<div class="message-item">'; if(json_array[i].state == 1){ html_me += '<div class="message-item-info">'; }else{ html_me += '<div class="message-item-info unread">'; } // Sanitize user input let safeUserName = escapeHtml(json_array[i].userVo.name); let safeContent = escapeHtml(json_array[i].content); html_me += '<a class="message-item-user" href="'+url_user_id+''+json_array[i].userVo.id+'" target="_blank"><span></span>'+safeUserName+'</a>'; html_me += '   @我  '; html_me += '<a class="message-item-content" href="'+url_comment+'" target="_blank">'+safeContent+'</a>'; html_me += '</div>'; html_me += '<div class="message-item-time">'+escapeHtml(json_array[i].createTime)+'</div>'; html_me += '</div>' } html_me += '<div class="mess_btnbox"><a href="'+url_user_id+''+user_id+'?key=tweet" class="mess_btn_more">查看更多</a></div>' $('#user_my').html(html_me) }else{ $('#user_my').html("<div class='user_mess_nodata'></div>") } }else{ console.log("出错了!!!") } } }) } //评论的消息 function getHandleComment(){ let url_formal; let url_user_formal; if("https://www.oschina.net/" == "http://www.oschina.com/"){ url_formal = "http://apiv1.oschina.com/oschinapi/message/content/comment" url_user_formal = "http://www.oschina.com/" url_user_id=" http://my.oschina.com/u_beta/" url_user_blog = "http://my.oschina.com/" }else if("https://www.oschina.net/" == "http://www.oschina.osc/"){ url_formal = "http://apiv1.oschina.osc/oschinapi/message/content/comment" url_user_formal = "http://www.oschina.osc/" url_user_id=" http://my.oschina.osc/u_beta/" url_user_blog = "http://my.oschina.osc/" }else{ url_formal = "https://apiv1.oschina.net/oschinapi/message/content/comment" url_user_formal = "https://www.oschina.net/" url_user_id=" https://my.oschina.net/u_beta/" url_user_blog = "http://my.oschina.net/" } let user_id = ""; let queryParem = {pageNum:1,pageSize:5} $.ajax({ url: url_formal, method: "post", dataType: "json", xhrFields: { withCredentials: true }, crossDomain: true, data:queryParem, success: function (res) { let html_comment = ''; if(res.code == 200){ if(res.result.length > 0){ let json_array = res.result; for(let i=0; i<json_array.length; i++){ let url_comment; if(json_array[i].objType == 3){ url_comment = url_user_blog+"u/"+json_array[i].userVo.id+"/blog_beta/"+json_array[i].linkObjId }else if(json_array[i].objType == 18){ url_comment = url_user_blog+"u/"+json_array[i].userVo.id+"/blog_beta/"+json_array[i].linkObjId+"#comment" }else if(json_array[i].objType == 4){ if(json_array[i].ident){ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId+'/'+json_array[i].ident }else{ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId } }else if(json_array[i].objType == 16){ if(json_array[i].ident){ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId+'/'+json_array[i].ident+"#comment" }else{ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId+"#comment" } }else if(json_array[i].objType == 40){ url_comment = url_user_formal+"aiCreation/details/"+json_array[i].linkObjId }else if(json_array[i].objType == 100){ url_comment = url_user_formal+"oscTweet/"+json_array[i].linkObjId }else if(json_array[i].objType == 101){ url_comment = url_user_formal+"oscTweet/"+json_array[i].linkObjId }else{ console.warn("类型错误") } html_comment += '<div class="message-item">'; if(json_array[i].state == 1){ html_comment += '<div class="message-item-info">'; }else{ html_comment += '<div class="message-item-info unread">'; } // Sanitize user input let safeUserName = escapeHtml(json_array[i].userVo.name); let safeContent = escapeHtml(json_array[i].content); html_comment += '<a class="message-item-user" href="'+url_user_id+''+json_array[i].userVo.id+'" target="_blank"><span></span>'+safeUserName+'</a>'; html_comment += '   评论了  '; html_comment += '<a class="message-item-content" href="'+url_comment+'" target="_blank">'+safeContent+'</a>'; html_comment += '</div>'; html_comment += '<div class="message-item-time">'+escapeHtml(json_array[i].createTime)+'</div>'; html_comment += '</div>' } html_comment += '<div class="mess_btnbox"><a href="'+url_user_id+''+user_id+'?key=comment" class="mess_btn_more">查看更多</a></div>' $('#user_comment').html(html_comment) }else{ $('#user_comment').html("<div class='user_mess_nodata'></div>") } }else{ console.log("出错了!!!") } } }) } //点赞的消息 function getHandleLke(){ let url_formal; let url_user_formal; if("https://www.oschina.net/" == "http://www.oschina.com/"){ url_formal = "http://apiv1.oschina.com/oschinapi/message/content/like" url_user_formal = "http://www.oschina.com/" url_user_id=" http://my.oschina.com/u_beta/" url_user_blog = "http://my.oschina.com/" }else if("https://www.oschina.net/" == "http://www.oschina.osc/"){ url_formal = "http://apiv1.oschina.osc/oschinapi/message/content/like" url_user_formal = "http://www.oschina.osc/" url_user_id=" http://my.oschina.osc/u_beta/" url_user_blog = "http://my.oschina.osc/" }else{ url_formal = "https://apiv1.oschina.net/oschinapi/message/content/like" url_user_formal = "https://www.oschina.net/" url_user_id=" https://my.oschina.net/u_beta/" url_user_blog = "http://my.oschina.net/" } let queryParem = {pageNum:1,pageSize:5} $.ajax({ url: url_formal, method: "post", dataType: "json", xhrFields: { withCredentials: true }, crossDomain: true, data:queryParem, success: function (res) { let html_like = ''; if(res.code == 200){ if(res.result.length > 0){ let json_array = res.result; for(let i=0; i<json_array.length; i++){ let url_comment; if(json_array[i].objType == 3){ url_comment = url_user_blog+"u/"+json_array[i].userVo.id+"/blog_beta/"+json_array[i].linkObjId }else if(json_array[i].objType == 18){ url_comment = url_user_blog+"u/"+json_array[i].userVo.id+"/blog_beta/"+json_array[i].linkObjId+"#comment" }else if(json_array[i].objType == 4){ if(json_array[i].ident){ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId+'/'+json_array[i].ident }else{ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId } }else if(json_array[i].objType == 16){ if(json_array[i].ident){ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId+'/'+json_array[i].ident+"#comment" }else{ url_comment = url_user_formal+"news_beta/"+json_array[i].linkObjId+"#comment" } }else if(json_array[i].objType == 40){ url_comment = url_user_formal+"aiCreation/details/"+json_array[i].linkObjId }else if(json_array[i].objType == 100){ url_comment = url_user_formal+"oscTweet/"+json_array[i].linkObjId }else if(json_array[i].objType == 101){ url_comment = url_user_formal+"oscTweet/"+json_array[i].linkObjId }else{ console.warn("类型错误") } html_like += '<div class="message-item">'; if(json_array[i].state == 1){ html_like += '<div class="message-item-info">'; }else{ html_like += '<div class="message-item-info unread">'; } // Sanitize user input let safeUserName = escapeHtml(json_array[i].userVo.name); let safeContent = escapeHtml(json_array[i].content); html_like += '<a class="message-item-user" href="'+url_user_id+''+json_array[i].userVo.id+'" target="_blank"><span></span>'+safeUserName+'</a>'; html_like += '   点赞了  '; html_like += '<a class="message-item-content" href="'+url_comment+'" target="_blank">'+safeContent+'</a>'; html_like += '</div>'; html_like += '<div class="message-item-time">'+escapeHtml(json_array[i].createTime)+'</div>'; html_like += '</div>' } $('#user_like').html(html_like) }else{ $('#user_like').html("<div class='user_mess_nodata'></div>") } }else{ console.log("出错了!!!") } } }) } //获取未读数量接口 function findAllMsgCount(){ let url_formal = "https://www.oschina.net/msg/findAllMsgCount" let user_code = ""; let user_id = ""; let user_data = { "user_code":user_code, "userId":user_id } $.ajax({ url: url_formal, method: "post", dataType: "json", data: user_data, success: function (result) { //let html_msg = ''; if(result.message == "success"){ let msg_count = result.result.totalMsgCount; if(msg_count != 0){ //html_msg += '<div>'+msg_count+'</div>' //html_msg += '<div class="mess_btnbox"><a href="'+url_user_id+''+json_array[0].userVo.id+'?key=message" class="mess_btn_more">查看更多</a></div>' $("#message .notice_count").html(msg_count); $("#message .notice_count").css("display","block") }else{ $("#message .notice_count").css("display","none") } } } }); } // getAvatarUrl(); // getImgAvatarLoad(); //页面滚动时顶部动态显示隐藏 $(function(){ let winHeight = $(document).scrollTop(); $(window).scroll(function(){ if(scrollY > 70){ $(".top-prefix").hide(); }else{ $(".top-prefix").show(); } }) }) //创作基金弹窗 // 添加创作基金弹窗相关事件 $(function(){ // 点击创作基金显示弹窗 $('.ad-bjyh').on('click', function(){ $('.beijyh-modal-wrap').css('display', 'flex').fadeIn(300); }); // 点击蒙版关闭弹窗 $('.beijyh-modal-wrap').on('click', function(e){ if($(e.target).hasClass('beijyh-modal-wrap')) { $(this).fadeOut(300); } }); // 点击关闭按钮关闭弹窗 $('.beijyh-modal-box-close').on('click', function(){ $('.beijyh-modal-wrap').fadeOut(300); }); }); </script> <script type="text/javascript"> (function (ww, dt) { ww.__gac = { domain: 'www.oschina.net' }; if(!(/\/marketing\/ad-slice/.test(location.href))){ var script = dt.createElement('script'); script.setAttribute('type', 'text/javascript'); script.setAttribute('src', '//www.oschina.net/public/javascripts/cjl/ga.js?t=20160926'); dt.body.appendChild(script); } } (window, window.document)); </script></body> </html> <!-- Generated by OsChina.NET (init:0[ms],page:12[ms],ip:8.222.208.146) -->