关于uni-app:ShareSDK-Uniapp-插件

2次阅读

共计 10797 个字符,预计需要花费 27 分钟才能阅读完成。

筹备
下载开发工具 HBuilderX

筹备 uniapp 我的项目
如果没有曾经创立好的我的项目,能够自行创立新的我的项目

之后抉择新建 uni-app 我的项目。关上 HBuildX 的文件 -> 导入 -> 本地我的项目导入创立的文件夹 -> 创立。

插件集成

本地插件集成
[下载离线插件
](https://ext.dcloud.net.cn/plu…)

将下载好的插件放在我的项目的 nativeplugins 文件夹中。(若没有则创立此目录)目录构造如下:

之后在 uniapp 的“manifest.json”中抉择“app 原生插件配置”,点击抉择本地插件,如图:

云端插件集成

在 uniapp 的“manifest.json”中抉择“app 原生插件配置”,点击抉择云端插件,如图:

留神:本地插件和云端插件能够任选一样配置,区别在于本地插件寄存到工程 nativeplugins 目录下的原生插件,实用于未公布到插件市场的公有原生插件进行云打包,云端插件是曾经在插件市场购买或绑定试用的插件,无需下载插件到工程中,云打包时会间接合并打包原生插件到 App 中。不过咱们提供的插件是收费的哦!
iOS 平台相干配置
配置初始化信息和 URL SCheme
在“app 原生插件配置”中增加 MobTech 平台注册的 MOBAppKey 和 MOBAppSecret,如何失去这 2 个参数,请参考这个流程。以及微信、QQ、新浪、Facebook、Twitter 等平台的注册平台信息。各平台注册地址,请点击 这里。

并在“app 罕用其余设置”中的“iOS 设置”中填写 URL Scheme,以及白名单等信息,具体每个平台如何配置,请参考 原生文档配置 Xcode 我的项目这块。

配置平台的 Universal Link

微信以及 qq 要求用户在新版 SDK 中填写 universalLink,所以须要在利用中配置通用链接,须要在 manifest.json 的源码视图添 ”app-plus”->”distribute”->”ios” 下,增加如下代码:

Android 平台相干配置

留神:安卓端只反对本地依赖形式导入

增加依赖

  1. 在 uniapp 插件市场找到 ShareSDK 插件,点击下载 for 离线打包

2. 解压到 uni-app 利用的 nativeplugins 目录中
具体参考:https://ask.dcloud.net.cn/art…, 实现后如下图:

配置分享平台信息

配置 ShareSDK.xml 文件
在我的项目中 mob-sharesdk/android 下新建 assets 目录,在新创建的 assets 目录中创立名为 ShareSDK.xml 的文件,如下图:

ShareSDK.xml 文件内容示例为:

其中各平台的 appkey 等信息仅为 demo 示例,正式应用请替换为本人在分享受权平台申请的

<?xml version="1.0" encoding="utf-8"?>
<DevInfor>
<SinaWeibo Id="1" SortId="59" AppKey="568898243" AppSecret="38a4f8204cc784f81f9f0daaf31e02e3" ShareByAppClient="true" Enable="true" RedirectUrl="http://www.sharesdk.cn" />
<TencentWeibo Id="2" SortId="2" AppKey="801307650" AppSecret="ae36f4ee3946e1cbb98d6965b0b2ff5c" Enable="true" RedirectUri="http://sharesdk.cn" />
<Douban Id="16" SortId="16" Enable="true" ApiKey="031a96a3aa8b28af094fc3eaffa17a0d" Secret="2e675e730571b75d" RedirectUri="http://mob.com" />
<QZone Id="3" SortId="3" AppId="100371282" AppKey="aed9b0303e3ed1e27bae87c33761161d" ShareByAppClient="true" BypassApproval="false" Enable="true" />
<Renren Enable="false" />
<KaiXin Enable="false" />
<Facebook Id="8" SortId="8" ShareByAppClient="true" Enable="true" ConsumerKey="2796236850615578" ConsumerSecret="7d353609b517b23a80dcb057995ef30c" RedirectUrl="https://mob.com" />
<Twitter Id="9" SortId="9" ShareByAppClient="true" Enable="true" ConsumerKey="viOnkeLpHBKs6KXV7MPpeGyzE" ConsumerSecret="NJEglQUy2rqZ9Io9FcAU9p17omFqbORknUpRrCDOK46aAbIiey" CallbackUrl="http://mob.com" />
<Evernote Id="19" SortId="19" HostType="sandbox" ShareByAppClient="true" Enable="true" ConsumerKey="sharesdk-7807" ConsumerSecret="d05bf86993836004" />
<FourSquare Enable="false" />
<GooglePlus Id="21" SortId="21" OfficialVersion="default" ShareByAppClient="true" Enable="true" ClientID="236300675100-am5pm8km7md1memjevq8rl9pg5c4s4b8.apps.googleusercontent.com" RedirectUrl="http://localhost" />
<Instagram Id="28" SortId="28" ShareByAppClient="true" Enable="true" ClientId="ff68e3216b4f4f989121aa1c2962d058" ClientSecret="1b2e82f110264869b3505c3fe34e31a1" RedirectUri="http://sharesdk.cn" />
<LinkedIn Id="20" SortId="20" ShareByAppClient="true" Enable="true" ApiKey="ejo5ibkye3vo" SecretKey="cC7B2jpxITqPLZ5M" RedirectUrl="http://sharesdk.cn" />
<Tumblr Enable="false" />
<Email Id="12" SortId="12" Enable="true" />
<ShortMessage Id="13" SortId="13" Enable="true" />
<Wechat Id="4" SortId="4" AppId="wx4868b35061f87885" AppSecret="64020361b8ec4c99936c0e3999a9f249" WithShareTicket="true" BypassApproval="false" Enable="true" />
<WechatMoments Id="5" SortId="5" AppId="wx4868b35061f87885" AppSecret="64020361b8ec4c99936c0e3999a9f249" BypassApproval="false" Enable="true" />
<QQ Id="7" SortId="7" AppId="100371282" AppKey="aed9b0303e3ed1e27bae87c33761161d" ShareByAppClient="true" BypassApproval="false" Enable="true" />
<Instapaper Id="38" SortId="38" Enable="true" ConsumerKey="4rDJORmcOcSAZL1YpqGHRI605xUvrLbOhkJ07yO0wWrYrc61FA" ConsumerSecret="GNr1GespOQbrm8nvd7rlUsyRQsIo3boIbMguAl9gfpdL0aKZWe" />
<Pocket Id="37" SortId="37" Enable="true" ConsumerKey="32741-389c565043c49947ba7edf05" />
<YouDao Id="17" SortId="17" HostType="product" Enable="true" ConsumerKey="dcde25dca105bcc36884ed4534dab940" ConsumerSecret="d98217b4020e7f1874263795f44838fe" RedirectUri="http://www.sharesdk.cn/" />
<Pinterest Enable="false" />
<Flickr Enable="false" />
<Dropbox Enable="false" />
<VKontakte Id="27" SortId="27" ShareByAppClient="true" Enable="true" ApplicationId="3921561" />
<WechatFavorite Id="6" SortId="6" AppId="wx4868b35061f87885" AppSecret="64020361b8ec4c99936c0e3999a9f249" BypassApproval="false" Enable="true" />
<Yixin Enable="false" />
<YixinMoments Enable="false" />
<Mingdao Enable="false" />
<Line Id="32" SortId="32" callbackscheme="lineauth" Enable="true" ChannelID="1639219273" ChannelSecret="58faad55ffce8bf8f63b59fe6fb702ae" RedirectUri="https://www.mob.com/" />
<WhatsApp Id="35" SortId="35" Enable="true" />
<KakaoTalk Id="33" SortId="33" AppKey="48d3f524e4a636b08d81b3ceb50f1003" Enable="true" />
<KakaoStory Id="34" SortId="34" AppKey="48d3f524e4a636b08d81b3ceb50f1003" Enable="true" />
<FacebookMessenger Id="39" SortId="39" AppId="107704292745179" OfficialVersion="default" Enable="true" />
<Alipay Id="50" SortId="50" AppId="2015072400185895" Enable="true" />
<AlipayMoments Id="51" SortId="51" AppId="2015072400185895" Enable="true" />
<Dingding Id="52" SortId="52" AppId="dingoanxyrpiscaovl4qlw" BypassApproval="false" Enable="true" />
<Youtube Id="53" SortId="53" AppSecret="AIzaSyAO06g-0TDpHcsXXO918a7QE3Zdct2bB5E" ShareByAppClient="true" Enable="true" ClientID="370141748022-bicrnsjfiije93bvdt63dh3728m4shas.apps.googleusercontent.com" RedirectUrl="http://localhost" />
<Meipai Id="54" SortId="54" AppSecret="y9ym6rrjjijtkt23qtsc" ShareByAppClient="true" Enable="true" ClientID="1089867596" />
<Telegram Id="47" SortId="47" AppKey="782826033" Enable="true" RedirectUrl="http://www.mob.com" />
<Cmcc Id="55" SortId="55" AppId="300011860247" AppKey="2D464D8BFCE73A44B4F9DF95A2FDBE1C" />
<Reddit Id="56" SortId="56" AppKey="MExDxPuTCtFiRw" RedirectUrl="http://www.sharesdk.cn" />
<Telecom Id="57" SortId="57" AppKey="8148612606" AppSecret="mCltrhUqwshFa86egDTs0491ibaAulKA" Enable="true" RedirectUrl="http://www.sharesdk.cn" />
<Accountkit Id="58" SortId="58" AppKey="579465512480462" AppSecret="8a6383652dd9f23fb0994f03d350d0ca" Enable="true" RedirectUrl="http://www.sharesdk.cn/" />
<Douyin Id="59" SortId="1" AppKey="aw9ivykfjvi4hpwo" AppSecret="42b4caa6bda60bd49f05f06d0a4956e1" Enable="true" />
<Wework Id="60" SortId="60" AppKey="wwa21eaecf93f0e3ba" AppSecret="dW7e27P7Hc8NiYdRxnbTeOLgfI1ugR72e-PM8uusq2s" AgentId="1000012" Schema="wwautha21eaecf93f0e3ba000012" />
<HWAccount Enable="false" />
<Oasis Enable="false" />
<XMAccount Enable="false" />
<SnapChat Enable="false" />
<Kuaishou Id="68" SortId="68" Enable="true" />
<Littleredbook Enable="false" />
<Watermelonvideo Enable="false" />
<Tiktok Enable="false" />
</DevInfor>

配置 manifest.json
抉择 manifest.json 文件中的 App 原生插件配置,增加本地插件或云端插件 mob-sharesdk,别离填写 Mob-AppKey、Mob-AppSecret、QQ-AppId、Facebook-AppKey、Line-CallBackScheme,其中 Mob-AppKey、Mob-AppSecret 为必填,其余三项可按需填写。

接口调用

编写相干代码
在 index.vue 中编写代码,包含页面和点击办法。

引入模块(必要)

const modal = uni.requireNativePlugin('modal');
const pluginMobShare = uni.requireNativePlugin('mob-sharesdk');

ShareSDK 性能接口
submitPrivacyGrantResult() 回传隐衷受权状态
例子调用:

// 回传用户受权后果
            //isurl 参数如果传入字符串‘true’则示意承受隐衷协定
            submitPrivacyGrantResult() {
                pluginMobShare.submitPrivacyGrantResult({
                    isUrl: 'true',
                    mobAppkey: 'moba0b0c0d0',
                    mobSecret: '5713f0d88511f9f4cf100cade0610a34',
                }, result => {const msg = JSON.stringify(result);
                    modal.toast({
                        message: msg,
                        duration: 2 ,
                    });
                });
            },

留神:该接口必须接入,否则可能造成无奈应用 MobTech 各 SDK 提供的相干服务。
generalShare() 间接分享办法接口

可传参数阐明:String PLATNAME = "platName";          // 平台名
 String MOB_APPKEY = "mobAppkey";       //MobSDK 的 appkey
 String MOB_SECRET = "mobSecret";       //MobSDK 的 appSecret
 String PLAT_APPKEY = "platAppkey";     // 平台的 appkey
 String PLAT_APPSECRET = "platAppSecret";// 平台的 appsecret
 String PLAT_REDIRECTURL = "platRedirectUrl";// 平台的回掉地址

 String PLAT_SHAREBYAPPCLIENT = "platShareByAppClient";// 平台的是否通过客户端分享
 String PLAT_BYPASSAPPROVAL = "platBypassApproval";// 平台的是否绕过审核

 String TEXT = "text"; // 文本
 String TITLE = "title"; // 题目
 String URL = "url";// 链接地址
 String IMAGE_URL = "imageUrl";// 网络图片地址
 SHARETYPE = "shareType";// 分享类型
 String TITLE_URL = "titleUrl";//QQ 平台须要的参数
 String IMAGE_PATH = "imagePath";// 本地图片地址
 String MUSIC_URL = "musicUrl";// 音乐链接地址
 String SITE = "site";//QQ 须要的参数
 SITE_URL = "siteUrl";//QQ 须要的参数
 FILE_PATH = "filePath";// 文件本地门路

返回类型

//state : number 类型 状态 1、胜利,2、失败,3、勾销
//userData:对象类型,用户信息
//contentEtitiy: 对象类型,内容实体
//error:对象类型,错误信息
{
state: 1 
userData:{}
contentEtitiy:{}
error:{}}

例子调用:

mobShareWebpage() {
                    pluginMobShare.generalShare({
                    platName: SSDKPlatformID.WeChat,
                    params: {
                        text: 'text',
                        title: "title",
                        imageUrl: "http://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg",
                        url: "http://m.93lj.com/sharelink?mobid=ziqMNf",
                    },
                    shareType: SSDKContentType.WebPage,
                }, result => {const modal = uni.requireNativePlugin('modal');
                    const msg = JSON.stringify(result);
                    modal.toast({
                        message: msg,
                        duration: 1.5
                    });

                });
            }

authorize()受权办法接口

参数阐明:platName: 平台号
mobAppkey: 申请的 MobSDK 的 appkey
mobSecret: 申请的 MobSDK 的 secret

iOS 返回:

//state : number 类型 状态 1、胜利,2、失败,3、勾销
//userData:对象类型,用户信息
//error:对象类型,错误信息
{
state: 1 
userData:{}
error:{}}

例子调用

mobAuthorize() {
                pluginMobShare.authorize({
                    platName: '24',
                    mobAppkey: 'moba0b0c0d0',
                    mobSecret: '5713f0d88511f9f4cf100cade0610a34',
                }, result => {const msg = JSON.stringify(result);
                    modal.toast({
                        message: msg,
                        duration: 2 ,
                    });

                });
                    switch (result.type) {
                        case 'onComplete':
                            console.log("callback---onComplete--" + result.onCompleteResult);
                            break;
                        case 'onError':
                            console.log("callback---onError--" + result.onErrorResult);
                            break;
                        case 'onCancel':
                            console.log("callback---onCancel--");
                            break;
                }
            }

cancelauthorize() 勾销受权

参数阐明:platName: 平台号
mobAppkey: 申请的 MobSDK 的 appkey
mobSecret: 申请的 MobSDK 的 secret

返回类型:

//error: 勾销受权失败返回信息
{error:{}
}

例子调用

mobCancelAuthorize() {
                pluginMobShare.cancelauthorize({
                    platName: '24',
                    mobAppkey: 'moba0b0c0d0',
                    mobSecret: '5713f0d88511f9f4cf100cade0610a34',
                }, result => {const msg = JSON.stringify(result);
                    modal.toast({
                        message: msg,
                        duration: 2 ,
                    });

                });
                    switch (result.type) {
                        case 'onComplete':
                            console.log("callback---onComplete--" + result.onCompleteResult);
                            break;
                        case 'onError':
                            console.log("callback---onError--" + result.onErrorResult);
                            break;
                }
            }

getUserInfo() 获取用户信息

参数阐明:platName: 平台号
mobAppkey: 申请的 MobSDK 的 appkey
mobSecret: 申请的 MobSDK 的 secret
返回参数
//state : number 类型 状态 1、胜利,2、失败,3、勾销
//userData:对象类型,用户信息
//error:对象类型,错误信息
{
state: 1 
userData:{}
error:{}}

例子调用

mobgetUserInfo() {
                pluginMobShare.getUserInfo({
                    platName: '24',
                    mobAppkey: 'moba0b0c0d0',
                    mobSecret: '5713f0d88511f9f4cf100cade0610a34',
                }, result => {const msg = JSON.stringify(result);
                    modal.toast({
                        message: msg,
                        duration: 2 ,
                    });

                });
                    switch (result.type) {
                        case 'onComplete':
                            console.log("callback---onComplete--" + result.onCompleteResult);
                            break;
                        case 'onError':
                            console.log("callback---onError--" + result.onErrorResult);
                            break;
                        case 'onCancel':
                            console.log("callback---onCancel--");
                            break;
                }
            }

调试

将插件放入 uniapp 我的项目中调试
打自定义基座

将证书等信息增加进去,期待云打包实现后

选中自定义基座,运行这个我的项目,进行调试
自此,整个流程就走完了。如有问题,能够分割官网技术支持 QQ:4006852216
备注:对于参数 platName 平台号对照表

SinaWeibo 1
TencentWeibo 2
Douban 5
QZone 6
Renren 7
KaiXin 8
Facebook 10
Twitter 11
Evernote 12
FourSquare 13
GooglePlus 14
Instagram 15
LinkedIn 16
Tumblr 17
Email 18
Wechat 22
WechatMoments 23
QQ 24
Instapaper 25
Pocket 26
YouDao 27
Pinterest 30
Flickr 34
Dropbox 35
VKontakte 36
WechatFavorite 37
Yixin 38
YixinMoments 39
Mingdao 41
Line 42
WhatsApp 43
KakaoTalk 44
KakaoStory 45
FacebookMessenger 46
Bluetooth 48
Alipay 50
AlipayMoments 51
Dingding 52
Youtube 53
Meipai 54
Cmcc 55
Reddit 56
Telecom 57
Douyin 58
Accountkit 59
备注:对于参数 SHARETYPE 平台号对照表

Auto 0
Text 1
Image 2
Webpage 3
App 4
Audio 5
Video 6
File 7
正文完
 0