共计 23854 个字符,预计需要花费 60 分钟才能阅读完成。
前言
ShareSDKPlus 封装了 ShareSDK, 是对 APICloud 平台的反对,为 APICloud 开发的 App 提供社交分享性能的一个组件,反对包含 QQ、微信、新浪微博等多家支流社交平台,帮忙开发者轻松实现社会化分享、第三方登录、关注、取得用户材料、获取好友列表等支流的性能。以后 ShareSDK 版本,iOS:v4.2.5、Android:v3.5.2
集成筹备
注册 Mob 利用
开发者应用本模块之前须要先到 Mob 官网申请开发者账号,并在账号内填写相应信息创立本人的 APP,从而获取 AppKey 和 AppSecret。详情参考: 获取 AppKey 和 AppSecret
创立 APICloud 利用
APICloud 提供了两种创立利用的形式,不便开发者在云端或 APICloud Studio 中创立利用。
云端创立利用 :
注册并登录 APICloud 零碎:https://www.apicloud.com/console 点击左上⻆“创立利用”,如图:抉择“Native”,填写“名称”及“阐明”,利用创立实现。
APICloud Studio 中创立利用:
下载并装置开发工具:APICloud Studio 2 登录 APICloud Studio,没有账号点击“注册账号”,曾经注册,用之前注册的 APICloud 账号登录 APICloud Studio
这两端能够互相同步信息:
同步本地利用到云端资源库,开发者在 APICloud Studio 创立的利用会和云端资源库建设连贯。我的项目代码改变后,能够应用 APICloud Studio 的代码提交性能提交代码到云端资源库。
关上 APICloud 云端,退出咱们的 ShareSDK 模块和 comlib 模块
模块配置
应用此模块之前倡议先配置 config.xml 文件,配置结束,需通过云端编译失效,配置办法如下:
iOS 配置
配置 config.xml 文件
上面是配置各个平台 URL Scheme 例子,开发者自行删减。上面的值都是 ShareSDK Demo 测试应用,开发者可自行依据本人的 AppKey 批改配置
<feature name="shareSDKPlus">
<param name="urlScheme" value="wx617c77c82218ea2c" />
<param name="urlScheme" value="wb568898243" />
<param name="urlScheme" value="tencent100371282" />
<param name="urlScheme" value="QQ05FB8B52" />
<param name="urlScheme" value="ap2017062107540437" />
<param name="urlScheme" value="fb1412473428822331" />
<param name="urlScheme" value="line3rdp.com.mob.product.ShareSDK" />
<param name="urlScheme" value="yx0d9a9f9088ea44d78680f3274da1765f" />
<param name="urlScheme" value="pdk4987008320438021391" />
<param name="urlScheme" value="kakao9c17eb03317e0e627ec95a400f5785fb" />
<param name="urlScheme" value="dingoabcwtuab76wy0kyzo" />
<param name="urlScheme" value="pocketapp1234" />
<param name="urlScheme" value="vk5312801" />
<param name="urlScheme" value="twitterkit-viOnkeLpHBKs6KXV7MPpeGyzE" />
<param name="urlScheme" value="rm226427com.mob.product.ShareSDK" />
<param name="urlScheme" value="ak1412473428822331" />
<param name="urlScheme" value="aw9ivykfjvi4hpwo" />
</feature>
字段形容:
URL Scheme:用于实现利用间跳转及数据交换,跳转到第三方利用客户端进行分享或受权后,从第三方利用客户端平台跳回到以后利用。URL Scheme 的 value 值依据第三方平台规定设置。能够配置多个 URL Scheme。
各个平台配置标准:
微信:微信开放平台获取的 AppId,URL Scheme 为 wx+AppId 如:wx617c77c82218ea2c
QQ:须要配置两个 URL Scheme,一个是 tencent + AppId; 一个是 QQ + AppId 转换成的十六进制(如果 AppId 转换的 16 进制数不够 8 位则在后面补 0,如转换的是:5FB8B52,则最终填入为 QQ05FB8B52 留神:转换后的字母要大写),这里的字母肯定要是大写
新浪微博:新浪微博开放平台获取到的 appkey,URL Scheme 为 wb+Appkey 如:wb568898243
Facebook:URL Scheme 为 fb+AppId 如:fb1412473428822331
配置 key.xml 文件
须要将第三方平台(微博、QQ、微信、Twitter、Facebook 等)申请的 AppKey、AppSecret、redirecturi 等参数配置到 key.xml 文件中。
key.xml 配置详解:
key.xml 文件须要放在 widget://res 文件目录下,格局如下:
<?xml version="1.0" encoding="UTF-8" ?>
<security>
<item name="shareSDKPlus_SinaWei_AppKey" value="568898243" />
<item name="shareSDKPlus_SinaWei_AppSecret" value="38a4f8204cc784f81f9f0daaf31e02e3" />
<item name="shareSDKPlus_SinaWei_RedirectUri" value="http://www.sharesdk.cn" />
<item name="shareSDKPlus_QQ_AppKey" value="100371282" />
<item name="shareSDKPlus_QQ_AppSecret" value="aed9b0303e3ed1e27bae87c33761161d" />
<item name="shareSDKPlus_Wechat_AppKey" value="wx617c77c82218ea2c" />
<item name="shareSDKPlus_Wechat_AppSecret" value="c7253e5289986cf4c4c74d1ccc185fb1" />
<item name="shareSDKPlus_Wechat_AppUniversalLink" value="https://ybpre.share2dlink.com/" />
<item name="shareSDKPlus_Douyin_AppKey" value="aw9ivykfjvi4hpwo" />
<item name="shareSDKPlus_Douyin_AppSecret" value="42b4caa6bda60bd49f05f06d0a4956e1" />
<item name="shareSDKPlus_Facebook_AppKey" value="1412473428822331" />
<item name="shareSDKPlus_Facebook_AppSecret" value="a42f4f3f867dc947b9ed6020c2e93558" />
<item name="shareSDKPlus_Facebook_DisplayName" value="shareSDK" />
<item name="shareSDKPlus_Twitter_AppKey" value="viOnkeLpHBKs6KXV7MPpeGyzE" />
<item name="shareSDKPlus_Twitter_AppSecret" value="NJEglQUy2rqZ9Io9FcAU9p17omFqbORknUpRrCDOK46aAbIiey" />
<item name="shareSDKPlus_Twitter_RedirectUri" value="http://mob.com" />
<item name="shareSDKPlus_Instagram_AppKey" value="ff68e3216b4f4f989121aa1c2962d058" />
<item name="shareSDKPlus_Instagram_AppSecret" value="1b2e82f110264869b3505c3fe34e31a1" />
<item name="shareSDKPlus_Instagram_RedirectUri" value="http://sharesdk.cn" />
<item name="shareSDKPlus_Google_AppKey" value="232554794995.apps.googleusercontent.com" />
<item name="shareSDKPlus_Google_AppSecret" value="PEdFgtrMw97aCvf0joQj7EMk" />
<item name="shareSDKPlus_Google_RedirectUri" value="http://localhost" />
<item name="shareSDKPlus_Line_AuthType" value="2" />
<item name="shareSDKPlus_AliPaySocial_AppKey" value="2017062107540437" />
<item name="shareSDKPlus_MeiPai_AppKey" value="1089867639" />
<item name="shareSDKPlus_DingTalk_AppKey" value="dingoabcwtuab76wy0kyzo" />
<item name="shareSDKPlus_DouBan_AppKey" value="02e2cbe5ca06de5908a863b15e149b0b" />
<item name="shareSDKPlus_DouBan_AppSecret" value="9f1e7b4f71304f2f" />
<item name="shareSDKPlus_DouBan_RedirectUri" value="http://www.sharesdk.cn" />
<item name="shareSDKPlus_TencentWeibo_AppKey" value="801307650" />
<item name="shareSDKPlus_TencentWeibo_AppSecret" value="ae36f4ee3946e1cbb98d6965b0b2ff5c" />
<item name="shareSDKPlus_TencentWeibo_RedirectUri" value="http://www.sharesdk.cn" />
<item name="shareSDKPlus_YinXiang_AppKey" value="46131514-6903" />
<item name="shareSDKPlus_YinXiang_AppSecret" value="08d7a6f3afcc888a" />
<item name="shareSDKPlus_YinXiang_Sandbox" value="1" />
<item name="shareSDKPlus_YouDaoNote_AppKey" value="dcde25dca105bcc36884ed4534dab940" />
<item name="shareSDKPlus_YouDaoNote_AppSecret" value="d98217b4020e7f1874263795f44838fe" />
<item name="shareSDKPlus_YouDaoNote_RedirectUri" value="http://www.sharesdk.cn/" />
<item name="shareSDKPlus_Mingdao_AppKey" value="97230F25CA5C" />
<item name="shareSDKPlus_Mingdao_AppSecret" value="A5DC29AF7C5A5851F28E903AE9EAC0" />
<item name="shareSDKPlus_Mingdao_RedirectUri" value="http://mob.com" />
<item name="shareSDKPlus_Kaixin_AppKey" value="358443394194887cee81ff5890870c7c" />
<item name="shareSDKPlus_Kaixin_AppSecret" value="da32179d859c016169f66d90b6db2a23" />
<item name="shareSDKPlus_Kaixin_RedirectUri" value="http://www.sharesdk.cn/" />
<item name="shareSDKPlus_Renren_AppId" value="226427" />
<item name="shareSDKPlus_Renren_AppKey" value="fc5b8aed373c4c27a05b712acba0f8c3" />
<item name="shareSDKPlus_Renren_AppSecret" value="f29df781abdd4f49beca5a2194676ca4" />
<item name="shareSDKPlus_Renren_AuthType" value="2" />
<item name="shareSDKPlus_YiXin_AppKey" value="yx0d9a9f9088ea44d78680f3274da1765f" />
<item name="shareSDKPlus_YiXin_AppSecret" value="1a5bd421ae089c3" />
<item name="shareSDKPlus_YiXin_RedirectUri" value="https://open.yixin.im/resource/oauth2_callback.html" />
<item name="shareSDKPlus_Kakao_AppKey" value="9c17eb03317e0e627ec95a400f5785fb" />
<item name="shareSDKPlus_Kakao_ApiKey" value="802e551a5048c3172fc1dedaaf40fcf1" />
<item name="shareSDKPlus_Kakao_RedirectUri" value="http://www.mob.com/oauth" />
<item name="shareSDKPlus_YouTube_AppKey" value="906418427202-jinnbqal1niq4s8isbg2ofsqc5ddkcgr.apps.googleusercontent.com" />
<item name="shareSDKPlus_YouTube_AppSecret" value="" />
<item name="shareSDKPlus_YouTube_RedirectUri" value="http://localhost" />
<item name="shareSDKPlus_Flickr_AppKey" value="cbed81d4a1bc7417693ab7865e354717" />
<item name="shareSDKPlus_Flickr_AppSecret" value="4c490343869091f2" />
<item name="shareSDKPlus_Dropbox_AppKey" value="us514wslpfojbxc" />
<item name="shareSDKPlus_Dropbox_AppSecret" value="w0nmp4os3ngo1ja" />
<item name="shareSDKPlus_Dropbox_RedirectUri" value="http://localhost" />
<item name="shareSDKPlus_Evernote_AppKey" value="46131514-6903" />
<item name="shareSDKPlus_Evernote_AppSecret" value="08d7a6f3afcc888a" />
<item name="shareSDKPlus_Evernote_Sandbox" value="1" />
<item name="shareSDKPlus_Pinterest_AppKey" value="4987008320438021391" />
<item name="shareSDKPlus_Pocket_AppKey" value="11496-de7c8c5eb25b2c9fcdc2b627" />
<item name="shareSDKPlus_Pocket_RedirectUri" value="pocketapp1234" />
<item name="shareSDKPlus_LinkedIn_AppKey" value="46kic3zr7s4n" />
<item name="shareSDKPlus_LinkedIn_AppSecret" value="RWw6WRl9YJOcdWsj" />
<item name="shareSDKPlus_LinkedIn_RedirectUri" value="http://baidu.com" />
<item name="shareSDKPlus_VKontakte_AppKey" value="5312801" />
<item name="shareSDKPlus_VKontakte_AppSecret" value="ZHG2wGymmNUCRLG2r6CY" />
<item name="shareSDKPlus_VKontakte_AuthType" value="2" />
<item name="shareSDKPlus_Instapaper_AppKey" value="4rDJORmcOcSAZL1YpqGHRI605xUvrLbOhkJ07yO0wWrYrc61FA" />
<item name="shareSDKPlus_Instapaper_AppSecret" value="GNr1GespOQbrm8nvd7rlUsyRQsIo3boIbMguAl9gfpdL0aKZWe" />
<item name="shareSDKPlus_Tumblr_AppKey" value="2QUXqO9fcgGdtGG1FcvML6ZunIQzAEL8xY6hIaxdJnDti2DYwM" />
<item name="shareSDKPlus_Tumblr_AppSecret" value="3Rt0sPFj7u2g39mEVB3IBpOzKnM3JnTtxX2bao2JKk4VV1gtNo" />
<item name="shareSDKPlus_Tumblr_RedirectUri" value="http://sharesdk.cn" />
<item name="shareSDKPlus_SMS_CountryList" value="0" />
<item name="shareSDKPlus_CMCC_AppId" value="300011862498" />
<item name="shareSDKPlus_CMCC_AppKey" value="38D9CA1CC280C5F207E2C343745D4A4B" />
<item name="shareSDKPlus_CMCC_DisplayUI" value="1" />
<item name="shareSDKPlus_Telegram_BotToken" value="646009290:AAGSonNPZqyjl0MUER8MdM8pwSPritFVNgI" />
<item name="shareSDKPlus_Telegram_BotDomain" value="http://www.mob.com" />
<item name="shareSDKPlus_Reddit_AppKey" value="ObzXn50T7Cg0Xw" />
<item name="shareSDKPlus_Reddit_RedirectUri" value="https://www.mob.com/reddit_callback" />
<item name="shareSDKPlus_ESurfing_AppKey" value="8148612606" />
<item name="shareSDKPlus_ESurfing_AppSecret" value="mCltrhUqwshFa86egDTs0491ibaAulKA" />
<item name="shareSDKPlus_ESurfing_AppName" value="shareSDK" />
</security>
以上可能呈现的全副各个平台的配置,依据开发者须要删减,另外局部非凡平台须要在 info.plist 文件中配置
字段形容:
shareSDKPlus_SinaWei_AppKey: 从新浪微博开放平台获取的 AppKey.
shareSDKPlus_SinaWei_AppSecret: 从新浪微博开放平台获取的 AppSecret.
shareSDKPlus_SinaWei_RedirectUri: 从新浪微博开放平台创立利用时自定义填写的回调地址 url
其余平台也都是各自到开放平台注册利用获取
配置 info.plist 文件
该文件含 MOB 平台 MOBAppKey 和 MOBAppSecret、非凡平台 AppKey 配置、白名单配置, 将 info.plist 放在 widget://res 文件目录下,文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MOBAppKey</key>
<string>moba6b6c6d6</string>
<key>MOBAppSecret</key>
<string>b89d2427a3bc7ad1aea1e1e8c1d36bf3</string>
<key>AccountKitClientToken</key>
<string>c30c08723aa8c48fbd5e01d1c3103891</string>
<key>FacebookAppID</key>
<string>1412473428822331</string>
<key>KAKAO_APP_KEY</key>
<string>9c17eb03317e0e627ec95a400f5785fb</string>
<key>LineSDKConfig</key>
<dict>
<key>ChannelID</key>
<string>1521201864</string>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>kakaotalk-5.9.7</string>
<string>pinterestsdk.v1</string>
<string>vkauthorize</string>
<string>storylink</string>
<string>kakaolink</string>
<string>storykompassauth</string>
<string>kakaokompassauth</string>
<string>yixinfav</string>
<string>yixinoauth</string>
<string>yixinopenapi</string>
<string>yixin</string>
<string>pocket-oauth-v1</string>
<string>dingtalk-open</string>
<string>dingtalk</string>
<string>alipayshare</string>
<string>alipay</string>
<string>whatsapp</string>
<string>tim</string>
<string>timapi</string>
<string>timopensdkfriend</string>
<string>timwpa</string>
<string>timgamebindinggroup</string>
<string>timapiwallet</string>
<string>timOpensdkSSoLogin</string>
<string>wtlogintim</string>
<string>timopensdkgrouptribeshare</string>
<string>timopensdkapiV4</string>
<string>timgamebindinggroup</string>
<string>timopensdkdataline</string>
<string>wtlogintimV1</string>
<string>timapiV1</string>
<string>yixinoauth</string>
<string>yixin</string>
<string>sinaweibohd</string>
<string>sinaweibo</string>
<string>weibosdk2.5</string>
<string>weibosdk</string>
<string>weibo</string>
<string>sinaweibosso</string>
<string>weixin</string>
<string>youtube</string>
<string>mpsharesdk11</string>
<string>mpsharesdk10</string>
<string>mtmv</string>
<string>mqqopensdkapiV4</string>
<string>mqzone</string>
<string>mqqwpa</string>
<string>wtloginmqq2</string>
<string>mqzoneopensdkapiV2</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapi</string>
<string>mqzoneopensdk</string>
<string>mqqopensdkapiV3</string>
<string>mqqopensdkapiV2</string>
<string>mqq</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqapi</string>
<string>lineauth</string>
<string>line</string>
<string>instagram</string>
<string>fbauth</string>
<string>fb-messenger-platform-20150714</string>
<string>fb-messenger</string>
<string>fbauth2</string>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>twitterauth</string>
<string>tg</string>
<string>telegram</string>
<string>renrenapi</string>
<string>renrenios</string>
<string>renreniphone</string>
<string>douyinsharesdk</string>
<string>douyinopensdk</string>
</array>
<key>NSPhotoLibraryAddUsageDescription</key>
<string> 写入相册视频 </string>
<key>NSPhotoLibraryUsageDescription</key>
<string> 从手机相册中抉择 </string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
MOBAppKey、MOBAppSecret:(必须配置)从 MOB 平台创立利用后,申请的 AppKey 和 AppSecret.
KAKAO_APP_KEY: 从 kaKao 平台申请的 AppKey,若 iOS 平台须要应用 kaKaoTalk、kaKaoStory 平台进行分享,必须增加此字段
LineSDKConfig: line 平台配置
LSApplicationQueriesSchemes: 白名单配置,用于判断是否装置第三方客户端及跳转到第三方客户端,留神用到哪个就配置哪个,无用的能够不配置
留神:
配置白名单,也能够在配置 config.xml 文件中,配置办法参考配置可被检测的 URL Scheme。配置内容参考 疾速集成 配置 ATS(App Transport Security),在 info.plist 文件中,APP 能够应用 http 协定拜访。配置办法参考 iOS 批改 Info.plist 之配置 ATS.
配置 UZApp.entitlements 文件
将 UZApp.entitlements 放在 widget://res 文件目录下,并配置 universal Link,文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:ybpre.share2dlink.com</string>
</array>
</dict>
</plist>
Android 配置
留神:ShareSDK 的 ApiCloud 插件 1.3.1 及之后的版本, 做了分包解决, 集成形式如下: (老版本集成文档)
平台配置
Android 配置第三方平台的 AppKey 和 Mob-AppKey/Mob-AppSecret 等信息遵循 APICloud 的常规是在 config.xml 中配置。在 name 为”ShareSDKPlus”的标签内,配置标签来填充 AppKey 等属性的值。上面是配置各个平台 AppKey/AppSecret/RedirectUrl 的例子,理论的应用中须要开发者填写本人在第三方网站申请的值(只须要扭转值,不要扭转 AppKey/AppSecret/RedirectUrl 的名称,否则将会读取不到)
<feature name="shareSDKPlus">
<param name="Mob-AppKey" value="moba0b0c0d0" />
<param name="Mob-AppSecret" value="5713f0d88511f9f4cf100cade0610a34" />
<param name="WeChat-AppId" value="wx4868b35061f87885" />
<param name="WeChat-AppSecret" value="64020361b8ec4c99936c0e3999a9f249" />
<param name="WeChat-WithShareTicket" value="true" />
<param name="WeChat-BypassApproval" value="false" />
<param name="SinaWeibo-AppKey" value="568898243" />
<param name="SinaWeibo-AppSecret" value="38a4f8204cc784f81f9f0daaf31e02e3" />
<param name="SinaWeibo-ShareByAppClient" value="true" />
<param name="SinaWeibo-RedirectUrl" value="http://www.sharesdk.cn" />
<param name="QQ-AppId" value="100371282" />
<param name="QQ-AppKey" value="aed9b0303e3ed1e27bae87c33761161d" />
<param name="QQ-ShareByAppClient" value="true" />
<param name="QQ-BypassApproval" value="false" />
<param name="Google-ClientID" value="232554794995.apps.googleusercontent.com" />
<param name="Google-RedirectUri" value="http://localhost" />
<param name="Google-ShareByAppClient" value="true" />
<param name="Facebook-ConsumerKey" value="1412473428822331" />
<param name="Facebook-ConsumerSecret" value="a42f4f3f867dc947b9ed6020c2e93558" />
<param name="Facebook-RedirectUrl" value="https://mob.com" />
<param name="Facebook-ShareByAppClient" value="true" />
<param name="Twitter-ConsumerKey" value="viOnkeLpHBKs6KXV7MPpeGyzE" />
<param name="Twitter-ConsumerSecret" value="NJEglQUy2rqZ9Io9FcAU9p17omFqbORknUpRrCDOK46aAbIiey" />
<param name="Twitter-CallbackUrl" value="http://mob.com" />
<param name="Twitter-ShareByAppClient" value="true" />
<param name="Twitter-BypassApproval" value="true" />
<param name="Instagram-ClientId" value="ff68e3216b4f4f989121aa1c2962d058" />
<param name="Instagram-ClientSecret" value="1b2e82f110264869b3505c3fe34e31a1" />
<param name="Instagram-RedirectUri" value="http://sharesdk.cn" />
<param name="Instagram-ShareByAppClient" value="true" />
<param name="Alipay-AppId" value="2015072400185895" />
<param name="Kakao-AppKey" value="48d3f524e4a636b08d81b3ceb50f1003" />
<param name="Telegram-AppKey" value="782826033" />
<param name="Telegram-RedirectUrl" value="http://www.mob.com" />
<param name="Line-ChannelID" value="1639219273" />
<param name="Line-ChannelSecret" value="58faad55ffce8bf8f63b59fe6fb702ae" />
<param name="Line-RedirectUri" value="https://www.mob.com/" />
<param name="Dingding-AppId" value="dingoanxyrpiscaovl4qlw" />
<param name="Dingding-BypassApproval" value="false" />
<param name="Dingding-RedirectUrl" value="http://localhost" />
</feature>
Android 端反对平台
留神:shareSDKPlus 模块在 ApiCloud 的模块库中增加,shareSDKPlus 须要应用的其余第三方平台在 gitHub 上下载
API 接口
留神:
- 应用 QQ 空间时,QQ 模块也必须引入,即 ShareSDKPlusQZone 和 ShareSDKPlusQQ 模块都须要引入。
- 应用 QQ 模块时,须要批改 ShareSDKPlusQQ.zip 内容。
步骤为:
- 解压 ShareSDKPlusQQ.zip
- 批改解压出的 ShareSDKPlusQQ/res 文件夹下的 AndroidManifest.xml 文件中 ${QQ-AppKey}内容,把 ${QQ-AppKey}替换为本人利用的 QQAPPkey
批改后的内容为:其中 1234567 则为本人 QQ 的 appkey
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mob.sharesdkplusqq">
<application>
<activity
android:name="cn.sharesdk.tencent.qq.ReceiveActivity"
android:launchMode="singleTask"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tencent1234567" />
</intent-filter>
</activity>
</application>
</manifest>
- 批改实现,压缩 ShareSDKPlusQQ 文件夹,压缩形式抉择规范。
模块接口
首先增加一个 ShareSDK.js,放在 widget://script 文件目录下,内容如下:
/**
* 常量:分享类型,分享 / 受权平台,分享 / 受权后果状态
*/
function ShareSDK()
{
/**
* JSON 字符串转换为对象
* @param string JSON 字符串
* @returns {Object} 转换后对象
*/
JsonStringToObject = function (string)
{
try
{return eval("(" + string + ")");
}
catch (err)
{return null;}
};
this.JsonStringToObject = function (string)
{return JsonStringToObject(string);
}
/**
* 对象转 JSON 字符串
* @param obj 对象
* @returns {string} JSON 字符串
*/
ObjectToJsonString = function (obj)
{var S = [];
var J = null;
var type = Object.prototype.toString.apply(obj);
if (type === '[object Array]')
{for (var i = 0; i < obj.length; i++)
{S.push(ObjectToJsonString(obj[i]));
}
J = '[' + S.join(',') + ']';
}
else if (type === '[object Date]')
{J = "new Date(" + obj.getTime() + ")";
}
else if (type === '[object RegExp]'
|| type === '[object Function]')
{J = obj.toString();
}
else if (type === '[object Object]')
{for (var key in obj)
{var value = ObjectToJsonString(obj[key]);
if (value != null)
{S.push('"'+ key +'":' + value);
}
}
J = '{' + S.join(',') + '}';
}
else if (type === '[object String]')
{J = '"'+ obj.replace(/\\/g,'\\\\').replace(/"/g, '\\"').replace(/\n/g, '') +'"';
}
else if (type === '[object Number]')
{J = obj;}
else if (type === '[object Boolean]')
{J = obj;}
return J;
};
this.ObjectToJsonString = function (obj)
{return ObjectToJsonString(obj);
}
/**
* 平台类型
* @type {object}
*/
this.PlatformID = {
Unknown : 0,
SinaWeibo : 1, //Sina Weibo
TencentWeibo : 2, //Tencent Weibo
DouBan : 5, //Dou Ban
QZone : 6, //QZone
Renren : 7, //Ren Ren
Kaixin : 8, //Kai Xin
Pengyou : 9, //Friends
Facebook : 10, //Facebook
Twitter : 11, //Twitter
Evernote : 12, //Evernote
Foursquare : 13, //Foursquare
GooglePlus : 14, //Google+
Instagram : 15, //Instagram
LinkedIn : 16, //LinkedIn
Tumblr : 17, //Tumblr
Mail : 18, //Mail
SMS : 19, //SMS
Print : 20, //Print
Copy : 21, //Copy
WeChat : 22, //WeChat Friends
WeChatMoments : 23, //WeChat Timeline
QQ : 24, //QQ
Instapaper : 25, //Instapaper
Pocket : 26, //Pocket
YouDaoNote : 27, //You Dao Note
Pinterest : 30, //Pinterest
Flickr : 34, //Flickr
Dropbox : 35, //Dropbox
VKontakte : 36, //VKontakte
WeChatFavorites : 37, //WeChat Favorited
YiXinSession : 38, //YiXin Session
YiXinTimeline : 39, //YiXin Timeline
YiXinFav : 40, //YiXin Favorited
MingDao : 41, // 明道
Line : 42, //Line
WhatsApp : 43, //Whats App
KakaoTalk : 44, //KakaoTalk
KakaoStory : 45, //KakaoStory
FacebookMessenger : 46, //FacebookMessenger
Bluetooth : 48, //Bluetooth
Alipay : 50, //Alipay
AliPaySocialTimeline:51,//AliPaySocial Timeline
DingTalk:52, //DingTalk
YouTube:53, //youtube
MeiPai:54, // 美拍
Cmcc : 55, // 中国移动
Reddit : 56, //Reddit
ESurfing : 57, // 天翼
Douyin : 58, // 抖音
FacebookAccount : 58, //FacebookAccount
KakaoPlatform : 995, //Kakao Series
EvernotePlatform : 996, //Evernote Series
WechatPlatform : 997, //Wechat Series
QQPlatform : 998, //QQ Series
Any : 999 //Any Platform
};
/**
* 回复状态
* @type {object}
*/
this.ResponseState = {
Begin : 0, // 开始
Success: 1, // 胜利
Fail : 2, // 失败
Cancel : 3 // 勾销
};
/**
* 内容分享类型
* @type {object}
*/
this.ContentType = {
Auto : 0,
Text : 1,
Image : 2,
WebPage : 4,
Music : 5,
Video : 6,
App : 7,
File : 8,
Emoji : 9
};
};
var $sharesdk = new ShareSDK();
增加 ShareSDK.js 目标次要是提供平台号,回调状态等一些常量
引入模块
var shareApi = api.require('shareSDKPlus');
authorize(受权)
authorize({params}, callback(ret, err))
params
platform:类型:数字 形容:受权平台号,是新浪微博受权还是微信受权或者其余平台受权,由此参数决定
callback(ret, err)
ret:类型:JSON 对象 外部字段:
{
state: 1 // 数字类型,1: 胜利 2: 失败 3: 勾销
data:{} //json 对象 受权后获取的用户信息
error:{ // state = 2 时
error_code:, // 错误码
error_msg: // 错误信息
}
}
示例代码
var shareApi = api.require('ShareSDKPlus');
shareApi.authorize({"platform": $sharesdk.PlatformID.SinaWeibo},function(ret, err){
var state = ret.state;
switch(state)
{
case $sharesdk.ResponseState.Success://1
api.toast({
msg: "受权胜利",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Fail://2
api.toast({
msg: "受权失败",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Cancel://3
api.toast({
msg: "勾销受权",
location: 'middle'
});
break;
default:
}
});
可用性 iOS 零碎,Android 零碎 可提供的 1.0.0 及更高版本
cancelAuthorize(勾销受权)
cancelAuthorize({params}, callback(ret, err))
params
platform:类型:数字 形容:受权平台号
callback(ret, err)
ret:类型:JSON 对象 外部字段:
{
state: 1 // 数字类型,1: 胜利 2: 失败 3: 勾销
error:{ // state = 2 时
error_code:, // 错误码
error_msg: // 错误信息
}
}
示例代码
var shareApi = api.require('ShareSDKPlus');
shareApi.cancelAuthorize({"platform": $sharesdk.PlatformID.SinaWeibo},function(ret, err){
var state = ret.state;
switch(state)
{
case $sharesdk.ResponseState.Success://1
api.toast({
msg: "胜利",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Fail://2
api.toast({
msg: "失败",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Cancel://3
api.toast({
msg: "受权",
location: 'middle'
});
break;
default:
}
});
可用性
iOS 零碎,Android 零碎 可提供的 1.0.0 及更高版本
getUserInfo(获取用户信息)
getUserInfo({params}, callback(ret, err))
params
platform:类型:数字 形容:平台号,是获取新浪微博还是微信或者其余平台用户信息,由此参数决定
callback(ret, err)
ret:类型:JSON 对象 外部字段:
{
state: 1 // 数字类型,1: 胜利 2: 失败 3: 勾销
data:{} //json 对象 获取的用户信息
error:{ // state = 2 时
error_code:, // 错误码
error_msg: // 错误信息
}
}
示例代码
var shareApi = api.require('ShareSDKPlus');
shareApi.getUserInfo({"platform": $sharesdk.PlatformID.SinaWeibo},function(ret, err){
var state = ret.state;
switch(state)
{
case $sharesdk.ResponseState.Success://1
api.toast({
msg: "胜利",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Fail://2
api.toast({
msg: "失败",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Cancel://3
api.toast({
msg: "勾销",
location: 'middle'
});
break;
default:
}
});
shareContent(间接分享)
shareContent({params}, callback(ret, err))
params
platform:类型:数字 形容:平台号,分享到指定平台
shareParams
类型:json 形容:分享内容 text:文本 imageUrl:图片地址 title:题目
callback(ret, err)
ret:类型:JSON 对象 外部字段:
{
state: 1 // 数字类型,1: 胜利 2: 失败 3: 勾销
data:{} //
error:{ // state = 2 时
error_code:, // 错误码
error_msg: // 错误信息
}
}
示例代码
var shareApi = api.require('ShareSDKPlus');
var shareParams =
{
"text" : "测试的文字",
"imageUrl" : "https://download.sdk.mob.com/206/4f8/dfc9ea27dd8bc4abfec865c38d/800_450_156.2.jpg",
"title" : "测试的题目",
"titleUrl" : "http://www.mob.com",
"description" : "测试的形容",
"site" : "ShareSDK",
"siteUrl" : "http://www.mob.com",
};
shareApi.shareContent({
"platform": $sharesdk.PlatformID.SinaWeibo,
"shareParams": shareParams
"shareType" : $sharesdk.ContentType.Auto
},function(ret, err){
var state = ret.state;
switch(state)
{
case $sharesdk.ResponseState.Success://1
api.toast({
msg: "分享胜利",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Fail://2
api.toast({
msg: "分享失败",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Cancel://3
api.toast({
msg: "勾销分享",
location: 'middle'
});
break;
default:
}
});
可用性
iOS 零碎,Android 零碎 可提供的 1.0.0 及更高版本
oneKeyShareContent(一键分享 / 菜单分享)
oneKeyShareContent({params}, callback(ret, err))
params
platforms:
platform:类型:数组 形容:可分享的平台列表,为 null 为全平台
shareParams:
类型:json 形容:分享内容 text:文本 imageUrl:图片地址 title:题目
callback(ret, err)
ret:类型:JSON 对象 外部字段:
{
state: 1 // 数字类型,1: 胜利 2: 失败 3: 勾销
data:{} //
error:{ // state = 2 时
error_code:, // 错误码
error_msg: // 错误信息
}
}
示例代码
var shareApi = api.require('ShareSDKPlus');
var shareParams =
{
"text" : "测试的文字",
"imageUrl" : "https://download.sdk.mob.com/206/4f8/dfc9ea27dd8bc4abfec865c38d/800_450_156.2.jpg",
"title" : "测试的题目",
"titleUrl" : "http://www.mob.com",
"description" : "测试的形容",
"site" : "ShareSDK",
"siteUrl" : "http://www.mob.com",
};
var platforms =
[
$sharesdk.PlatformID.SinaWeibo,
$sharesdk.PlatformID.WeChat
];
shareApi.oneKeyShareContent({
"platforms": platforms, // 为 null 时,显示全副可分享的平台(排除以后环境不可分享平台)"shareParams": shareParams
},function(ret, err){
var state = ret.state;
switch(state)
{
case $sharesdk.ResponseState.Success://1
api.toast({
msg: "分享胜利",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Fail://2
api.toast({
msg: "分享失败",
location: 'middle'
});
break;
case $sharesdk.ResponseState.Cancel://3
api.toast({
msg: "勾销分享",
location: 'middle'
});
break;
default:
}
});
可用性 iOS 零碎,Android 零碎 可提供的 1.0.0 及更高版本
如何裁减平台
以后 ShareSDKPlus 只反对微信、QQ、新浪微博、钉钉、支付宝、facebook、twitter、Instagram、line、WhatsApp 等十个平台,如果想要反对其余平台应如何操作
iOS 计划
点击此处
Android 计划
点击此处
APICloud 例子 demo
点击此处