├── .github └── ISSUE_TEMPLATE.md ├── .gitignore ├── LICENSE ├── README.md ├── README_ZH.md ├── ScreenShot.png ├── example_www ├── css │ ├── bootstrap.css │ └── index.css ├── img │ └── logo.png ├── index.html └── js │ └── index.js ├── package.json ├── plugin.xml ├── src ├── android │ ├── WeiboSDKPlugin.java │ └── libs │ │ ├── WeiboSDKPlugin.gradle │ │ ├── openDefault-4.3.6.aar │ │ └── so │ │ ├── arm64-v8a │ │ └── libweibosdkcore.so │ │ ├── armeabi-v7a │ │ └── libweibosdkcore.so │ │ ├── armeabi │ │ └── libweibosdkcore.so │ │ ├── mips │ │ └── libweibosdkcore.so │ │ ├── mips64 │ │ └── libweibosdkcore.so │ │ ├── x86 │ │ └── libweibosdkcore.so │ │ └── x86_64 │ │ └── libweibosdkcore.so └── ios │ ├── CDVWeiboSDK.h │ ├── CDVWeiboSDK.m │ └── libWeiboSDK │ ├── WBHttpRequest.h │ ├── WeiboSDK.bundle │ ├── images │ │ ├── common_button_white@2x.png │ │ ├── common_button_white_highlighted@2x.png │ │ └── empty_failed@2x.png │ └── others │ │ └── mfp.cer │ ├── WeiboSDK.h │ └── libWeiboSDK.a └── www └── weibo.js /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Before submitting issues ... 2 | 3 | - 确保你的 App 在[微博开放平台](http://open.weibo.com/)已审核通过. 4 | - 如果是 Android 平台请确保你的 apk 签名是正确的. 5 | - 请确认 demo 已测试通过. 6 | - 请先搜索相关的 issues,看是否同样的问题已经有解决方案了. 7 | - 发生授权出错的情况,请前先去微博开发者平台咨询,也可查看微博开发的[常见问题](https://github.com/sinaweibosdk/weibo_ios_sdk/blob/master/FAQ.md). 8 | 9 | 当你提交 issues 的时候, 请提供以下信息来帮助开发者更好的修复Bug: 10 | 11 | - 开发环境: 插件版本, Cordova 版本, Xcode 版本. 12 | - 如果出现错误,希望提供 Xcode 或 Android Studio 的错误日志. 13 | - 如果有其他额外的信息,也希望可以提供一下,帮助我们更快的定位问题. 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | .DS_Store 20 | 21 | # CocoaPods 22 | # 23 | # We recommend against adding the Pods directory to your .gitignore. However 24 | # you should judge for yourself, the pros and cons are mentioned at: 25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 26 | # 27 | # Pods/ 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Van 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cordova-plugin-weibosdk 2 | [![npm](https://img.shields.io/npm/v/cordova-plugin-weibosdk.svg)](https://www.npmjs.com/package/cordova-plugin-weibosdk) 3 | [![npm](https://img.shields.io/npm/dm/cordova-plugin-weibosdk.svg)](https://www.npmjs.com/package/cordova-plugin-weibosdk) 4 | [![platform](https://img.shields.io/badge/platform-iOS%2FAndroid-lightgrey.svg?style=flat)](https://github.com/iVanPan/cordova_weibo) 5 | [![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat)](https://github.com/iVanPan/cordova_weibo/blob/master/LICENSE) 6 | 7 | A Cordova wrapper around the Sina WeiboSDK for Android and iOS. Provides access to ssoLogin, WeiboSharing etc... [简体中文](https://github.com/iVanPan/cordova_weibo/blob/master/README_ZH.md) 8 | 9 | 10 | ## Feature 11 | - Weibo SSO Login 12 | - Weibo Logout 13 | - Weibo Share (WebPage,Text,Image) 14 | - Check Weibo Client is Installed 15 | 16 | ## Requirements 17 | - Cordova Version 3.5+ 18 | - Cordova-Android >= 7.0 19 | - Cordova-iOS >= 4.0 20 | 21 | ## Installation 22 | 1. ```cordova plugin add cordova-plugin-weibosdk --variable WEIBO_APP_ID=YOUR_WEIBO_APPID``` 23 | 2. Add `````` in your config.xml If you don't add this preference the defualt redirecturi is https://api.weibo.com/oauth2/default.html 24 | 3. cordova build 25 | 26 | 27 | ## Notes 28 | 1. This plugin is required Cordova-Android version >= 4.0,so using Cordova 5.0 or higher is recommended 29 | 2. This plugin should be used after the deviceready event has been fired!!! 30 | 3. ~~If Cordova version  <5.1.1,when two Cordova plugins are modifying “*-Info.plist” CFBundleURLTypes, only the first added plugin is getting the changes applied.so after installing plugin,please check the URLTypes in your Xcode project.You can find this issue [here](https://issues.apache.org/jira/browse/CB-8007).~~ Update:This Bug is fixed in last Cordova version(5.1.1) 31 | 32 | 33 | ## Usage 34 | 35 | ### Weibo SSO Login 36 | ```Javascript 37 | WeiboSDK.ssoLogin(function (args) { 38 | alert('access token is ' + args.access_token); 39 | alert('userId is ' + args.userId); 40 | alert('expires_time is ' + new Date(parseInt(args.expires_time)) + ' TimeStamp is ' + args.expires_time); 41 | }, function (failReason) { 42 | alert(failReason); 43 | }); 44 | ``` 45 | 46 | ### Weibo Logout 47 | ```Javascript 48 | WeiboSDK.logout(function () { 49 | alert('logout success'); 50 | }, function (failReason) { 51 | alert(failReason); 52 | }); 53 | ``` 54 | 55 | ### Weibo WebPage Share 56 | ```Javascript 57 | var args = {}; 58 | args.url = 'https://cordova.apache.org/'; 59 | args.title = 'Apache Cordova'; 60 | args.description = 'This is a Cordova Plugin'; 61 | args.image = 'https://cordova.apache.org/static/img/pluggy.png'; 62 | WeiboSDK.shareToWeibo(function () { 63 | alert('share success'); 64 | }, function (failReason) { 65 | alert(failReason); 66 | }, args); 67 | ``` 68 | ### Weibo Image Share 69 | ```Javascript 70 | var args = {}; 71 | args.image = 'https://cordova.apache.org/static/img/pluggy.png'; 72 | WeiboSDK.shareImageToWeibo(function () { 73 | alert('share success'); 74 | }, function (failReason) { 75 | alert(failReason); 76 | }, args); 77 | ``` 78 | ### Weibo Text Share 79 | ```Javascript 80 | var args = {}; 81 | args.text = 'This is a Cordova Plugin'; 82 | WeiboSDK.shareTextToWeibo(function () { 83 | alert('share success'); 84 | }, function (failReason) { 85 | alert(failReason); 86 | }, args); 87 | ``` 88 | ### CheckClientInstalled 89 | ```Javascript 90 | WeiboSDK.checkClientInstalled(function () { 91 | alert('client is installed'); 92 | }, function () { 93 | alert('client is not installed'); 94 | }); 95 | ``` 96 | ### GetUserInfo 97 | ```Javascript 98 | var url = 'https://api.weibo.com/2/users/show.json?uid=' + usrid + '&&access_token=' + token; 99 | http.get(url) 100 | ``` 101 | 102 | ## Example 103 | 1. install this plugin 104 | 2. backup www folder in your cordova project 105 | 3. replace www by example_www 106 | 4. cordova build & test 107 | 108 |
example
109 | 110 | ## About WeiboSdk 111 | you can downlaod last weibosdk [here](https://github.com/sinaweibosdk) .if you find any problem about weibosdk, open an isssus please. 112 | 113 | ## Contributing 114 | Feel free to contribute 115 | 116 | ## License 117 | 118 | **cordova-plugin-weibosdk** is released under the **MIT** license. See [LICENSE](https://github.com/iVanPan/cordova_weibo/blob/master/LICENSE) file for more information. 119 | 120 | -------------------------------------------------------------------------------- /README_ZH.md: -------------------------------------------------------------------------------- 1 | # cordova-plugin-weibosdk 2 | [![npm](https://img.shields.io/npm/v/cordova-plugin-weibosdk.svg)](https://www.npmjs.com/package/cordova-plugin-weibosdk) 3 | [![npm](https://img.shields.io/npm/dm/cordova-plugin-weibosdk.svg)](https://www.npmjs.com/package/cordova-plugin-weibosdk) 4 | [![platform](https://img.shields.io/badge/platform-iOS%2FAndroid-lightgrey.svg?style=flat)](https://github.com/iVanPan/cordova_weibo) 5 | [![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat)](https://github.com/iVanPan/cordova_weibo/blob/master/LICENSE) 6 | 7 | 8 | 这是一个微博的 Cordova 插件. [English](https://github.com/iVanPan/cordova_weibo) 9 | 如果有任何问题或是建议,请开 issuss,也欢迎 star 或是 fork。微博SDK部分如有涉及版权问题,版权归新浪微博所有 10 | 11 | ## 功能 12 | - 微博 SSO 登录 13 | - 微博登出 14 | - 微博分享(网页、文字、图片) 15 | - 检查微博官方客户端是否安装 16 | 17 | ## 安装要求 18 | - Cordova Version >= 3.5 19 | - Cordova-Android >= 7.0 20 | - Cordova-iOS >= 4.0 21 | 22 | ## 安装 23 | 1. 命令行运行 ```cordova plugin add cordova-plugin-weibosdk --variable WEIBO_APP_ID=YOUR_WEIBO_APPID``` 24 | 2. 在你的config.xml文件中添加 `````` 如果你不添加这个选项,那么默认的 redirecturi 是 https://api.weibo.com/oauth2/default.html 25 | 3. 命令行运行 cordova build 26 | 27 | # 注意事项 28 | 1. 这个插件要求 Cordova-Android 的版本 >=4.0,推荐使用 Cordova 5.0 或更高的版本,因为从 Cordova 5.0 开始 Cordova-Android 4.0 是默认使用的 Android 版本 29 | 2. 请在 Cordova 的 deviceready 事件触发以后再调用本插件!!!!! 30 | 3. 在低于5.1.1的 Cordova 版本中存在一个 Bug,如果你有多个插件要修改 iOS 工程中的 “*-Info.plist” CFBundleURLTypes, 只有第一个安装的插件才会生效.所以安装完插件请务必在你的 Xcode 工程里面检查一下 URLTypes。 关于这个 bug 的详情你可以在 [这里](https://issues.apache.org/jira/browse/CB-8007)找到 建议安装使用5.1.1及以上的 Cordova 版本 31 | 32 | ## 使用方法 33 | ### 微博SSO登录 34 | ```Javascript 35 | WeiboSDK.ssoLogin(function (args) { 36 | alert('access token is ' + args.access_token); 37 | alert('userId is ' + args.userId); 38 | alert('expires_time is ' + new Date(parseInt(args.expires_time)) + ' TimeStamp is ' + args.expires_time); 39 | }, function (failReason) { 40 | alert(failReason); 41 | }); 42 | ``` 43 | 44 | 45 | ### 微博登出 46 | ```Javascript 47 | WeiboSDK.logout(function () { 48 | alert('logout success'); 49 | }, function (failReason) { 50 | alert(failReason); 51 | }); 52 | ``` 53 | 54 | ### 微博网页分享 55 | ```Javascript 56 | var args = {}; 57 | args.url = 'https://cordova.apache.org/'; 58 | args.title = 'Apache Cordova'; 59 | args.description = 'This is a Cordova Plugin'; 60 | args.image = 'https://cordova.apache.org/static/img/pluggy.png'; 61 | WeiboSDK.shareToWeibo(function () { 62 | alert('share success'); 63 | }, function (failReason) { 64 | alert(failReason); 65 | }, args); 66 | ``` 67 | 68 | ### 微博图片分享 69 | ```Javascript 70 | var args = {}; 71 | args.image = 'https://cordova.apache.org/static/img/pluggy.png'; 72 | WeiboSDK.shareImageToWeibo(function () { 73 | alert('share success'); 74 | }, function (failReason) { 75 | alert(failReason); 76 | }, args); 77 | ``` 78 | 79 | ### 微博文字分享 80 | ```Javascript 81 | var args = {}; 82 | args.text = 'This is a Cordova Plugin'; 83 | WeiboSDK.shareTextToWeibo(function () { 84 | alert('share success'); 85 | }, function (failReason) { 86 | alert(failReason); 87 | }, args); 88 | ``` 89 | 90 | ### 检查微博客户端是否安装 91 | ```Javascript 92 | WeiboSDK.checkClientInstalled(function () { 93 | alert('client is installed'); 94 | }, function () { 95 | alert('client is not installed'); 96 | }); 97 | ``` 98 | 99 | ### 获取用户信息 100 | ```Javascript 101 | var url = 'https://api.weibo.com/2/users/show.json?uid=' + usrid + '&&access_token=' + token; 102 | http.get(url) 103 | ``` 104 | 105 | # 测试Demo 106 | 在安装完这个插件以后,把 Cordova 工程中的代码替换为 example_www 中的代码,在 build 以后可以进行各个功能测试,以下为运行效果图: 107 |
example
108 | 109 | ## 关于微博SDK 110 | 你可以在[这里](https://github.com/sinaweibosdk),找到最新的微博 SDK,如果发现 bug 请开 issus,同时也欢迎 star 和 fork 111 | 112 | ## 贡献代码 113 | 欢迎提交 PR,贡献你的代码,如果有新功能,请提供 Demo。 114 | 115 | ## 开源证书 116 | 117 | **cordova-plugin-weibosdk** 遵照了 **MIT** 证书. 详情可以查看 [证书](https://github.com/iVanPan/cordova_weibo/blob/master/LICENSE) 文件 118 | 119 | -------------------------------------------------------------------------------- /ScreenShot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/ScreenShot.png -------------------------------------------------------------------------------- /example_www/css/bootstrap.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.3.7 (http://getbootstrap.com) 3 | * Copyright 2011-2017 Twitter, Inc. 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */ 6 | 7 | /*! 8 | * Generated using the Bootstrap Customizer () 9 | * Config saved to config.json and 10 | */ 11 | /*! 12 | * Bootstrap v3.3.7 (http://getbootstrap.com) 13 | * Copyright 2011-2016 Twitter, Inc. 14 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 15 | */ 16 | /*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */ 17 | html { 18 | font-family: sans-serif; 19 | -ms-text-size-adjust: 100%; 20 | -webkit-text-size-adjust: 100%; 21 | } 22 | body { 23 | margin: 0; 24 | } 25 | article, 26 | aside, 27 | details, 28 | figcaption, 29 | figure, 30 | footer, 31 | header, 32 | hgroup, 33 | main, 34 | menu, 35 | nav, 36 | section, 37 | summary { 38 | display: block; 39 | } 40 | audio, 41 | canvas, 42 | progress, 43 | video { 44 | display: inline-block; 45 | vertical-align: baseline; 46 | } 47 | audio:not([controls]) { 48 | display: none; 49 | height: 0; 50 | } 51 | [hidden], 52 | template { 53 | display: none; 54 | } 55 | a { 56 | background-color: transparent; 57 | } 58 | a:active, 59 | a:hover { 60 | outline: 0; 61 | } 62 | abbr[title] { 63 | border-bottom: 1px dotted; 64 | } 65 | b, 66 | strong { 67 | font-weight: bold; 68 | } 69 | dfn { 70 | font-style: italic; 71 | } 72 | h1 { 73 | font-size: 2em; 74 | margin: 0.67em 0; 75 | } 76 | mark { 77 | background: #ff0; 78 | color: #000; 79 | } 80 | small { 81 | font-size: 80%; 82 | } 83 | sub, 84 | sup { 85 | font-size: 75%; 86 | line-height: 0; 87 | position: relative; 88 | vertical-align: baseline; 89 | } 90 | sup { 91 | top: -0.5em; 92 | } 93 | sub { 94 | bottom: -0.25em; 95 | } 96 | img { 97 | border: 0; 98 | } 99 | svg:not(:root) { 100 | overflow: hidden; 101 | } 102 | figure { 103 | margin: 1em 40px; 104 | } 105 | hr { 106 | -webkit-box-sizing: content-box; 107 | -moz-box-sizing: content-box; 108 | box-sizing: content-box; 109 | height: 0; 110 | } 111 | pre { 112 | overflow: auto; 113 | } 114 | code, 115 | kbd, 116 | pre, 117 | samp { 118 | font-family: monospace, monospace; 119 | font-size: 1em; 120 | } 121 | button, 122 | input, 123 | optgroup, 124 | select, 125 | textarea { 126 | color: inherit; 127 | font: inherit; 128 | margin: 0; 129 | } 130 | button { 131 | overflow: visible; 132 | } 133 | button, 134 | select { 135 | text-transform: none; 136 | } 137 | button, 138 | html input[type="button"], 139 | input[type="reset"], 140 | input[type="submit"] { 141 | -webkit-appearance: button; 142 | cursor: pointer; 143 | } 144 | button[disabled], 145 | html input[disabled] { 146 | cursor: default; 147 | } 148 | button::-moz-focus-inner, 149 | input::-moz-focus-inner { 150 | border: 0; 151 | padding: 0; 152 | } 153 | input { 154 | line-height: normal; 155 | } 156 | input[type="checkbox"], 157 | input[type="radio"] { 158 | -webkit-box-sizing: border-box; 159 | -moz-box-sizing: border-box; 160 | box-sizing: border-box; 161 | padding: 0; 162 | } 163 | input[type="number"]::-webkit-inner-spin-button, 164 | input[type="number"]::-webkit-outer-spin-button { 165 | height: auto; 166 | } 167 | input[type="search"] { 168 | -webkit-appearance: textfield; 169 | -webkit-box-sizing: content-box; 170 | -moz-box-sizing: content-box; 171 | box-sizing: content-box; 172 | } 173 | input[type="search"]::-webkit-search-cancel-button, 174 | input[type="search"]::-webkit-search-decoration { 175 | -webkit-appearance: none; 176 | } 177 | fieldset { 178 | border: 1px solid #c0c0c0; 179 | margin: 0 2px; 180 | padding: 0.35em 0.625em 0.75em; 181 | } 182 | legend { 183 | border: 0; 184 | padding: 0; 185 | } 186 | textarea { 187 | overflow: auto; 188 | } 189 | optgroup { 190 | font-weight: bold; 191 | } 192 | table { 193 | border-collapse: collapse; 194 | border-spacing: 0; 195 | } 196 | td, 197 | th { 198 | padding: 0; 199 | } 200 | * { 201 | -webkit-box-sizing: border-box; 202 | -moz-box-sizing: border-box; 203 | box-sizing: border-box; 204 | } 205 | *:before, 206 | *:after { 207 | -webkit-box-sizing: border-box; 208 | -moz-box-sizing: border-box; 209 | box-sizing: border-box; 210 | } 211 | html { 212 | font-size: 10px; 213 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 214 | } 215 | body { 216 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 217 | font-size: 14px; 218 | line-height: 1.42857143; 219 | color: #333333; 220 | background-color: #ffffff; 221 | } 222 | input, 223 | button, 224 | select, 225 | textarea { 226 | font-family: inherit; 227 | font-size: inherit; 228 | line-height: inherit; 229 | } 230 | a { 231 | color: #337ab7; 232 | text-decoration: none; 233 | } 234 | a:hover, 235 | a:focus { 236 | color: #23527c; 237 | text-decoration: underline; 238 | } 239 | a:focus { 240 | outline: 5px auto -webkit-focus-ring-color; 241 | outline-offset: -2px; 242 | } 243 | figure { 244 | margin: 0; 245 | } 246 | img { 247 | vertical-align: middle; 248 | } 249 | .img-responsive { 250 | display: block; 251 | max-width: 100%; 252 | height: auto; 253 | } 254 | .img-rounded { 255 | border-radius: 6px; 256 | } 257 | .img-thumbnail { 258 | padding: 4px; 259 | line-height: 1.42857143; 260 | background-color: #ffffff; 261 | border: 1px solid #dddddd; 262 | border-radius: 4px; 263 | -webkit-transition: all 0.2s ease-in-out; 264 | -o-transition: all 0.2s ease-in-out; 265 | transition: all 0.2s ease-in-out; 266 | display: inline-block; 267 | max-width: 100%; 268 | height: auto; 269 | } 270 | .img-circle { 271 | border-radius: 50%; 272 | } 273 | hr { 274 | margin-top: 20px; 275 | margin-bottom: 20px; 276 | border: 0; 277 | border-top: 1px solid #eeeeee; 278 | } 279 | .sr-only { 280 | position: absolute; 281 | width: 1px; 282 | height: 1px; 283 | margin: -1px; 284 | padding: 0; 285 | overflow: hidden; 286 | clip: rect(0, 0, 0, 0); 287 | border: 0; 288 | } 289 | .sr-only-focusable:active, 290 | .sr-only-focusable:focus { 291 | position: static; 292 | width: auto; 293 | height: auto; 294 | margin: 0; 295 | overflow: visible; 296 | clip: auto; 297 | } 298 | [role="button"] { 299 | cursor: pointer; 300 | } 301 | .btn { 302 | display: inline-block; 303 | margin-bottom: 0; 304 | font-weight: normal; 305 | text-align: center; 306 | vertical-align: middle; 307 | -ms-touch-action: manipulation; 308 | touch-action: manipulation; 309 | cursor: pointer; 310 | background-image: none; 311 | border: 1px solid transparent; 312 | white-space: nowrap; 313 | padding: 6px 12px; 314 | font-size: 14px; 315 | line-height: 1.42857143; 316 | border-radius: 4px; 317 | -webkit-user-select: none; 318 | -moz-user-select: none; 319 | -ms-user-select: none; 320 | user-select: none; 321 | } 322 | .btn:focus, 323 | .btn:active:focus, 324 | .btn.active:focus, 325 | .btn.focus, 326 | .btn:active.focus, 327 | .btn.active.focus { 328 | outline: 5px auto -webkit-focus-ring-color; 329 | outline-offset: -2px; 330 | } 331 | .btn:hover, 332 | .btn:focus, 333 | .btn.focus { 334 | color: #333333; 335 | text-decoration: none; 336 | } 337 | .btn:active, 338 | .btn.active { 339 | outline: 0; 340 | background-image: none; 341 | -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); 342 | box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); 343 | } 344 | .btn.disabled, 345 | .btn[disabled], 346 | fieldset[disabled] .btn { 347 | cursor: not-allowed; 348 | opacity: 0.65; 349 | filter: alpha(opacity=65); 350 | -webkit-box-shadow: none; 351 | box-shadow: none; 352 | } 353 | a.btn.disabled, 354 | fieldset[disabled] a.btn { 355 | pointer-events: none; 356 | } 357 | .btn-default { 358 | color: #333333; 359 | background-color: #ffffff; 360 | border-color: #cccccc; 361 | } 362 | .btn-default:focus, 363 | .btn-default.focus { 364 | color: #333333; 365 | background-color: #e6e6e6; 366 | border-color: #8c8c8c; 367 | } 368 | .btn-default:hover { 369 | color: #333333; 370 | background-color: #e6e6e6; 371 | border-color: #adadad; 372 | } 373 | .btn-default:active, 374 | .btn-default.active, 375 | .open > .dropdown-toggle.btn-default { 376 | color: #333333; 377 | background-color: #e6e6e6; 378 | border-color: #adadad; 379 | } 380 | .btn-default:active:hover, 381 | .btn-default.active:hover, 382 | .open > .dropdown-toggle.btn-default:hover, 383 | .btn-default:active:focus, 384 | .btn-default.active:focus, 385 | .open > .dropdown-toggle.btn-default:focus, 386 | .btn-default:active.focus, 387 | .btn-default.active.focus, 388 | .open > .dropdown-toggle.btn-default.focus { 389 | color: #333333; 390 | background-color: #d4d4d4; 391 | border-color: #8c8c8c; 392 | } 393 | .btn-default:active, 394 | .btn-default.active, 395 | .open > .dropdown-toggle.btn-default { 396 | background-image: none; 397 | } 398 | .btn-default.disabled:hover, 399 | .btn-default[disabled]:hover, 400 | fieldset[disabled] .btn-default:hover, 401 | .btn-default.disabled:focus, 402 | .btn-default[disabled]:focus, 403 | fieldset[disabled] .btn-default:focus, 404 | .btn-default.disabled.focus, 405 | .btn-default[disabled].focus, 406 | fieldset[disabled] .btn-default.focus { 407 | background-color: #ffffff; 408 | border-color: #cccccc; 409 | } 410 | .btn-default .badge { 411 | color: #ffffff; 412 | background-color: #333333; 413 | } 414 | .btn-primary { 415 | color: #ffffff; 416 | background-color: #337ab7; 417 | border-color: #2e6da4; 418 | } 419 | .btn-primary:focus, 420 | .btn-primary.focus { 421 | color: #ffffff; 422 | background-color: #286090; 423 | border-color: #122b40; 424 | } 425 | .btn-primary:hover { 426 | color: #ffffff; 427 | background-color: #286090; 428 | border-color: #204d74; 429 | } 430 | .btn-primary:active, 431 | .btn-primary.active, 432 | .open > .dropdown-toggle.btn-primary { 433 | color: #ffffff; 434 | background-color: #286090; 435 | border-color: #204d74; 436 | } 437 | .btn-primary:active:hover, 438 | .btn-primary.active:hover, 439 | .open > .dropdown-toggle.btn-primary:hover, 440 | .btn-primary:active:focus, 441 | .btn-primary.active:focus, 442 | .open > .dropdown-toggle.btn-primary:focus, 443 | .btn-primary:active.focus, 444 | .btn-primary.active.focus, 445 | .open > .dropdown-toggle.btn-primary.focus { 446 | color: #ffffff; 447 | background-color: #204d74; 448 | border-color: #122b40; 449 | } 450 | .btn-primary:active, 451 | .btn-primary.active, 452 | .open > .dropdown-toggle.btn-primary { 453 | background-image: none; 454 | } 455 | .btn-primary.disabled:hover, 456 | .btn-primary[disabled]:hover, 457 | fieldset[disabled] .btn-primary:hover, 458 | .btn-primary.disabled:focus, 459 | .btn-primary[disabled]:focus, 460 | fieldset[disabled] .btn-primary:focus, 461 | .btn-primary.disabled.focus, 462 | .btn-primary[disabled].focus, 463 | fieldset[disabled] .btn-primary.focus { 464 | background-color: #337ab7; 465 | border-color: #2e6da4; 466 | } 467 | .btn-primary .badge { 468 | color: #337ab7; 469 | background-color: #ffffff; 470 | } 471 | .btn-success { 472 | color: #ffffff; 473 | background-color: #5cb85c; 474 | border-color: #4cae4c; 475 | } 476 | .btn-success:focus, 477 | .btn-success.focus { 478 | color: #ffffff; 479 | background-color: #449d44; 480 | border-color: #255625; 481 | } 482 | .btn-success:hover { 483 | color: #ffffff; 484 | background-color: #449d44; 485 | border-color: #398439; 486 | } 487 | .btn-success:active, 488 | .btn-success.active, 489 | .open > .dropdown-toggle.btn-success { 490 | color: #ffffff; 491 | background-color: #449d44; 492 | border-color: #398439; 493 | } 494 | .btn-success:active:hover, 495 | .btn-success.active:hover, 496 | .open > .dropdown-toggle.btn-success:hover, 497 | .btn-success:active:focus, 498 | .btn-success.active:focus, 499 | .open > .dropdown-toggle.btn-success:focus, 500 | .btn-success:active.focus, 501 | .btn-success.active.focus, 502 | .open > .dropdown-toggle.btn-success.focus { 503 | color: #ffffff; 504 | background-color: #398439; 505 | border-color: #255625; 506 | } 507 | .btn-success:active, 508 | .btn-success.active, 509 | .open > .dropdown-toggle.btn-success { 510 | background-image: none; 511 | } 512 | .btn-success.disabled:hover, 513 | .btn-success[disabled]:hover, 514 | fieldset[disabled] .btn-success:hover, 515 | .btn-success.disabled:focus, 516 | .btn-success[disabled]:focus, 517 | fieldset[disabled] .btn-success:focus, 518 | .btn-success.disabled.focus, 519 | .btn-success[disabled].focus, 520 | fieldset[disabled] .btn-success.focus { 521 | background-color: #5cb85c; 522 | border-color: #4cae4c; 523 | } 524 | .btn-success .badge { 525 | color: #5cb85c; 526 | background-color: #ffffff; 527 | } 528 | .btn-info { 529 | color: #ffffff; 530 | background-color: #5bc0de; 531 | border-color: #46b8da; 532 | } 533 | .btn-info:focus, 534 | .btn-info.focus { 535 | color: #ffffff; 536 | background-color: #31b0d5; 537 | border-color: #1b6d85; 538 | } 539 | .btn-info:hover { 540 | color: #ffffff; 541 | background-color: #31b0d5; 542 | border-color: #269abc; 543 | } 544 | .btn-info:active, 545 | .btn-info.active, 546 | .open > .dropdown-toggle.btn-info { 547 | color: #ffffff; 548 | background-color: #31b0d5; 549 | border-color: #269abc; 550 | } 551 | .btn-info:active:hover, 552 | .btn-info.active:hover, 553 | .open > .dropdown-toggle.btn-info:hover, 554 | .btn-info:active:focus, 555 | .btn-info.active:focus, 556 | .open > .dropdown-toggle.btn-info:focus, 557 | .btn-info:active.focus, 558 | .btn-info.active.focus, 559 | .open > .dropdown-toggle.btn-info.focus { 560 | color: #ffffff; 561 | background-color: #269abc; 562 | border-color: #1b6d85; 563 | } 564 | .btn-info:active, 565 | .btn-info.active, 566 | .open > .dropdown-toggle.btn-info { 567 | background-image: none; 568 | } 569 | .btn-info.disabled:hover, 570 | .btn-info[disabled]:hover, 571 | fieldset[disabled] .btn-info:hover, 572 | .btn-info.disabled:focus, 573 | .btn-info[disabled]:focus, 574 | fieldset[disabled] .btn-info:focus, 575 | .btn-info.disabled.focus, 576 | .btn-info[disabled].focus, 577 | fieldset[disabled] .btn-info.focus { 578 | background-color: #5bc0de; 579 | border-color: #46b8da; 580 | } 581 | .btn-info .badge { 582 | color: #5bc0de; 583 | background-color: #ffffff; 584 | } 585 | .btn-warning { 586 | color: #ffffff; 587 | background-color: #f0ad4e; 588 | border-color: #eea236; 589 | } 590 | .btn-warning:focus, 591 | .btn-warning.focus { 592 | color: #ffffff; 593 | background-color: #ec971f; 594 | border-color: #985f0d; 595 | } 596 | .btn-warning:hover { 597 | color: #ffffff; 598 | background-color: #ec971f; 599 | border-color: #d58512; 600 | } 601 | .btn-warning:active, 602 | .btn-warning.active, 603 | .open > .dropdown-toggle.btn-warning { 604 | color: #ffffff; 605 | background-color: #ec971f; 606 | border-color: #d58512; 607 | } 608 | .btn-warning:active:hover, 609 | .btn-warning.active:hover, 610 | .open > .dropdown-toggle.btn-warning:hover, 611 | .btn-warning:active:focus, 612 | .btn-warning.active:focus, 613 | .open > .dropdown-toggle.btn-warning:focus, 614 | .btn-warning:active.focus, 615 | .btn-warning.active.focus, 616 | .open > .dropdown-toggle.btn-warning.focus { 617 | color: #ffffff; 618 | background-color: #d58512; 619 | border-color: #985f0d; 620 | } 621 | .btn-warning:active, 622 | .btn-warning.active, 623 | .open > .dropdown-toggle.btn-warning { 624 | background-image: none; 625 | } 626 | .btn-warning.disabled:hover, 627 | .btn-warning[disabled]:hover, 628 | fieldset[disabled] .btn-warning:hover, 629 | .btn-warning.disabled:focus, 630 | .btn-warning[disabled]:focus, 631 | fieldset[disabled] .btn-warning:focus, 632 | .btn-warning.disabled.focus, 633 | .btn-warning[disabled].focus, 634 | fieldset[disabled] .btn-warning.focus { 635 | background-color: #f0ad4e; 636 | border-color: #eea236; 637 | } 638 | .btn-warning .badge { 639 | color: #f0ad4e; 640 | background-color: #ffffff; 641 | } 642 | .btn-danger { 643 | color: #ffffff; 644 | background-color: #d9534f; 645 | border-color: #d43f3a; 646 | } 647 | .btn-danger:focus, 648 | .btn-danger.focus { 649 | color: #ffffff; 650 | background-color: #c9302c; 651 | border-color: #761c19; 652 | } 653 | .btn-danger:hover { 654 | color: #ffffff; 655 | background-color: #c9302c; 656 | border-color: #ac2925; 657 | } 658 | .btn-danger:active, 659 | .btn-danger.active, 660 | .open > .dropdown-toggle.btn-danger { 661 | color: #ffffff; 662 | background-color: #c9302c; 663 | border-color: #ac2925; 664 | } 665 | .btn-danger:active:hover, 666 | .btn-danger.active:hover, 667 | .open > .dropdown-toggle.btn-danger:hover, 668 | .btn-danger:active:focus, 669 | .btn-danger.active:focus, 670 | .open > .dropdown-toggle.btn-danger:focus, 671 | .btn-danger:active.focus, 672 | .btn-danger.active.focus, 673 | .open > .dropdown-toggle.btn-danger.focus { 674 | color: #ffffff; 675 | background-color: #ac2925; 676 | border-color: #761c19; 677 | } 678 | .btn-danger:active, 679 | .btn-danger.active, 680 | .open > .dropdown-toggle.btn-danger { 681 | background-image: none; 682 | } 683 | .btn-danger.disabled:hover, 684 | .btn-danger[disabled]:hover, 685 | fieldset[disabled] .btn-danger:hover, 686 | .btn-danger.disabled:focus, 687 | .btn-danger[disabled]:focus, 688 | fieldset[disabled] .btn-danger:focus, 689 | .btn-danger.disabled.focus, 690 | .btn-danger[disabled].focus, 691 | fieldset[disabled] .btn-danger.focus { 692 | background-color: #d9534f; 693 | border-color: #d43f3a; 694 | } 695 | .btn-danger .badge { 696 | color: #d9534f; 697 | background-color: #ffffff; 698 | } 699 | .btn-link { 700 | color: #337ab7; 701 | font-weight: normal; 702 | border-radius: 0; 703 | } 704 | .btn-link, 705 | .btn-link:active, 706 | .btn-link.active, 707 | .btn-link[disabled], 708 | fieldset[disabled] .btn-link { 709 | background-color: transparent; 710 | -webkit-box-shadow: none; 711 | box-shadow: none; 712 | } 713 | .btn-link, 714 | .btn-link:hover, 715 | .btn-link:focus, 716 | .btn-link:active { 717 | border-color: transparent; 718 | } 719 | .btn-link:hover, 720 | .btn-link:focus { 721 | color: #23527c; 722 | text-decoration: underline; 723 | background-color: transparent; 724 | } 725 | .btn-link[disabled]:hover, 726 | fieldset[disabled] .btn-link:hover, 727 | .btn-link[disabled]:focus, 728 | fieldset[disabled] .btn-link:focus { 729 | color: #777777; 730 | text-decoration: none; 731 | } 732 | .btn-lg { 733 | padding: 10px 16px; 734 | font-size: 18px; 735 | line-height: 1.3333333; 736 | border-radius: 6px; 737 | } 738 | .btn-sm { 739 | padding: 5px 10px; 740 | font-size: 12px; 741 | line-height: 1.5; 742 | border-radius: 3px; 743 | } 744 | .btn-xs { 745 | padding: 1px 5px; 746 | font-size: 12px; 747 | line-height: 1.5; 748 | border-radius: 3px; 749 | } 750 | .btn-block { 751 | display: block; 752 | width: 100%; 753 | } 754 | .btn-block + .btn-block { 755 | margin-top: 5px; 756 | } 757 | input[type="submit"].btn-block, 758 | input[type="reset"].btn-block, 759 | input[type="button"].btn-block { 760 | width: 100%; 761 | } 762 | .clearfix:before, 763 | .clearfix:after { 764 | content: " "; 765 | display: table; 766 | } 767 | .clearfix:after { 768 | clear: both; 769 | } 770 | .center-block { 771 | display: block; 772 | margin-left: auto; 773 | margin-right: auto; 774 | } 775 | .pull-right { 776 | float: right !important; 777 | } 778 | .pull-left { 779 | float: left !important; 780 | } 781 | .hide { 782 | display: none !important; 783 | } 784 | .show { 785 | display: block !important; 786 | } 787 | .invisible { 788 | visibility: hidden; 789 | } 790 | .text-hide { 791 | font: 0/0 a; 792 | color: transparent; 793 | text-shadow: none; 794 | background-color: transparent; 795 | border: 0; 796 | } 797 | .hidden { 798 | display: none !important; 799 | } 800 | .affix { 801 | position: fixed; 802 | } 803 | -------------------------------------------------------------------------------- /example_www/css/index.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | * { 20 | -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */ 21 | } 22 | 23 | body { 24 | -webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */ 25 | -webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */ 26 | -webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */ 27 | background-color:#E4E4E4; 28 | background-image:linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); 29 | background-image:-webkit-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); 30 | background-image:-ms-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); 31 | background-image:-webkit-gradient( 32 | linear, 33 | left top, 34 | left bottom, 35 | color-stop(0, #A7A7A7), 36 | color-stop(0.51, #E4E4E4) 37 | ); 38 | background-attachment:fixed; 39 | font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif; 40 | font-size:12px; 41 | height:100%; 42 | margin:0px; 43 | padding:0px; 44 | text-transform:uppercase; 45 | width:100%; 46 | } 47 | 48 | /* Portrait layout (default) */ 49 | .app { 50 | background:url(../img/logo.png) no-repeat center top; /* 170px x 200px */ 51 | position:absolute; /* position in the center of the screen */ 52 | left:50%; 53 | top:25%; 54 | height:50px; /* text area height */ 55 | width:225px; /* text area width */ 56 | text-align:center; 57 | padding:180px 0px 0px 0px; /* image height is 200px (bottom 20px are overlapped with text) */ 58 | margin:-115px 0px 0px -112px; /* offset vertical: half of image height and text area height */ 59 | /* offset horizontal: half of text area width */ 60 | } 61 | 62 | /* Landscape layout (with min-width) */ 63 | @media screen and (min-aspect-ratio: 1/1) and (min-width:400px) { 64 | .app { 65 | background-position:left center; 66 | padding:75px 0px 75px 170px; /* padding-top + padding-bottom + text area = image height */ 67 | margin:-90px 0px 0px -198px; /* offset vertical: half of image height */ 68 | /* offset horizontal: half of image width and text area width */ 69 | } 70 | } 71 | 72 | h1 { 73 | font-size:24px; 74 | font-weight:normal; 75 | margin:0px; 76 | overflow:visible; 77 | padding:0px; 78 | text-align:center; 79 | } 80 | 81 | .event { 82 | border-radius:4px; 83 | -webkit-border-radius:4px; 84 | color:#FFFFFF; 85 | font-size:12px; 86 | margin:0px 30px; 87 | padding:2px 0px; 88 | } 89 | 90 | .event.listening { 91 | background-color:#333333; 92 | display:block; 93 | } 94 | 95 | .event.received { 96 | background-color:#4B946A; 97 | display:none; 98 | } 99 | 100 | @keyframes fade { 101 | from { opacity: 1.0; } 102 | 50% { opacity: 0.4; } 103 | to { opacity: 1.0; } 104 | } 105 | 106 | @-webkit-keyframes fade { 107 | from { opacity: 1.0; } 108 | 50% { opacity: 0.4; } 109 | to { opacity: 1.0; } 110 | } 111 | 112 | .blink { 113 | animation:fade 3000ms infinite; 114 | -webkit-animation:fade 3000ms infinite; 115 | } 116 | -------------------------------------------------------------------------------- /example_www/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/example_www/img/logo.png -------------------------------------------------------------------------------- /example_www/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 17 | Corodva Weibo Plugin Exmaple 18 | 19 | 20 |
21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /example_www/js/index.js: -------------------------------------------------------------------------------- 1 | var app = function () { 2 | this.checkClientInstalled = function () { 3 | WeiboSDK.checkClientInstalled(function () { 4 | alert('client is installed'); 5 | }, function () { 6 | alert('client is not installed'); 7 | }); 8 | }; 9 | 10 | this.ssoLogin = function () { 11 | WeiboSDK.ssoLogin(function (args) { 12 | alert('access token is ' + args.access_token); 13 | alert('userId is ' + args.userId); 14 | alert('expires_time is ' + new Date(parseInt(args.expires_time)) + ' TimeStamp is ' + args.expires_time); 15 | }, function (failReason) { 16 | alert(failReason); 17 | }); 18 | }; 19 | 20 | this.shareToWeibo = function () { 21 | var args = {}; 22 | args.url = 'https://cordova.apache.org/'; 23 | args.title = 'Apache Cordova'; 24 | args.description = 'This is a Cordova Plugin'; 25 | args.image = 'https://cordova.apache.org/static/img/pluggy.png'; 26 | WeiboSDK.shareToWeibo(function () { 27 | alert('share success'); 28 | }, function (failReason) { 29 | alert(failReason); 30 | }, args); 31 | }; 32 | 33 | this.shareImageToWeibo = function () { 34 | var args = {}; 35 | args.image = 'https://cordova.apache.org/static/img/pluggy.png'; 36 | WeiboSDK.shareImageToWeibo(function () { 37 | alert('share success'); 38 | }, function (failReason) { 39 | alert(failReason); 40 | }, args); 41 | }; 42 | 43 | this.shareTextToWeibo = function () { 44 | var args = {}; 45 | args.text = 'This is a Cordova Plugin'; 46 | WeiboSDK.shareTextToWeibo(function () { 47 | alert('share success'); 48 | }, function (failReason) { 49 | alert(failReason); 50 | }, args); 51 | }; 52 | 53 | this.logout = function () { 54 | WeiboSDK.logout(function () { 55 | alert('logout success'); 56 | }, function (failReason) { 57 | alert(failReason); 58 | }); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-plugin-weibosdk", 3 | "version": "0.6.4", 4 | "description": "codrova/phonegap wrapper for weibo sdk", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/iVanPan/cordova_weibo.git" 12 | }, 13 | "cordova": { 14 | "id": "cordova-plugin-weibosdk", 15 | "platforms": [ 16 | "android", 17 | "ios" 18 | ] 19 | }, 20 | "keywords": [ 21 | "ecosystem:cordova", 22 | "cordova-android", 23 | "cordova-ios", 24 | "cordova", 25 | "phonegap", 26 | "plugin", 27 | "weibosdk", 28 | "weibo", 29 | "sina", 30 | "login", 31 | "share" 32 | ], 33 | "engines": [ 34 | { 35 | "name": "cordova-android", 36 | "version": ">=7.0.0" 37 | } 38 | ], 39 | "author": "https://github.com/iVanPan", 40 | "license": "MIT", 41 | "bugs": { 42 | "url": "https://github.com/iVanPan/cordova_weibo/issues" 43 | }, 44 | "homepage": "https://github.com/iVanPan/cordova_weibo" 45 | } 46 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | WeiboSDK 8 | A Cordova wrapper around the Sina WeiboSDK for Android and iOS. Provides access to ssoLogin, WeiboShating etc 9 | MIT 10 | Cordova,Weibo 11 | https://github.com/iVanPan/cordova_weibo.git 12 | https://github.com/iVanPan/cordova_weibo/issues 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | CFBundleTypeRole 46 | Editor 47 | CFBundleURLName 48 | $PACKAGE_NAME 49 | CFBundleURLSchemes 50 | 51 | wb$WEIBO_APP_ID 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | sinaweibohd 60 | sinaweibo 61 | weibosdk 62 | weibosdk2.5 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 1.安装完这个插件,请用 Xcode 打开工程,查看 URL Types 里面 Weibo 的 URL Type 有没有,如果没有请手动添加。 87 | 88 | 1.after installing this plugin,check the URL Types in your Xcode project.If you don't find URL Types for weibosdk,manually add it. 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /src/android/WeiboSDKPlugin.java: -------------------------------------------------------------------------------- 1 | package me.vanpan.weibosdk; 2 | 3 | import android.content.Intent; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.util.Base64; 7 | import android.webkit.URLUtil; 8 | 9 | import com.sina.weibo.sdk.WbSdk; 10 | import com.sina.weibo.sdk.WeiboAppManager; 11 | import com.sina.weibo.sdk.api.ImageObject; 12 | import com.sina.weibo.sdk.api.TextObject; 13 | import com.sina.weibo.sdk.api.WeiboMultiMessage; 14 | import com.sina.weibo.sdk.auth.AccessTokenKeeper; 15 | import com.sina.weibo.sdk.auth.AuthInfo; 16 | import com.sina.weibo.sdk.auth.Oauth2AccessToken; 17 | import com.sina.weibo.sdk.auth.WbAppInfo; 18 | import com.sina.weibo.sdk.auth.WbConnectErrorMessage; 19 | import com.sina.weibo.sdk.auth.sso.SsoHandler; 20 | import com.sina.weibo.sdk.share.WbShareCallback; 21 | import com.sina.weibo.sdk.share.WbShareHandler; 22 | 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | import java.net.HttpURLConnection; 26 | import java.net.URL; 27 | import org.apache.cordova.CallbackContext; 28 | import org.apache.cordova.CordovaArgs; 29 | import org.apache.cordova.CordovaPlugin; 30 | import org.apache.cordova.PluginResult; 31 | import org.json.JSONException; 32 | import org.json.JSONObject; 33 | 34 | public class WeiboSDKPlugin extends CordovaPlugin implements WbShareCallback { 35 | 36 | private static final String SCOPE = "email,direct_messages_read,direct_messages_write," 37 | + "friendships_groups_read,friendships_groups_write,statuses_to_me_read," 38 | + "follow_app_official_microblog," + "invitation_write"; 39 | private static final String WEBIO_APP_ID = "weibo_app_id"; 40 | private static final String WEBIO_REDIRECT_URL = "redirecturi"; 41 | private static final String DEFAULT_URL = "https://api.weibo.com/oauth2/default.html"; 42 | private static final String CANCEL_BY_USER = "cancel by user"; 43 | private static final String WEIBO_EXCEPTION = "weibo exception"; 44 | private static final String PARAM_ERROR = "param error"; 45 | private static final String ONLY_GET_CODE = "only get code"; 46 | private static final String SHARE_FAIL ="sharefail"; 47 | private static final String WEIBO_CLIENT_NOT_INSTALLED = "weibo client is not installed"; 48 | public static CallbackContext currentCallbackContext; 49 | public static String APP_KEY; 50 | public static WbShareHandler shareHandler = null; 51 | private Oauth2AccessToken mAccessToken; 52 | private String REDIRECT_URL; 53 | private SsoHandler mSsoHandler; 54 | 55 | @Override 56 | protected void pluginInitialize() { 57 | super.pluginInitialize(); 58 | // The first letter "a" was added in plugin.xml to avoid the string be parsed as 59 | // a number, remove it here. 60 | APP_KEY = webView.getPreferences().getString(WEBIO_APP_ID, "a").substring(1); 61 | REDIRECT_URL = webView.getPreferences().getString(WEBIO_REDIRECT_URL, DEFAULT_URL); 62 | WbSdk.install(WeiboSDKPlugin.this.cordova.getActivity(),new AuthInfo(WeiboSDKPlugin.this.cordova.getActivity(), APP_KEY, REDIRECT_URL, SCOPE)); 63 | } 64 | 65 | @Override 66 | public boolean execute(String action, final CordovaArgs args, 67 | final CallbackContext callbackContext) throws JSONException { 68 | if (action.equalsIgnoreCase("ssoLogin")) { 69 | return ssoLogin(callbackContext); 70 | } else if (action.equalsIgnoreCase("logout")) { 71 | return logout(callbackContext); 72 | } else if (action.equalsIgnoreCase("shareToWeibo")) { 73 | return shareToWeibo(callbackContext, args); 74 | } else if (action.equalsIgnoreCase("checkClientInstalled")) { 75 | return checkClientInstalled(callbackContext); 76 | } else if (action.equalsIgnoreCase("shareImageToWeibo")) { 77 | return shareImageToWeibo(callbackContext,args); 78 | } else if (action.equalsIgnoreCase("shareTextToWeibo")) { 79 | return shareTextToWeibo(callbackContext,args); 80 | } 81 | return super.execute(action, args, callbackContext); 82 | } 83 | 84 | /** 85 | * weibo sso 登录 86 | * 87 | * @param callbackContext 88 | * @return 89 | */ 90 | private boolean ssoLogin(CallbackContext callbackContext) { 91 | currentCallbackContext = callbackContext; 92 | mSsoHandler = new SsoHandler(WeiboSDKPlugin.this.cordova.getActivity()); 93 | Runnable runnable = new Runnable() { 94 | public void run() { 95 | if (mSsoHandler != null) { 96 | mSsoHandler.authorize(new SelfWbAuthListener()); 97 | } 98 | } 99 | }; 100 | this.cordova.setActivityResultCallback(this); 101 | this.cordova.getActivity().runOnUiThread(runnable); 102 | return true; 103 | } 104 | 105 | /** 106 | * 检查微博客户端是否安装 107 | * 108 | * @param callbackContext 109 | * @return 110 | */ 111 | private boolean checkClientInstalled(CallbackContext callbackContext) { 112 | WbAppInfo wbAppInfo = WeiboAppManager.getInstance(WeiboSDKPlugin.this.cordova.getActivity()).getWbAppInfo(); 113 | Boolean installed = (wbAppInfo != null && wbAppInfo.isLegal()); 114 | if (installed) { 115 | callbackContext.success(); 116 | } else { 117 | callbackContext.error(WEIBO_CLIENT_NOT_INSTALLED); 118 | } 119 | return true; 120 | } 121 | 122 | /** 123 | * 微博登出 124 | * 125 | * @param callbackContext 126 | * @return 127 | */ 128 | private boolean logout(CallbackContext callbackContext) { 129 | AccessTokenKeeper.clear(this.cordova.getActivity()); 130 | mAccessToken = new Oauth2AccessToken(); 131 | callbackContext.success(); 132 | return true; 133 | } 134 | 135 | /** 136 | * 微博分享网页 137 | * 138 | * @param callbackContext 139 | * @param args 140 | * @return 141 | */ 142 | private boolean shareToWeibo(final CallbackContext callbackContext, 143 | final CordovaArgs args) { 144 | currentCallbackContext = callbackContext; 145 | if (shareHandler == null) { 146 | shareHandler = new WbShareHandler(WeiboSDKPlugin.this.cordova.getActivity()); 147 | } 148 | shareHandler.registerApp(); 149 | cordova.getThreadPool().execute(new Runnable() { 150 | 151 | @Override 152 | public void run() { 153 | sendMultiMessage(callbackContext,args); 154 | } 155 | }); 156 | return true; 157 | } 158 | 159 | /** 160 | * 微博图片分享 161 | * @param callbackContext 162 | * @param args 163 | * @return 164 | */ 165 | private boolean shareImageToWeibo(final CallbackContext callbackContext, 166 | final CordovaArgs args) { 167 | currentCallbackContext = callbackContext; 168 | if (shareHandler == null) { 169 | shareHandler = new WbShareHandler(WeiboSDKPlugin.this.cordova.getActivity()); 170 | } 171 | shareHandler.registerApp(); 172 | cordova.getThreadPool().execute(new Runnable() { 173 | 174 | @Override 175 | public void run() { 176 | sendImageMessage(callbackContext,args); 177 | } 178 | }); 179 | return true; 180 | } 181 | 182 | /** 183 | * 分享文字到微博 184 | * @param callbackContext 185 | * @param args 186 | * @return 187 | */ 188 | private boolean shareTextToWeibo(final CallbackContext callbackContext, 189 | final CordovaArgs args) { 190 | currentCallbackContext = callbackContext; 191 | if (shareHandler == null) { 192 | shareHandler = new WbShareHandler(WeiboSDKPlugin.this.cordova.getActivity()); 193 | } 194 | shareHandler.registerApp(); 195 | cordova.getThreadPool().execute(new Runnable() { 196 | 197 | @Override 198 | public void run() { 199 | sendTextMessage(callbackContext,args); 200 | } 201 | }); 202 | return true; 203 | } 204 | 205 | @Override 206 | public void onActivityResult(int requestCode, int resultCode, Intent intent) { 207 | super.onActivityResult(requestCode, resultCode, intent); 208 | if (mSsoHandler != null && requestCode == 32973) { 209 | mSsoHandler.authorizeCallBack(requestCode, resultCode, intent); 210 | } else if(requestCode == 1) { 211 | WeiboSDKPlugin.shareHandler.doResultIntent(intent,this); 212 | } 213 | } 214 | 215 | /** 216 | * 第三方应用发送请求消息到微博,唤起微博分享界面。 217 | */ 218 | private void sendMultiMessage(final CallbackContext callbackContext, CordovaArgs args) { 219 | // 1. 初始化微博的分享消息 220 | WeiboMultiMessage weiboMessage = new WeiboMultiMessage(); 221 | final JSONObject data; 222 | try { 223 | data = args.getJSONObject(0); 224 | String title = data.has("title")? data.getString("title"): ""; 225 | String url = data.has("url")? data.getString("url"): ""; 226 | String description = data.has("description")? data.getString("description"): ""; 227 | String image = data.has("image")? data.getString("image"): ""; 228 | Bitmap imageData = processImage(image); 229 | //WebpageObject mediaObject = new WebpageObject(); 230 | //mediaObject.identify = Utility.generateGUID(); 231 | //mediaObject.title = title; 232 | //mediaObject.description = description; 233 | //mediaObject.actionUrl = url; 234 | if (imageData != null) { 235 | //注意:最终压缩过的缩略图大小不得超过 32kb。 236 | ImageObject imageObject = new ImageObject(); 237 | imageObject.setImageObject(imageData); 238 | weiboMessage.imageObject = imageObject; 239 | // mediaObject.setThumbImage(imageData); 240 | } 241 | // weiboMessage.mediaObject = mediaObject; 242 | TextObject textObject = new TextObject(); 243 | textObject.text = description + " " + url; 244 | textObject.title = title; 245 | weiboMessage.textObject = textObject; 246 | shareHandler.shareMessage(weiboMessage, false); 247 | } catch (JSONException e) { 248 | WeiboSDKPlugin.this.webView.sendPluginResult(new PluginResult( 249 | PluginResult.Status.ERROR, PARAM_ERROR), 250 | callbackContext.getCallbackId()); 251 | } 252 | } 253 | 254 | /** 255 | * 组装图片分享消息 256 | * @param callbackContext 257 | * @param args 258 | */ 259 | private void sendImageMessage(final CallbackContext callbackContext, CordovaArgs args) { 260 | WeiboMultiMessage weiboMessage = new WeiboMultiMessage(); 261 | final JSONObject data; 262 | try { 263 | data = args.getJSONObject(0); 264 | String image = data.has("image")? data.getString("image"): ""; 265 | Bitmap imageData = processImage(image); 266 | if (imageData != null) { 267 | //注意:最终压缩过的缩略图大小不得超过 32kb。 268 | ImageObject imageObject = new ImageObject(); 269 | imageObject.setImageObject(imageData); 270 | weiboMessage.imageObject = imageObject; 271 | } 272 | shareHandler.shareMessage(weiboMessage, false); 273 | } catch (JSONException e) { 274 | WeiboSDKPlugin.this.webView.sendPluginResult(new PluginResult( 275 | PluginResult.Status.ERROR, PARAM_ERROR), 276 | callbackContext.getCallbackId()); 277 | } 278 | } 279 | 280 | /** 281 | * 组装微博文字分享消息 282 | * @param callbackContext 283 | * @param args 284 | */ 285 | private void sendTextMessage(final CallbackContext callbackContext, CordovaArgs args) { 286 | // 1. 初始化微博的分享消息 287 | WeiboMultiMessage weiboMessage = new WeiboMultiMessage(); 288 | final JSONObject data; 289 | try { 290 | data = args.getJSONObject(0); 291 | String text = data.has("text")? data.getString("text"): ""; 292 | TextObject textObject = new TextObject(); 293 | textObject.text = text; 294 | weiboMessage.textObject = textObject; 295 | shareHandler.shareMessage(weiboMessage, false); 296 | } catch (JSONException e) { 297 | WeiboSDKPlugin.this.webView.sendPluginResult(new PluginResult( 298 | PluginResult.Status.ERROR, PARAM_ERROR), 299 | callbackContext.getCallbackId()); 300 | } 301 | } 302 | /** 303 | * 组装JSON 304 | * 305 | * @param access_token 306 | * @param userId 307 | * @param expires_time 308 | * @return 309 | */ 310 | private JSONObject makeJson(String access_token, String userId, long expires_time) { 311 | String json = "{\"access_token\": \"" + access_token + "\", " + 312 | " \"userId\": \"" + userId 313 | + "\", " + 314 | " \"expires_time\": \"" + String.valueOf(expires_time) + "\"" + 315 | "}"; 316 | JSONObject jo = null; 317 | try { 318 | jo = new JSONObject(json); 319 | } catch (JSONException e) { 320 | e.printStackTrace(); 321 | } 322 | return jo; 323 | } 324 | /** 325 | * 处理图片 326 | * @param image 327 | * @return 328 | */ 329 | private Bitmap processImage(String image) { 330 | if(URLUtil.isHttpUrl(image) || URLUtil.isHttpsUrl(image)) { 331 | return getBitmapFromURL(image); 332 | } else if (isBase64(image)) { 333 | return decodeBase64ToBitmap(image); 334 | } else { 335 | return getBitmapByPath(image); 336 | } 337 | } 338 | 339 | /** 340 | * 检查图片字符串是不是Base64 341 | * @param image 342 | * @return 343 | */ 344 | private boolean isBase64(String image) { 345 | try { 346 | byte[] decodedString = Base64.decode(image, Base64.DEFAULT); 347 | Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 348 | if (bitmap == null) { 349 | return false; 350 | } 351 | return true; 352 | } catch (Exception e) { 353 | return false; 354 | } 355 | } 356 | 357 | /** 358 | * 将图片的 URL 转化为 Bitmap 359 | * @param src 360 | * @return 361 | */ 362 | public static Bitmap getBitmapFromURL(String src) { 363 | try { 364 | URL url = new URL(src); 365 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 366 | connection.setDoInput(true); 367 | connection.connect(); 368 | InputStream input = connection.getInputStream(); 369 | Bitmap bitmap = BitmapFactory.decodeStream(input); 370 | return bitmap; 371 | } catch (IOException e) { 372 | return null; 373 | } 374 | } 375 | 376 | /** 377 | * 根据文件路径生成 Bitmap 378 | * @param path 379 | * @return 380 | */ 381 | public static Bitmap getBitmapByPath(String path) { 382 | if (path == null) 383 | return null; 384 | try { 385 | Bitmap bitmap = BitmapFactory.decodeFile(path); 386 | return bitmap; 387 | } catch (Exception e) { 388 | e.printStackTrace(); 389 | return null; 390 | } catch (Error e) { 391 | e.printStackTrace(); 392 | return null; 393 | } 394 | } 395 | 396 | /** 397 | * 将Base64解码成Bitmap 398 | */ 399 | 400 | private Bitmap decodeBase64ToBitmap(String Base64String) { 401 | byte[] decode = Base64.decode(Base64String, Base64.DEFAULT); 402 | Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length); 403 | return bitmap; 404 | } 405 | 406 | @Override public void onWbShareSuccess() { 407 | WeiboSDKPlugin.currentCallbackContext.success(); 408 | } 409 | 410 | @Override public void onWbShareCancel() { 411 | WeiboSDKPlugin.currentCallbackContext.error(CANCEL_BY_USER); 412 | } 413 | 414 | @Override public void onWbShareFail() { 415 | WeiboSDKPlugin.currentCallbackContext.error(SHARE_FAIL); 416 | } 417 | 418 | // @Override 419 | // public void onNewIntent(Intent intent) { 420 | // super.onNewIntent(intent); 421 | // WeiboSDKPlugin.shareHandler.doResultIntent(intent,this); 422 | // } 423 | 424 | private class SelfWbAuthListener implements com.sina.weibo.sdk.auth.WbAuthListener{ 425 | @Override 426 | public void onSuccess(final Oauth2AccessToken token) { 427 | mAccessToken = token; 428 | if (mAccessToken.isSessionValid()) { 429 | AccessTokenKeeper.writeAccessToken( 430 | WeiboSDKPlugin.this.cordova.getActivity(), mAccessToken); 431 | JSONObject jo = makeJson(mAccessToken.getToken(), 432 | mAccessToken.getUid(),mAccessToken.getExpiresTime()); 433 | WeiboSDKPlugin.this.webView.sendPluginResult(new PluginResult( 434 | PluginResult.Status.OK, jo), currentCallbackContext.getCallbackId()); 435 | } else { 436 | // 以下几种情况,您会收到 Code: 437 | // 1. 当您未在平台上注册的应用程序的包名与签名时; 438 | // 2. 当您注册的应用程序包名与签名不正确时; 439 | // 3. 当您在平台上注册的包名和签名与您当前测试的应用的包名和签名不匹配时。 440 | // String code = values.getString("code"); 441 | WeiboSDKPlugin.this.webView.sendPluginResult(new PluginResult( 442 | PluginResult.Status.ERROR, ONLY_GET_CODE), 443 | currentCallbackContext.getCallbackId()); 444 | } 445 | } 446 | 447 | @Override 448 | public void cancel() { 449 | WeiboSDKPlugin.this.webView.sendPluginResult(new PluginResult( 450 | PluginResult.Status.ERROR, CANCEL_BY_USER), 451 | currentCallbackContext.getCallbackId()); 452 | } 453 | 454 | @Override 455 | public void onFailure(WbConnectErrorMessage errorMessage) { 456 | WeiboSDKPlugin.this.webView.sendPluginResult(new PluginResult( 457 | PluginResult.Status.ERROR, WEIBO_EXCEPTION), 458 | currentCallbackContext.getCallbackId()); 459 | } 460 | } 461 | } 462 | -------------------------------------------------------------------------------- /src/android/libs/WeiboSDKPlugin.gradle: -------------------------------------------------------------------------------- 1 | 2 | repositories{ 3 | flatDir { 4 | dirs 'libs' 5 | } 6 | } 7 | 8 | dependencies { 9 | compile(name: 'openDefault-4.3.6', ext: 'aar') 10 | } 11 | -------------------------------------------------------------------------------- /src/android/libs/openDefault-4.3.6.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/android/libs/openDefault-4.3.6.aar -------------------------------------------------------------------------------- /src/android/libs/so/arm64-v8a/libweibosdkcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/android/libs/so/arm64-v8a/libweibosdkcore.so -------------------------------------------------------------------------------- /src/android/libs/so/armeabi-v7a/libweibosdkcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/android/libs/so/armeabi-v7a/libweibosdkcore.so -------------------------------------------------------------------------------- /src/android/libs/so/armeabi/libweibosdkcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/android/libs/so/armeabi/libweibosdkcore.so -------------------------------------------------------------------------------- /src/android/libs/so/mips/libweibosdkcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/android/libs/so/mips/libweibosdkcore.so -------------------------------------------------------------------------------- /src/android/libs/so/mips64/libweibosdkcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/android/libs/so/mips64/libweibosdkcore.so -------------------------------------------------------------------------------- /src/android/libs/so/x86/libweibosdkcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/android/libs/so/x86/libweibosdkcore.so -------------------------------------------------------------------------------- /src/android/libs/so/x86_64/libweibosdkcore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/android/libs/so/x86_64/libweibosdkcore.so -------------------------------------------------------------------------------- /src/ios/CDVWeiboSDK.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "WeiboSDK.h" 3 | 4 | @interface CDVWeiboSDK : CDVPlugin 5 | 6 | @property (nonatomic, copy) NSString *callbackId; 7 | @property (nonatomic, copy) NSString *redirectURI; 8 | @property (nonatomic, copy) NSString *weiboAppId; 9 | 10 | - (void)ssoLogin:(CDVInvokedUrlCommand *)command; 11 | 12 | - (void)logout:(CDVInvokedUrlCommand *)command; 13 | 14 | - (void)shareToWeibo:(CDVInvokedUrlCommand *)command; 15 | 16 | - (void)checkClientInstalled:(CDVInvokedUrlCommand *)command; 17 | 18 | - (void)shareImageToWeibo:(CDVInvokedUrlCommand *)command; 19 | 20 | - (void)shareTextToWeibo:(CDVInvokedUrlCommand *)command; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /src/ios/CDVWeiboSDK.m: -------------------------------------------------------------------------------- 1 | #import "CDVWeiboSDK.h" 2 | 3 | NSString *WEBIO_APP_ID = @"weibo_app_id"; 4 | NSString *WEBIO_REDIRECT_URI = @"redirecturi"; 5 | NSString *WEBIO_DEFUALT_REDIRECT_URI = @"https://api.weibo.com/oauth2/default.html"; 6 | NSString *WEIBO_CANCEL_BY_USER = @"cancel by user"; 7 | NSString *WEIBO_SHARE_INSDK_FAIL = @"share in sdk failed"; 8 | NSString *WEIBO_SEND_FAIL = @"send failed"; 9 | NSString *WEIBO_UNSPPORTTED = @"Weibo unspport"; 10 | NSString *WEIBO_AUTH_ERROR = @"Weibo auth error"; 11 | NSString *WEIBO_UNKNOW_ERROR = @"Weibo unknow error"; 12 | NSString *WEIBO_TOKEN_EMPTY = @"Weibo token is empty"; 13 | NSString *WEIBO_USER_CANCEL_INSTALL = @"user cancel install weibo"; 14 | 15 | @implementation CDVWeiboSDK 16 | /** 17 | * 插件初始化主要用于appkey的注册 18 | */ 19 | - (void)pluginInitialize { 20 | NSString *weiboAppId = [[self.commandDelegate settings] objectForKey:WEBIO_APP_ID]; 21 | self.weiboAppId = weiboAppId; 22 | [WeiboSDK registerApp:weiboAppId]; 23 | NSString *redirectURI = [[self.commandDelegate settings] objectForKey:WEBIO_REDIRECT_URI]; 24 | if (nil == redirectURI) { 25 | self.redirectURI = WEBIO_DEFUALT_REDIRECT_URI; 26 | } else { 27 | self.redirectURI = redirectURI; 28 | } 29 | } 30 | /** 31 | * 检查微博官方客户端是否安装 32 | * 33 | * @param command CDVInvokedUrlCommand 34 | */ 35 | - (void)checkClientInstalled:(CDVInvokedUrlCommand *)command { 36 | if ([WeiboSDK isWeiboAppInstalled]) { 37 | CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; 38 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 39 | } else { 40 | CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; 41 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 42 | } 43 | } 44 | 45 | /** 46 | * 微博单点登录 47 | * 48 | * @param command CDVInvokedUrlCommand 49 | */ 50 | - (void)ssoLogin:(CDVInvokedUrlCommand *)command { 51 | self.callbackId = command.callbackId; 52 | WBAuthorizeRequest *request = [WBAuthorizeRequest request]; 53 | request.redirectURI = self.redirectURI; 54 | request.scope = @"all"; 55 | request.userInfo = @{ @"SSO_From" : @"CDVWeiboSDK", 56 | @"Other_Info_1" : [NSNumber numberWithInt:123], 57 | @"Other_Info_2" : @[ @"obj1", @"obj2" ], 58 | @"Other_Info_3" : @{@"key1" : @"obj1", @"key2" : @"obj2"} }; 59 | [WeiboSDK sendRequest:request]; 60 | } 61 | 62 | /** 63 | * 微博登出 64 | * 65 | * @param command CDVInvokedUrlCommand 66 | */ 67 | - (void)logout:(CDVInvokedUrlCommand *)command { 68 | NSUserDefaults *saveDefaults = [NSUserDefaults standardUserDefaults]; 69 | NSString *token = [saveDefaults objectForKey:@"access_token"]; 70 | [saveDefaults removeObjectForKey:@"userId"]; 71 | [saveDefaults removeObjectForKey:@"access_token"]; 72 | [saveDefaults removeObjectForKey:@"expires_time"]; 73 | [saveDefaults synchronize]; 74 | if (token) { 75 | [WeiboSDK logOutWithToken:token delegate:self withTag:nil]; 76 | self.callbackId = command.callbackId; 77 | } else { 78 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_TOKEN_EMPTY]; 79 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 80 | } 81 | } 82 | 83 | /** 84 | * 分享网页到微博 85 | * 86 | * @param command CDVInvokedUrlCommand 87 | */ 88 | - (void)shareToWeibo:(CDVInvokedUrlCommand *)command { 89 | self.callbackId = command.callbackId; 90 | WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request]; 91 | authRequest.redirectURI = self.redirectURI; 92 | authRequest.scope = @"all"; 93 | NSDictionary *params = [command.arguments objectAtIndex:0]; 94 | WBMessageObject *message = [WBMessageObject message]; 95 | WBWebpageObject *webpage = [WBWebpageObject object]; 96 | webpage.objectID = [NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]]; 97 | webpage.title = [self check:@"title" in:params]; 98 | webpage.description = [NSString stringWithFormat:[self check:@"description" in:params], [[NSDate date] timeIntervalSince1970]]; 99 | webpage.webpageUrl = [self check:@"url" in:params]; 100 | NSString *image = [self check:@"image" in:params]; 101 | NSData *imageData = [self processImage:image]; 102 | webpage.thumbnailData = imageData; 103 | message.mediaObject = webpage; 104 | NSUserDefaults *saveDefaults = [NSUserDefaults standardUserDefaults]; 105 | NSString *token = [saveDefaults objectForKey:@"access_token"]; 106 | WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message authInfo:authRequest access_token:token]; 107 | request.userInfo = @{ @"ShareMessageFrom" : @"CDVWeiboSDK", 108 | @"Other_Info_1" : [NSNumber numberWithInt:123], 109 | @"Other_Info_2" : @[ @"obj1", @"obj2" ], 110 | @"Other_Info_3" : @{@"key1" : @"obj1", @"key2" : @"obj2"} }; 111 | [WeiboSDK sendRequest:request]; 112 | } 113 | /** 114 | * 分享图片到微博 115 | * 116 | * @param command CDVInvokedUrlCommand 117 | */ 118 | - (void)shareImageToWeibo:(CDVInvokedUrlCommand *)command { 119 | self.callbackId = command.callbackId; 120 | WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request]; 121 | authRequest.redirectURI = self.redirectURI; 122 | authRequest.scope = @"all"; 123 | NSDictionary *params = [command.arguments objectAtIndex:0]; 124 | WBMessageObject *message = [WBMessageObject message]; 125 | WBImageObject *imageObject = [WBImageObject object]; 126 | NSString *image = [self check:@"image" in:params]; 127 | NSData *imageData = [self processImage:image]; 128 | imageObject.imageData = imageData; 129 | message.imageObject = imageObject; 130 | NSUserDefaults *saveDefaults = [NSUserDefaults standardUserDefaults]; 131 | NSString *token = [saveDefaults objectForKey:@"access_token"]; 132 | WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message authInfo:authRequest access_token:token]; 133 | request.userInfo = @{ @"ShareMessageFrom" : @"CDVWeiboSDK", 134 | @"Other_Info_1" : [NSNumber numberWithInt:123], 135 | @"Other_Info_2" : @[ @"obj1", @"obj2" ], 136 | @"Other_Info_3" : @{@"key1" : @"obj1", @"key2" : @"obj2"} }; 137 | [WeiboSDK sendRequest:request]; 138 | } 139 | /** 140 | * 分享文字到微博 141 | * 142 | * @param command CDVInvokedUrlCommand 143 | */ 144 | - (void)shareTextToWeibo:(CDVInvokedUrlCommand *)command { 145 | self.callbackId = command.callbackId; 146 | WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request]; 147 | authRequest.redirectURI = self.redirectURI; 148 | authRequest.scope = @"all"; 149 | NSDictionary *params = [command.arguments objectAtIndex:0]; 150 | WBMessageObject *message = [WBMessageObject message]; 151 | NSString *text = [self check:@"text" in:params]; 152 | message.text = text; 153 | NSUserDefaults *saveDefaults = [NSUserDefaults standardUserDefaults]; 154 | NSString *token = [saveDefaults objectForKey:@"access_token"]; 155 | WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message authInfo:authRequest access_token:token]; 156 | request.userInfo = @{ @"ShareMessageFrom" : @"CDVWeiboSDK", 157 | @"Other_Info_1" : [NSNumber numberWithInt:123], 158 | @"Other_Info_2" : @[ @"obj1", @"obj2" ], 159 | @"Other_Info_3" : @{@"key1" : @"obj1", @"key2" : @"obj2"} }; 160 | [WeiboSDK sendRequest:request]; 161 | } 162 | 163 | /** 164 | * 处理URL 165 | * 166 | * @param notification cordova传递的消息对象 167 | */ 168 | - (void)handleOpenURL:(NSNotification *)notification { 169 | NSURL *url = [notification object]; 170 | if ([url isKindOfClass:[NSURL class]] && [url.absoluteString hasPrefix:[@"wb" stringByAppendingString:self.weiboAppId]]) { 171 | [WeiboSDK handleOpenURL:url delegate:self]; 172 | } 173 | } 174 | 175 | #pragma mark - WeiboSDKDelegate 176 | - (void)didReceiveWeiboResponse:(WBBaseResponse *)response { 177 | if ([response isKindOfClass:WBSendMessageToWeiboResponse.class]) { 178 | if (response.statusCode == WeiboSDKResponseStatusCodeSuccess) { 179 | WBSendMessageToWeiboResponse *sendMessageToWeiboResponse = (WBSendMessageToWeiboResponse *)response; 180 | NSString *accessToken = [sendMessageToWeiboResponse.authResponse accessToken]; 181 | NSString *userId = [sendMessageToWeiboResponse.authResponse userID]; 182 | NSString *expirationTime = [NSString stringWithFormat:@"%f", [sendMessageToWeiboResponse.authResponse.expirationDate timeIntervalSince1970] * 1000]; 183 | if (accessToken && userId && expirationTime) { 184 | NSUserDefaults *saveDefaults = [NSUserDefaults standardUserDefaults]; 185 | [saveDefaults setValue:accessToken forKey:@"access_token"]; 186 | [saveDefaults setValue:userId forKey:@"userId"]; 187 | [saveDefaults setValue:expirationTime forKey:@"expires_time"]; 188 | [saveDefaults synchronize]; 189 | } 190 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; 191 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 192 | } else if (response.statusCode == WeiboSDKResponseStatusCodeUserCancel) { 193 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_CANCEL_BY_USER]; 194 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 195 | } else if (response.statusCode == WeiboSDKResponseStatusCodeSentFail) { 196 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_SEND_FAIL]; 197 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 198 | } else if (response.statusCode == WeiboSDKResponseStatusCodeShareInSDKFailed) { 199 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_SHARE_INSDK_FAIL]; 200 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 201 | } else if (response.statusCode == WeiboSDKResponseStatusCodeUnsupport) { 202 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_UNSPPORTTED]; 203 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 204 | } else if (response.statusCode == WeiboSDKResponseStatusCodeUnknown) { 205 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_UNKNOW_ERROR]; 206 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 207 | } else if (response.statusCode == WeiboSDKResponseStatusCodeAuthDeny) { 208 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_AUTH_ERROR]; 209 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 210 | } else if (response.statusCode == WeiboSDKResponseStatusCodeUserCancelInstall) { 211 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_USER_CANCEL_INSTALL]; 212 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 213 | } 214 | } else if ([response isKindOfClass:WBAuthorizeResponse.class]) { 215 | if (response.statusCode == WeiboSDKResponseStatusCodeSuccess) { 216 | NSMutableDictionary *Dic = [NSMutableDictionary dictionaryWithCapacity:2]; 217 | [Dic setObject:[(WBAuthorizeResponse *)response userID] forKey:@"userId"]; 218 | [Dic setObject:[(WBAuthorizeResponse *)response accessToken] forKey:@"access_token"]; 219 | [Dic setObject:[NSString stringWithFormat:@"%f", [(WBAuthorizeResponse *)response expirationDate].timeIntervalSince1970 * 1000] forKey:@"expires_time"]; 220 | NSUserDefaults *saveDefaults = [NSUserDefaults standardUserDefaults]; 221 | [saveDefaults setValue:[(WBAuthorizeResponse *)response userID] forKey:@"userId"]; 222 | [saveDefaults setValue:[(WBAuthorizeResponse *)response accessToken] forKey:@"access_token"]; 223 | [saveDefaults setValue:[NSString stringWithFormat:@"%f", [(WBAuthorizeResponse *)response expirationDate].timeIntervalSince1970 * 1000] forKey:@"expires_time"]; 224 | [saveDefaults synchronize]; 225 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:Dic]; 226 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 227 | } else if (response.statusCode == WeiboSDKResponseStatusCodeUserCancel) { 228 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_CANCEL_BY_USER]; 229 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 230 | } else if (response.statusCode == WeiboSDKResponseStatusCodeSentFail) { 231 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_SEND_FAIL]; 232 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 233 | } else if (response.statusCode == WeiboSDKResponseStatusCodeShareInSDKFailed) { 234 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_SHARE_INSDK_FAIL]; 235 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 236 | } else if (response.statusCode == WeiboSDKResponseStatusCodeUnsupport) { 237 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_UNSPPORTTED]; 238 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 239 | } else if (response.statusCode == WeiboSDKResponseStatusCodeUnknown) { 240 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_UNKNOW_ERROR]; 241 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 242 | } else if (response.statusCode == WeiboSDKResponseStatusCodeAuthDeny) { 243 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_AUTH_ERROR]; 244 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 245 | } else if (response.statusCode == WeiboSDKResponseStatusCodeUserCancelInstall) { 246 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:WEIBO_USER_CANCEL_INSTALL]; 247 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 248 | } 249 | } 250 | } 251 | 252 | - (void)didReceiveWeiboRequest:(WBBaseRequest *)request { 253 | } 254 | 255 | #pragma mark - WBHttpRequestDelegate 256 | 257 | - (void)request:(WBHttpRequest *)request didFinishLoadingWithResult:(NSString *)result { 258 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; 259 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 260 | } 261 | 262 | - (void)request:(WBHttpRequest *)request didFailWithError:(NSError *)error { 263 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; 264 | [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; 265 | } 266 | /** 267 | 图片处理 268 | 269 | @param image 图片数据 270 | @return 图片NSdata数据 271 | */ 272 | - (NSData *)processImage:(NSString *)image { 273 | if ([self isBase64Data:image]) { 274 | return [[NSData alloc] initWithBase64EncodedString:image options:0]; 275 | } else if ([image hasPrefix:@"http://"] || [image hasPrefix:@"https://"]) { 276 | NSURL *url = [NSURL URLWithString:image]; 277 | return [NSData dataWithContentsOfURL:url]; 278 | } else { 279 | return [NSData dataWithContentsOfFile:image]; 280 | } 281 | } 282 | 283 | /** 284 | 检查图片是不是Base64 285 | 286 | @param data 图片数据 287 | @return 结果true or false 288 | */ 289 | - (BOOL)isBase64Data:(NSString *)data { 290 | data = [[data componentsSeparatedByCharactersInSet: 291 | [NSCharacterSet whitespaceAndNewlineCharacterSet]] 292 | componentsJoinedByString:@""]; 293 | if ([data length] % 4 == 0) { 294 | static NSCharacterSet *invertedBase64CharacterSet = nil; 295 | if (invertedBase64CharacterSet == nil) { 296 | invertedBase64CharacterSet = [[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="] invertedSet]; 297 | } 298 | return [data rangeOfCharacterFromSet:invertedBase64CharacterSet options:NSLiteralSearch].location == NSNotFound; 299 | } 300 | return NO; 301 | } 302 | 303 | /** 304 | 检查参数是否存在 305 | 306 | @param param 要检查的参数 307 | @param args 参数字典 308 | @return 参数 309 | */ 310 | - (NSString *)check:(NSString *)param in:(NSDictionary *)args { 311 | NSString *data = [args objectForKey:param]; 312 | return data?data:@""; 313 | } 314 | @end 315 | -------------------------------------------------------------------------------- /src/ios/libWeiboSDK/WBHttpRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // WBHttpRequest.h 3 | // WeiboSDK 4 | // 5 | // Created by DannionQiu on 14-9-18. 6 | // Copyright (c) 2014年 SINA iOS Team. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | #pragma mark - WBHttpRequest and WBHttpRequestDelegate 13 | @class WBHttpRequest; 14 | 15 | /** 16 | 接收并处理来自微博sdk对于网络请求接口的调用响应 以及logOutWithToken的请求 17 | */ 18 | @protocol WBHttpRequestDelegate 19 | 20 | /** 21 | 收到一个来自微博Http请求的响应 22 | 23 | @param response 具体的响应对象 24 | */ 25 | @optional 26 | - (void)request:(WBHttpRequest *)request didReceiveResponse:(NSURLResponse *)response; 27 | 28 | /** 29 | 收到一个来自微博Http请求失败的响应 30 | 31 | @param error 错误信息 32 | */ 33 | @optional 34 | - (void)request:(WBHttpRequest *)request didFailWithError:(NSError *)error; 35 | 36 | /** 37 | 收到一个来自微博Http请求的网络返回 38 | 39 | @param result 请求返回结果 40 | */ 41 | @optional 42 | - (void)request:(WBHttpRequest *)request didFinishLoadingWithResult:(NSString *)result; 43 | 44 | /** 45 | 收到一个来自微博Http请求的网络返回 46 | 47 | @param data 请求返回结果 48 | */ 49 | @optional 50 | - (void)request:(WBHttpRequest *)request didFinishLoadingWithDataResult:(NSData *)data; 51 | 52 | /** 53 | 收到快速SSO授权的重定向 54 | 55 | @param URI 56 | */ 57 | @optional 58 | - (void)request:(WBHttpRequest *)request didReciveRedirectResponseWithURI:(NSURL *)redirectUrl; 59 | 60 | @end 61 | 62 | 63 | /** 64 | 微博封装Http请求的消息结构 65 | 66 | */ 67 | @interface WBHttpRequest : NSObject 68 | { 69 | NSURLConnection *connection; 70 | NSMutableData *responseData; 71 | } 72 | 73 | /** 74 | 用户自定义请求地址URL 75 | */ 76 | @property (nonatomic, strong) NSString *url; 77 | 78 | /** 79 | 用户自定义请求方式 80 | 81 | 支持"GET" "POST" 82 | */ 83 | @property (nonatomic, strong) NSString *httpMethod; 84 | 85 | /** 86 | 用户自定义请求参数字典 87 | */ 88 | @property (nonatomic, strong) NSDictionary *params; 89 | 90 | /** 91 | WBHttpRequestDelegate对象,用于接收微博SDK对于发起的接口请求的请求的响应 92 | */ 93 | @property (nonatomic, weak) id delegate; 94 | 95 | /** 96 | 用户自定义TAG 97 | 98 | 用于区分回调Request 99 | */ 100 | @property (nonatomic, strong) NSString* tag; 101 | 102 | /** 103 | 统一HTTP请求接口 104 | 调用此接口后,将发送一个HTTP网络请求 105 | @param url 请求url地址 106 | @param httpMethod 支持"GET" "POST" 107 | @param params 向接口传递的参数结构 108 | @param delegate WBHttpRequestDelegate对象,用于接收微博SDK对于发起的接口请求的请求的响应 109 | @param tag 用户自定义TAG,将通过回调WBHttpRequest实例的tag属性返回 110 | */ 111 | + (WBHttpRequest *)requestWithURL:(NSString *)url 112 | httpMethod:(NSString *)httpMethod 113 | params:(NSDictionary *)params 114 | delegate:(id)delegate 115 | withTag:(NSString *)tag; 116 | 117 | /** 118 | 统一微博Open API HTTP请求接口 119 | 调用此接口后,将发送一个HTTP网络请求(用于访问微博open api) 120 | @param accessToken 应用获取到的accessToken,用于身份验证 121 | @param url 请求url地址 122 | @param httpMethod 支持"GET" "POST" 123 | @param params 向接口传递的参数结构 124 | @param delegate WBHttpRequestDelegate对象,用于接收微博SDK对于发起的接口请求的请求的响应 125 | @param tag 用户自定义TAG,将通过回调WBHttpRequest实例的tag属性返回 126 | */ 127 | 128 | + (WBHttpRequest *)requestWithAccessToken:(NSString *)accessToken 129 | url:(NSString *)url 130 | httpMethod:(NSString *)httpMethod 131 | params:(NSDictionary *)params 132 | delegate:(id)delegate 133 | withTag:(NSString *)tag; 134 | 135 | 136 | 137 | /** 138 | 取消网络请求接口 139 | 调用此接口后,将取消当前网络请求,建议同时[WBHttpRequest setDelegate:nil]; 140 | 注意:该方法只对使用delegate的request方法有效。无法取消任何使用block的request的网络请求接口。 141 | */ 142 | - (void)disconnect; 143 | 144 | #pragma mark - block extension 145 | 146 | typedef void (^WBRequestHandler)(WBHttpRequest *httpRequest, 147 | id result, 148 | NSError *error); 149 | 150 | /** 151 | 统一微博Open API HTTP请求接口 152 | 调用此接口后,将发送一个HTTP网络请求(用于访问微博open api) 153 | @param url 请求url地址 154 | @param httpMethod 支持"GET" "POST" 155 | @param params 向接口传递的参数结构 156 | @param queue 发起请求的NSOperationQueue对象,如queue为nil,则在主线程([NSOperationQueue mainQueue])发起请求。 157 | @param handler 接口请求返回调用的block方法 158 | */ 159 | + (WBHttpRequest *)requestWithURL:(NSString *)url 160 | httpMethod:(NSString *)httpMethod 161 | params:(NSDictionary *)params 162 | queue:(NSOperationQueue*)queue 163 | withCompletionHandler:(WBRequestHandler)handler; 164 | 165 | 166 | /** 167 | 统一HTTP请求接口 168 | 调用此接口后,将发送一个HTTP网络请求 169 | @param url 请求url地址 170 | @param httpMethod 支持"GET" "POST" 171 | @param params 向接口传递的参数结构 172 | @param queue 发起请求的NSOperationQueue对象,如queue为nil,则在主线程([NSOperationQueue mainQueue])发起请求。 173 | @param handler 接口请求返回调用的block方法 174 | */ 175 | 176 | + (WBHttpRequest *)requestWithAccessToken:(NSString *)accessToken 177 | url:(NSString *)url 178 | httpMethod:(NSString *)httpMethod 179 | params:(NSDictionary *)params 180 | queue:(NSOperationQueue*)queue 181 | withCompletionHandler:(WBRequestHandler)handler; 182 | 183 | 184 | @end 185 | -------------------------------------------------------------------------------- /src/ios/libWeiboSDK/WeiboSDK.bundle/images/common_button_white@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/ios/libWeiboSDK/WeiboSDK.bundle/images/common_button_white@2x.png -------------------------------------------------------------------------------- /src/ios/libWeiboSDK/WeiboSDK.bundle/images/common_button_white_highlighted@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/ios/libWeiboSDK/WeiboSDK.bundle/images/common_button_white_highlighted@2x.png -------------------------------------------------------------------------------- /src/ios/libWeiboSDK/WeiboSDK.bundle/images/empty_failed@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/ios/libWeiboSDK/WeiboSDK.bundle/images/empty_failed@2x.png -------------------------------------------------------------------------------- /src/ios/libWeiboSDK/WeiboSDK.bundle/others/mfp.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/ios/libWeiboSDK/WeiboSDK.bundle/others/mfp.cer -------------------------------------------------------------------------------- /src/ios/libWeiboSDK/WeiboSDK.h: -------------------------------------------------------------------------------- 1 | // 2 | // WeiboSDKHeaders.h 3 | // WeiboSDKDemo 4 | // 5 | // Created by Wade Cheng on 4/3/13. 6 | // Copyright (c) 2013 SINA iOS Team. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | #import "WBHttpRequest.h" 13 | 14 | 15 | typedef NS_ENUM(NSInteger, WeiboSDKResponseStatusCode) 16 | { 17 | WeiboSDKResponseStatusCodeSuccess = 0,//成功 18 | WeiboSDKResponseStatusCodeUserCancel = -1,//用户取消发送 19 | WeiboSDKResponseStatusCodeSentFail = -2,//发送失败 20 | WeiboSDKResponseStatusCodeAuthDeny = -3,//授权失败 21 | WeiboSDKResponseStatusCodeUserCancelInstall = -4,//用户取消安装微博客户端 22 | WeiboSDKResponseStatusCodePayFail = -5,//支付失败 23 | WeiboSDKResponseStatusCodeShareInSDKFailed = -8,//分享失败 详情见response UserInfo 24 | WeiboSDKResponseStatusCodeUnsupport = -99,//不支持的请求 25 | WeiboSDKResponseStatusCodeUnknown = -100, 26 | }; 27 | 28 | 29 | @protocol WeiboSDKDelegate; 30 | @protocol WBHttpRequestDelegate; 31 | @class WBBaseRequest; 32 | @class WBBaseResponse; 33 | @class WBMessageObject; 34 | @class WBImageObject; 35 | @class WBBaseMediaObject; 36 | @class WBHttpRequest; 37 | @class PHAsset; 38 | @class WBNewVideoObject; 39 | 40 | /** 41 | 微博SDK接口类 42 | */ 43 | @interface WeiboSDK : NSObject 44 | 45 | /** 46 | 检查用户是否安装了微博客户端程序 47 | @return 已安装返回YES,未安装返回NO 48 | */ 49 | + (BOOL)isWeiboAppInstalled; 50 | 51 | /** 52 | 检查用户是否可以通过微博客户端进行分享 53 | @return 可以使用返回YES,不可以使用返回NO 54 | */ 55 | + (BOOL)isCanShareInWeiboAPP; 56 | 57 | /** 58 | 检查用户是否可以使用微博客户端进行SSO授权 59 | @return 可以使用返回YES,不可以使用返回NO 60 | */ 61 | + (BOOL)isCanSSOInWeiboApp; 62 | 63 | /** 64 | 打开微博客户端程序 65 | @return 成功打开返回YES,失败返回NO 66 | */ 67 | + (BOOL)openWeiboApp; 68 | 69 | 70 | 71 | /** 72 | 获取微博客户端程序的itunes安装地址 73 | @return 微博客户端程序的itunes安装地址 74 | */ 75 | + (NSString *)getWeiboAppInstallUrl; 76 | 77 | /** 78 | 获取当前微博SDK的版本号 79 | @return 当前微博SDK的版本号 80 | */ 81 | + (NSString *)getSDKVersion; 82 | 83 | 84 | extern NSString * const WeiboSDKGetAidSucessNotification; 85 | extern NSString * const WeiboSDKGetAidFailNotification; 86 | /** 87 | 获取当前微博SDK的aid 88 | 返回的aid值可能为 nil ,当值为 nil 时会尝试获取 aid 值。 89 | 当获取成功( aid 值变为有效值)时,SDK会发出名为 WeiboSDKGetAidSucessNotification 的通知,通知中带有 aid 值。 90 | 当获取失败时,SDK会发出名为 WeiboSDKGetAidFailNotification 的通知,通知中带有 NSError 对象。 91 | @return aid 用于广告的与设备信息相关的标识符 92 | */ 93 | + (NSString *)getWeiboAid; 94 | 95 | 96 | /** 97 | 向微博客户端程序注册第三方应用 98 | @param appKey 微博开放平台第三方应用appKey 99 | @return 注册成功返回YES,失败返回NO 100 | */ 101 | + (BOOL)registerApp:(NSString *)appKey; 102 | 103 | /** 104 | 处理微博客户端程序通过URL启动第三方应用时传递的数据 105 | 106 | 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用 107 | @param url 启动第三方应用的URL 108 | @param delegate WeiboSDKDelegate对象,用于接收微博触发的消息 109 | @see WeiboSDKDelegate 110 | */ 111 | + (BOOL)handleOpenURL:(NSURL *)url delegate:(id)delegate; 112 | 113 | /** 114 | 发送请求给微博客户端程序,并切换到微博 115 | 116 | 请求发送给微博客户端程序之后,微博客户端程序会进行相关的处理,处理完成之后一定会调用 [WeiboSDKDelegate didReceiveWeiboResponse:] 方法将处理结果返回给第三方应用 117 | 118 | @param request 具体的发送请求 119 | 120 | @see [WeiboSDKDelegate didReceiveWeiboResponse:] 121 | @see WBBaseResponse 122 | */ 123 | + (BOOL)sendRequest:(WBBaseRequest *)request; 124 | 125 | /** 126 | 收到微博客户端程序的请求后,发送对应的应答给微博客户端端程序,并切换到微博 127 | 128 | 第三方应用收到微博的请求后,异步处理该请求,完成后必须调用该函数将应答返回给微博 129 | 130 | @param response 具体的应答内容 131 | @see WBBaseRequest 132 | */ 133 | + (BOOL)sendResponse:(WBBaseResponse *)response; 134 | 135 | /** 136 | 设置WeiboSDK的调试模式 137 | 138 | 当开启调试模式时,WeiboSDK会在控制台输出详细的日志信息,开发者可以据此调试自己的程序。默认为 NO 139 | @param enabled 开启或关闭WeiboSDK的调试模式 140 | */ 141 | + (void)enableDebugMode:(BOOL)enabled; 142 | 143 | /** 144 | 取消授权,登出接口 145 | 调用此接口后,token将失效 146 | @param token 第三方应用之前申请的Token 147 | @param delegate WBHttpRequestDelegate对象,用于接收微博SDK对于发起的接口请求的请求的响应 148 | @param tag 用户自定义TAG,将通过回调WBHttpRequest实例的tag属性返回 149 | 150 | */ 151 | + (void)logOutWithToken:(NSString *)token delegate:(id)delegate withTag:(NSString*)tag; 152 | 153 | /** 154 | 呼起微博客户端或打开微博H5页面,SDK自动检测是否安装微博客户端,当调用SDK相关方法时: 155 | 156 | 有的话呼起微博客户端定位到对应界面; 157 | 没有的话打开 webView 加载相应的微博H5页面; 158 | @param uid 用户id 159 | @param mid 微博id 160 | @param aid 文章id 161 | */ 162 | 163 | //连接到指定用户的微博个人主页,连接后可进行加关注等互动 164 | + (void)linkToUser:(NSString *)uid; 165 | 166 | //连接到指定的单条微博详情页,连接后可对这条微博进行转、评、赞等互动 167 | + (void)linkToSingleBlog:(NSString *)uid blogID:(NSString *)mid; 168 | 169 | //连接到指定的微博头条文章页 170 | + (void)linkToArticle:(NSString *)aid; 171 | 172 | //分享到微博 173 | + (void)shareToWeibo:(NSString *)content; 174 | 175 | //评论指定的微博 176 | + (void)commentToWeibo:(NSString *)mid; 177 | 178 | //连接到微博搜索内容流 179 | + (void)linkToSearch:(NSString *)keyword; 180 | 181 | //连接到我的微博消息流 182 | + (void)linkToTimeLine; 183 | 184 | //连接到我的微博个人主页 185 | + (void)linkToProfile; 186 | 187 | @end 188 | 189 | /** 190 | 接收并处理来至微博客户端程序的事件消息 191 | */ 192 | @protocol WeiboSDKDelegate 193 | 194 | /** 195 | 收到一个来自微博客户端程序的请求 196 | 197 | 收到微博的请求后,第三方应用应该按照请求类型进行处理,处理完后必须通过 [WeiboSDK sendResponse:] 将结果回传给微博 198 | @param request 具体的请求对象 199 | */ 200 | - (void)didReceiveWeiboRequest:(WBBaseRequest *)request; 201 | 202 | /** 203 | 收到一个来自微博客户端程序的响应 204 | 205 | 收到微博的响应后,第三方应用可以通过响应类型、响应的数据和 WBBaseResponse.userInfo 中的数据完成自己的功能 206 | @param response 具体的响应对象 207 | */ 208 | - (void)didReceiveWeiboResponse:(WBBaseResponse *)response; 209 | 210 | @end 211 | 212 | 213 | #pragma mark - DataTransferObject and Base Request/Response 214 | 215 | /** 216 | 微博客户端程序和第三方应用之间传输数据信息的基类 217 | */ 218 | @interface WBDataTransferObject : NSObject 219 | 220 | /** 221 | 自定义信息字典,用于数据传输过程中存储相关的上下文环境数据 222 | 223 | 第三方应用给微博客户端程序发送 request 时,可以在 userInfo 中存储请求相关的信息。 224 | 225 | @warning userInfo中的数据必须是实现了 `NSCoding` 协议的对象,必须保证能序列化和反序列化 226 | @warning 序列化后的数据不能大于10M 227 | */ 228 | @property (nonatomic, strong) NSDictionary *userInfo; 229 | 230 | 231 | /** 232 | 发送该数据对象的SDK版本号 233 | 234 | 如果数据对象是自己生成的,则sdkVersion为当前SDK的版本号;如果是接收到的数据对象,则sdkVersion为数据发送方SDK版本号 235 | */ 236 | @property (strong, nonatomic, readonly) NSString *sdkVersion; 237 | 238 | 239 | /** 240 | 当用户没有安装微博客户端程序时是否提示用户打开微博安装页面 241 | 242 | 如果设置为YES,当用户未安装微博时会弹出Alert询问用户是否要打开微博App的安装页面。默认为YES 243 | */ 244 | @property (nonatomic, assign) BOOL shouldOpenWeiboAppInstallPageIfNotInstalled; 245 | 246 | 247 | @end 248 | 249 | 250 | /** 251 | 微博SDK所有请求类的基类 252 | */ 253 | @interface WBBaseRequest : WBDataTransferObject 254 | 255 | /** 256 | 返回一个 WBBaseRequest 对象 257 | 258 | @return 返回一个*自动释放的*WBBaseRequest对象 259 | */ 260 | + (id)request; 261 | 262 | @end 263 | 264 | 265 | /** 266 | 微博SDK所有响应类的基类 267 | */ 268 | @interface WBBaseResponse : WBDataTransferObject 269 | 270 | /** 271 | 对应的 request 中的自定义信息字典 272 | 273 | 如果当前 response 是由微博客户端响应给第三方应用的,则 requestUserInfo 中会包含原 request.userInfo 中的所有数据 274 | 275 | @see WBBaseRequest.userInfo 276 | */ 277 | @property (strong, nonatomic, readonly) NSDictionary *requestUserInfo; 278 | 279 | /** 280 | 响应状态码 281 | 282 | 第三方应用可以通过statusCode判断请求的处理结果 283 | */ 284 | @property (nonatomic, assign) WeiboSDKResponseStatusCode statusCode; 285 | 286 | /** 287 | 返回一个 WBBaseResponse 对象 288 | 289 | @return 返回一个*自动释放的*WBBaseResponse对象 290 | */ 291 | + (id)response; 292 | 293 | @end 294 | 295 | #pragma mark - Authorize Request/Response 296 | 297 | /** 298 | 第三方应用向微博客户端请求认证的消息结构 299 | 300 | 第三方应用向微博客户端申请认证时,需要调用 [WeiboSDK sendRequest:] 函数, 向微博客户端发送一个 WBAuthorizeRequest 的消息结构。 301 | 微博客户端处理完后会向第三方应用发送一个结构为 WBAuthorizeResponse 的处理结果。 302 | */ 303 | @interface WBAuthorizeRequest : WBBaseRequest 304 | 305 | /** 306 | 微博开放平台第三方应用授权回调页地址,默认为`http://` 307 | 308 | 参考 http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E#.E5.AE.A2.E6.88.B7.E7.AB.AF.E9.BB.98.E8.AE.A4.E5.9B.9E.E8.B0.83.E9.A1.B5 309 | 310 | @warning 必须保证和在微博开放平台应用管理界面配置的“授权回调页”地址一致,如未进行配置则默认为`http://` 311 | @warning 不能为空,长度小于1K 312 | */ 313 | @property (nonatomic, strong) NSString *redirectURI; 314 | 315 | /** 316 | 微博开放平台第三方应用scope,多个scrope用逗号分隔 317 | 318 | 参考 http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E#scope 319 | 320 | @warning 长度小于1K 321 | */ 322 | @property (nonatomic, strong) NSString *scope; 323 | 324 | /** 325 | 当用户没有安装微博客户端或微博客户端过低无法支持SSO的时候是否弹出SDK自带的Webview进行授权 326 | 327 | 如果设置为YES,当用户没有安装微博客户端或微博客户端过低无法支持SSO的时候会自动弹出SDK自带的Webview进行授权。 328 | 329 | 如果设置为NO,会根据 shouldOpenWeiboAppInstallPageIfNotInstalled 属性判断是否弹出安装/更新微博的对话框 330 | 331 | 默认为YES 332 | */ 333 | @property (nonatomic, assign) BOOL shouldShowWebViewForAuthIfCannotSSO; 334 | 335 | 336 | @end 337 | 338 | 339 | /** 340 | 微博客户端处理完第三方应用的认证申请后向第三方应用回送的处理结果 341 | 342 | WBAuthorizeResponse 结构中仅包含常用的 userID 、accessToken 和 expirationDate 信息,其他的认证信息(比如部分应用可以获取的 refresh_token 信息)会统一存放到 userInfo 中 343 | */ 344 | @interface WBAuthorizeResponse : WBBaseResponse 345 | 346 | /** 347 | 用户ID 348 | */ 349 | @property (nonatomic, strong) NSString *userID; 350 | 351 | /** 352 | 认证口令 353 | */ 354 | @property (nonatomic, strong) NSString *accessToken; 355 | 356 | /** 357 | 认证过期时间 358 | */ 359 | @property (nonatomic, strong) NSDate *expirationDate; 360 | 361 | /** 362 | 当认证口令过期时用于换取认证口令的更新口令 363 | */ 364 | @property (nonatomic, strong) NSString *refreshToken; 365 | 366 | @end 367 | 368 | #pragma mark - ProvideMessageForWeibo Request/Response 369 | 370 | /** 371 | 微博客户端向第三方程序请求提供内容的消息结构 372 | */ 373 | @interface WBProvideMessageForWeiboRequest : WBBaseRequest 374 | 375 | @end 376 | 377 | /** 378 | 微博客户端向第三方应用请求提供内容,第三方应用向微博客户端返回的消息结构 379 | */ 380 | @interface WBProvideMessageForWeiboResponse : WBBaseResponse 381 | 382 | /** 383 | 提供给微博客户端的消息 384 | */ 385 | @property (nonatomic, strong) WBMessageObject *message; 386 | 387 | /** 388 | 返回一个 WBProvideMessageForWeiboResponse 对象 389 | @param message 需要回送给微博客户端程序的消息对象 390 | @return 返回一个*自动释放的*WBProvideMessageForWeiboResponse对象 391 | */ 392 | + (id)responseWithMessage:(WBMessageObject *)message; 393 | 394 | @end 395 | 396 | #pragma mark - SendMessageToWeibo Request/Response 397 | 398 | /** 399 | 第三方应用发送消息至微博客户端程序的消息结构体 400 | */ 401 | @interface WBSendMessageToWeiboRequest : WBBaseRequest 402 | 403 | /** 404 | 发送给微博客户端的消息 405 | */ 406 | @property (nonatomic, strong) WBMessageObject *message; 407 | 408 | /** 409 | 返回一个 WBSendMessageToWeiboRequest 对象 410 | 此方法生成对象被[WeiboSDK sendRequest:]会唤起微博客户端的发布器进行分享,如果未安装微博客户端或客户端版本太低 411 | 会根据 shouldOpenWeiboAppInstallPageIfNotInstalled 属性判断是否弹出安装/更新微博的对话框 412 | @param message 需要发送给微博客户端的消息对象 413 | @return 返回一个*自动释放的*WBSendMessageToWeiboRequest对象 414 | */ 415 | + (id)requestWithMessage:(WBMessageObject *)message; 416 | 417 | /** 418 | 返回一个 WBSendMessageToWeiboRequest 对象 419 | 420 | 当用户安装了可以支持微博客户端內分享的微博客户端时,会自动唤起微博并分享 421 | 当用户没有安装微博客户端或微博客户端过低无法支持通过客户端內分享的时候会自动唤起SDK內微博发布器 422 | 423 | @param message 需要发送给微博的消息对象 424 | @param authRequest 授权相关信息,与access_token二者至少有一个不为空,当access_token为空并且需要弹出SDK內发布器时会通过此信息先进行授权后再分享 425 | @param access_token 第三方应用之前申请的Token,当此值不为空并且无法通过客户端分享的时候,会使用此token进行分享。 426 | @return 返回一个*自动释放的*WBSendMessageToWeiboRequest对象 427 | */ 428 | + (id)requestWithMessage:(WBMessageObject *)message 429 | authInfo:(WBAuthorizeRequest *)authRequest 430 | access_token:(NSString *)access_token; 431 | 432 | @end 433 | 434 | /** 435 | WBSendMessageToWeiboResponse 436 | */ 437 | @interface WBSendMessageToWeiboResponse : WBBaseResponse 438 | 439 | /** 440 | 可能在分享过程中用户进行了授权操作,当此值不为空时,为用户相应授权信息 441 | */ 442 | @property (nonatomic,strong) WBAuthorizeResponse *authResponse; 443 | @end 444 | 445 | 446 | 447 | #pragma mark - MessageObject / ImageObject 448 | 449 | /** 450 | 微博客户端程序和第三方应用之间传递的消息结构 451 | 452 | 一个消息结构由三部分组成:文字、图片和多媒体数据。三部分内容中至少有一项不为空,图片和多媒体数据不能共存。(新版的多图和视频属于图片数据,并且图片和视频也不能共存) 453 | */ 454 | @interface WBMessageObject : NSObject 455 | 456 | /** 457 | 消息的文本内容 458 | 459 | @warning 长度小于2000个汉字 460 | */ 461 | @property (nonatomic, strong) NSString *text; 462 | 463 | /** 464 | 消息的图片内容 465 | 466 | @see WBImageObject 467 | */ 468 | @property (nonatomic, strong) WBImageObject *imageObject; 469 | 470 | /** 471 | 消息的多媒体内容 472 | 473 | @see WBBaseMediaObject 474 | */ 475 | @property (nonatomic, strong) WBBaseMediaObject *mediaObject; 476 | 477 | /** 478 | 消息的视频内容 479 | 480 | @see WBVideoObject 481 | */ 482 | @property (nonatomic, strong) WBNewVideoObject *videoObject; 483 | /** 484 | 返回一个 WBMessageObject 对象 485 | 486 | @return 返回一个*自动释放的*WBMessageObject对象 487 | */ 488 | + (id)message; 489 | 490 | @end 491 | 492 | /** 493 | 图片视频分享时错误枚举 494 | */ 495 | 496 | typedef NS_ENUM(NSInteger, WBSDKMediaTransferErrorCode) 497 | { 498 | WBSDKMediaTransferAlbumPermissionError = 0,//相册权限 499 | WBSDKMediaTransferAlbumWriteError = 0,//相册写入错误 500 | WBSDKMediaTransferAlbumAssetTypeError = 0,//资源类型错误 501 | }; 502 | 503 | /** 504 | 图片视频分享协议 505 | */ 506 | @protocol WBMediaTransferProtocol 507 | 508 | /** 509 | 数据准备成功回调 510 | */ 511 | -(void)wbsdk_TransferDidReceiveObject:(id)object; 512 | 513 | /** 514 | 数据准备失败回调 515 | */ 516 | -(void)wbsdk_TransferDidFailWithErrorCode:(WBSDKMediaTransferErrorCode)errorCode andError:(NSError*)error; 517 | 518 | @end 519 | 520 | /** 521 | 消息中包含的图片数据对象 522 | */ 523 | @interface WBImageObject : NSObject 524 | 525 | /** 526 | 图片真实数据内容 527 | 528 | @warning 大小不能超过10M 529 | */ 530 | @property (nonatomic, strong) NSData *imageData; 531 | 532 | /** 533 | 是否分享到story 534 | */ 535 | @property (nonatomic) BOOL isShareToStory; 536 | 537 | /** 538 | 返回一个 WBImageObject 对象 539 | 540 | @return 返回一个*自动释放的*WBImageObject对象 541 | */ 542 | + (id)object; 543 | 544 | /** 545 | 返回一个 UIImage 对象 546 | 547 | @return 返回一个*自动释放的*UIImage对象 548 | */ 549 | - (UIImage *)image; 550 | 551 | 552 | /** 553 | 多图分享委托 554 | */ 555 | @property(nonatomic,weak)id delegate; 556 | 557 | /** 558 | 图片对象添加图片数组 559 | */ 560 | - (void)addImages:(NSArray*)imageArray; 561 | 562 | /** 563 | 图片对象添加照片数组 564 | */ 565 | - (void)addImageAssets:(NSArray*)assetArray; 566 | 567 | /** 568 | 多图最终传递对象 569 | */ 570 | -(NSArray*)finalAssetArray; 571 | 572 | @end 573 | 574 | @interface WBNewVideoObject : NSObject 575 | 576 | /** 577 | 返回一个 WBNewVideoObject 对象 578 | 579 | @return 返回一个*自动释放的*WBNewVideoObject对象 580 | */ 581 | + (id)object; 582 | 583 | /** 584 | 是否分享到story 585 | */ 586 | @property (nonatomic) BOOL isShareToStory; 587 | 588 | /** 589 | 多图分享委托 590 | */ 591 | @property(nonatomic,weak)id delegate; 592 | 593 | /** 594 | 视频对象添加视频 595 | */ 596 | -(void)addVideo:(NSURL*)videoUrl; 597 | 598 | /** 599 | 视频对象添加视频资源 600 | */ 601 | -(void)addVideoAsset:(PHAsset*)videoAsset; 602 | 603 | /** 604 | 视频最终传递对象 605 | */ 606 | -(NSString*)finalAsset; 607 | 608 | @end 609 | 610 | 611 | #pragma mark - Message Media Objects 612 | 613 | /** 614 | 消息中包含的多媒体数据对象基类,该类后期会被废弃,在发布器不再显示为linkcard样式,只显示为普通网络连接 615 | */ 616 | @interface WBBaseMediaObject : NSObject 617 | 618 | /** 619 | 对象唯一ID,用于唯一标识一个多媒体内容 620 | 621 | 当第三方应用分享多媒体内容到微博时,应该将此参数设置为被分享的内容在自己的系统中的唯一标识 622 | @warning 不能为空,长度小于255 623 | */ 624 | @property (nonatomic, strong) NSString *objectID; 625 | 626 | /** 627 | 多媒体内容标题 628 | @warning 不能为空且长度小于1k 629 | */ 630 | @property (nonatomic, strong) NSString *title; 631 | 632 | /** 633 | 多媒体内容描述 634 | @warning 长度小于1k 635 | */ 636 | @property (nonatomic, strong) NSString *description; 637 | 638 | /** 639 | 多媒体内容缩略图 640 | @warning 大小小于32k 641 | */ 642 | @property (nonatomic, strong) NSData *thumbnailData; 643 | 644 | /** 645 | 点击多媒体内容之后呼起第三方应用特定页面的scheme 646 | @warning 长度小于255 647 | */ 648 | @property (nonatomic, strong) NSString *scheme; 649 | 650 | /** 651 | 返回一个 WBBaseMediaObject 对象 652 | 653 | @return 返回一个*自动释放的*WBBaseMediaObject对象 654 | */ 655 | + (id)object; 656 | 657 | @end 658 | 659 | #pragma mark - Message WebPage Objects 660 | 661 | /** 662 | 消息中包含的网页数据对象 663 | */ 664 | @interface WBWebpageObject : WBBaseMediaObject 665 | 666 | /** 667 | 网页的url地址 668 | 669 | @warning 不能为空且长度不能超过255 670 | */ 671 | @property (nonatomic, strong) NSString *webpageUrl; 672 | 673 | @end 674 | 675 | 676 | -------------------------------------------------------------------------------- /src/ios/libWeiboSDK/libWeiboSDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iVanPan/cordova_weibo/0bc835dc8ffe2256b0e3f17881a732d8d1c83d64/src/ios/libWeiboSDK/libWeiboSDK.a -------------------------------------------------------------------------------- /www/weibo.js: -------------------------------------------------------------------------------- 1 | var cordova = require('cordova'); 2 | module.exports = { 3 | checkClientInstalled:function(successCallback, errorCallback){ 4 | cordova.exec(successCallback, errorCallback, "WeiboSDK", "checkClientInstalled", []); 5 | }, 6 | ssoLogin:function(successCallback, errorCallback){ 7 | cordova.exec(successCallback, errorCallback, "WeiboSDK", "ssoLogin", []); 8 | }, 9 | logout:function(successCallback, errorCallback){ 10 | cordova.exec(successCallback, errorCallback, "WeiboSDK", "logout", []); 11 | }, 12 | shareToWeibo:function(successCallback, errorCallback, args){ 13 | if(args == undefined){ 14 | args = {}; 15 | } 16 | cordova.exec(successCallback, errorCallback, "WeiboSDK", "shareToWeibo", [args]); 17 | }, 18 | shareImageToWeibo:function(successCallback, errorCallback, args){ 19 | if(args == undefined){ 20 | args = {}; 21 | } 22 | cordova.exec(successCallback, errorCallback, "WeiboSDK", "shareImageToWeibo", [args]); 23 | }, 24 | shareTextToWeibo:function(successCallback, errorCallback, args){ 25 | if(args == undefined){ 26 | args = {}; 27 | } 28 | cordova.exec(successCallback, errorCallback, "WeiboSDK", "shareTextToWeibo", [args]); 29 | } 30 | }; 31 | --------------------------------------------------------------------------------