前言这是一个基于ShareSDK功能的扩展的Flutter插件。使用此插件能够帮助您在使用Flutter开发应用时,快速地实现社会化功能,例如第三方授权登录,获取用户信息以及社交平台的分享等功能。Demo例子:https://github.com/MobClub/ShareSDK-For-Flutter开始集成引入插件
图片
在pubspec.yaml文件中加入下面依赖dependencies:
mobcommonlib:
sharesdk_plugin:
然后执行:flutter packages get 导入package在你的dart工程文件中,导入下面头文件,开始使用import 'package:sharesdk_plugin/sharesdk_plugin.dart';
iOS端集成配置iOS端自定义需要导入的分享平台(非必须)iOS : 这个文件里默认有我们的一些主流平台,如果需要增加平台,或者减少平台,你需要重新编辑 sharesdk_plugin.podspec文件设置 dependency,具体支持的平台可以参阅 pod search mob_sharesdk 或者参考 官网文档#

To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html

Pod::Spec.new do |s|
s.name = 'sharesdk_plugin'
s.version = '1.1.0'
s.summary = 'Flutter plugin for ShareSDK.'
s.description = <<-DESC
ShareSDK is the most comprehensive Social SDK in the world,which share easily with 40+ platforms.

                   DESC

s.homepage = 'http://www.mob.com/mobService/sharesdk'
s.license = { :file => '../LICENSE' }
s.author = { 'Mob' => 'mobproduct@mob.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/*/'
s.public_header_files = 'Classes/*/.h'
s.dependency 'Flutter'
s.dependency 'mob_sharesdk'
s.dependency 'mob_sharesdk/ShareSDKExtension'
s.dependency 'mob_sharesdk/ShareSDKUI'
s.dependency 'mob_sharesdk/ShareSDKPlatforms/QQ'
s.dependency 'mob_sharesdk/ShareSDKPlatforms/SinaWeibo'
s.dependency 'mob_sharesdk/ShareSDKPlatforms/WeChat'
s.dependency 'mob_sharesdk/ShareSDKPlatforms/Facebook'
s.dependency 'mob_sharesdk/ShareSDKPlatforms/Twitter'
s.static_framework = true

s.ios.deployment_target = '8.0'
end
改好了之后,cd到Xcode目录下,重新pod update即可!初始化SDK配置初始化我们SDK的AppKey在项目工程的Info.plist中如图增加MOBAppKey 和 MOBAppSecret 两个字段
图片
配置平台的URL SCheme和白名单配置对应平台的URL Scheme和白名单请参考原生文档里的第四点配置XCode项目里的 URL Scheme配置 和 白名单配置第三方平台初始化添加初始化代码@override

void initState() {
  // TODO: implement initState
  super.initState();

  ShareSDKRegister register = ShareSDKRegister();
  register.setupWechat(
    "wx617c77c82218ea2c", "c7253e5289986cf4c4c74d1ccc185fb1", "https://70imc.share2dlink.com/");
  register.setupSinaWeibo(
      "568898243", "38a4f8204cc784f81f9f0daaf31e02e3", "http://www.sharesdk.cn", "https://70imc.share2dlink.com/");
  register.setupQQ("100371282", "aed9b0303e3ed1e27bae87c33761161d");
  register.setupFacebook(
    "1412473428822331", "a42f4f3f867dc947b9ed6020c2e93558", "shareSDK");
  register.setupTwitter("viOnkeLpHBKs6KXV7MPpeGyzE",
    "NJEglQUy2rqZ9Io9FcAU9p17omFqbORknUpRrCDOK46aAbIiey", "http://mob.com");
  register.setupLinkedIn("46kic3zr7s4n", "RWw6WRl9YJOcdWsj", "http://baidu.com");
  SharesdkPlugin.regist(register);
}

Android端集成配置重新编辑build.gradleAndroid : 你需要重新编辑build.gradle文件来选择你需要使用的平台,具体支持的平台可以参阅 官网技术文档配置AndroidManifestAndroidManifest中需要加入配置tools:replace="android:name"
将其加到application中,避免mobsdk与flutter的application冲突;第三方平台添加如下所示,devInfo内部,需要的平台可以自己添加,不需要的可以删除其中的配置即可;具体支持的平台可以参阅 官网技术文档MobSDK {

    appKey "moba6b6c6d6"
    appSecret "b89d2427a3bc7ad1aea1e1e8c1d36bf3"

    ShareSDK {

        devInfo {
            QQ {
                id 7
                sortId 7
                appId "100371282"
                appKey "aed9b0303e3ed1e27bae87c33761161d"
                shareByAppClient true
                bypassApproval false
                enable true
                }

            SinaWeibo {
                id 1
                sortId 1
                appKey "568898243"
                appSecret "38a4f8204cc784f81f9f0daaf31e02e3"
                callbackUri "http://www.sharesdk.cn"
                shareByAppClient true
                enable true
                }

            Wechat {
                id 4
                sortId 4
                appId "wx4868b35061f87885"
                appSecret "64020361b8ec4c99936c0e3999a9f249"
                userName "gh_afb25ac019c9"
                path "pages/index/index.html?id=1"
                withShareTicket true
                miniprogramType 0
                bypassApproval false
                enable true
                }

            Facebook {
                id 8
                sortId 8
                appKey "1412473428822331"
                appSecret "a42f4f3f867dc947b9ed6020c2e93558"
                callbackUri "https://mob.com"
                shareByAppClient true
                enable true
            }

            Twitter {
                id 9
                sortId 9
                appKey "viOnkeLpHBKs6KXV7MPpeGyzE"
                appSecret "NJEglQUy2rqZ9Io9FcAU9p17omFqbORknUpRrCDOK46aAbIiey"
                callbackUri "http://mob.com"
                shareByAppClient true
                enable true
            }
        }
    }
}

API接口调用回传用户隐私授权结果 (submitPrivacyGrantResult)/**

  • 回传用户隐私授权结果
  • @param status 用户是否同意隐私协议
  • @param result 默认传null
    */

Mobcommonlib.submitPolicyGrantResult(bool status, Function(bool)? result)
参数类型作用必填statusbool是否同意隐私是resultFunction(bool)回调是例:
Mobcommonlib.submitPolicyGrantResult(true, null);
ShareSDK功能接口使用auth授权(只授权不获取用户信息)getUserInfo授权(授权的同时获取用户信息)ShowMenu弹出九宫格菜单分享openMiniProgram打开微信小程序shareMiniProgram分享微信小程序shareSinaLinkCard分享新浪微博linkcard效果shareSinaCustom新浪单独分享shareTwitterCustom推特单独分享shareFacebookCustomFacebook单独分享shareQQCustomQQ单独分享setGeneral单独分享(可以设置单独某个平台)授权(auth)void authToWechat(BuildContext context) {

SharesdkPlugin.auth(
    ShareSDKPlatforms.wechatSession, null, (SSDKResponseState state,
    Map user, SSDKError error) {
  showAlert(state, user != null ? user : error.rawData, context);
});

}
获取用户信息(getUserInfo)void getUserInfoToWechat(BuildContext context) {

SharesdkPlugin.getUserInfo(
    ShareSDKPlatforms.wechatSession, (SSDKResponseState state,
    Map user, SSDKError error) {
  showAlert(state, user != null ? user : error.rawData, context);
});

}
ShareSDKPlatforms.wechatSession这里以微信平台授权作为示例。调用九宫格分享(showMenu)setGeneral内的方法顺序及说明:title标题(String)text文本(String)images图片数组iOS使用(dynamic)imageUrlAndroidurl图片地址(String)imagePathAndroid本地图片路径(String)urlurl地址(String)titleUrlAndroid标题url地址(String)musicUrlAndroid音乐url地址(String)videoUrlAndroid视频url地址(String)filePath文件地址(String)SSDKContentType contentType分享类型SSDKMap params = SSDKMap()

  ..setGeneral(
      "title",
      "text",
      ["http://wx3.sinaimg.cn/large/006nLajtly1fpi9ikmj1kj30dw0dwwfq.jpg"],
      "http://wx3.sinaimg.cn/large/006nLajtly1fpi9ikmj1kj30dw0dwwfq.jpg",
      "",
      "http://www.mob.com/",
      "http://wx4.sinaimg.cn/large/006WfoFPly1fw9612f17sj30dw0dwgnd.jpg",
      "http://i.y.qq.com/v8/playsong.html?hostuin=0&songid=&songmid=002x5Jje3eUkXT&_wv=1&source=qq&appshare=iphone&media_mid=002x5Jje3eUkXT",
      "http://f1.webshare.mob.com/dvideo/demovideos.mp4",
      "",
      SSDKContentTypes.webpage);
SharesdkPlugin.showMenu(null, null, params, (SSDKResponseState state,
    ShareSDKPlatform platform,
    dynamic userData,
    dynamic contentEntity,
    SSDKError error) {
  showAlert(state, error.rawData, context);
});

单独分享第三方平台(share)如下所示,替换share方法内ShareSDKPlatforms.wechatSession第三方平台名称,即可单独分享不同的平台;具体第三方平台名称可以参考如下;//单独公共分享
SSDKMap params = SSDKMap()

  ..setGeneral(
      "h5.yoto.fun",
      "text",
      [
        "http://pic28.photophoto.cn/20130818/0020033143720852_b.jpg"
      ],
      "",
      "",
      "http://mob.com",
      "",
      "",
      "",
      "",
      SSDKContentTypes.image);

SharesdkPlugin.share(ShareSDKPlatforms.wechatSession, params,
    (SSDKResponseState state, dynamic userdata, dynamic contentEntity,
        SSDKError error) {
  showAlert(state, error.rawData, context);
});

单独分享QQ不需要的参数传null即可setQQtitle标题(String)text文本(String)urlurl地址(String)audio音频(String)video视频(String)musicUrlAndroid音乐url地址(String)videoUrlAndroid视频url地址(String)thumbImage缩略图(String)images图片数组iOS使用imageUrlAndroidurl图片地址(String)imagePathAndroid本地图片路径(String)titleUrlAndroid标题url地址(String)siteAndroidandroid使用(String)siteUrlAndroidandroid使用(String)SSDKContentType contentType分享类型0:auto(自动)1:text(文本)2:image(图像)3:webpage(网页)4:app(APP)5:audio(音频)6:video(视频)7:file(文件)10:miniProgram(小程序)ShareSDKPlatform subPlatform分享平台SSDKMap params = SSDKMap()

  ..setQQ(
      "text",
      "title",
      "http://m.93lj.com/sharelink?mobid=ziqMNf",
      "",
      "",
      "",
      "",
      "",
      "http://wx4.sinaimg.cn/large/006tkBCzly1fy8hfqdoy6j30dw0dw759.jpg",
      "",
      "",
      "http://m.93lj.com/sharelink?mobid=ziqMNf",
      "",
      "",
      SSDKContentTypes.webpage,
      ShareSDKPlatforms.qq);
SharesdkPlugin.share(ShareSDKPlatforms.qq, params, (SSDKResponseState state,
    dynamic userdata, dynamic contentEntity, SSDKError error) {
  showAlert(state, error.rawData, context);
});

单独分享微博setSinatext文本(String)title标题(String)images图片数组iOS使用videoiOS专用(String)url链接(String)latitude纬度 (double)longitude维度(double)objectId父类型 ID (String)isStoryiOS专用 ID (String)image_url图片链接地址 (String)image_path图片路径地址 (String)SSDKContentType type分享类型0:auto(自动)1:text(文本)2:image(图像)3:webpage(网页)4:app(APP)5:audio(音频)6:video(视频)7:file(文件)10:miniProgram(小程序)SSDKMap params = SSDKMap()

  ..setSina(
      "text",
      "title",
      [
        "http://download.sdk.mob.com/web/images/2019/07/30/14/1564468183056/750_750_65.12.png"
      ],
      "",
      "http://www.mob.com/",
      0.0,
      0.0,
      "",
      false,
      "http://wx4.sinaimg.cn/large/006WfoFPly1fq0jo9svnaj30dw0dwdhv.jpg",
      "",
      SSDKContentTypes.auto);
SharesdkPlugin.share(ShareSDKPlatforms.sina, params,
    (SSDKResponseState state, dynamic userdata, dynamic contentEntity,
        SSDKError error) {
  showAlert(state, error.rawData, context);
});

微博分享卡片模式setSinaLinkCardlinkcard类型如下参数,都不能为空text文本(String)title标题(String)url链接(String)sina_summary分享综括(String)image_url图片链接地址(String)imageX图片宽(String)imageY图片高(String)SSDKMap params = SSDKMap()

  ..setSinaLinkCard(
      "linkcard_text",
      "linkcard_title",
      "http://www.mob.com/",
      "全新品牌,优质服务",
      "http://wx4.sinaimg.cn/large/006WfoFPly1fq0jo9svnaj30dw0dwdhv.jpg",
      "120",
      "120");
SharesdkPlugin.share(ShareSDKPlatforms.sina, params,
    (SSDKResponseState state, dynamic userdata, dynamic contentEntity,
        SSDKError error) {
  showAlert(state, error.rawData, context);
});

单独分享推特text文本(String)Images图片数组video视频(String)latitude分享综括(double)longitude图片链接地址(double)SSDKContentType type分享类型单独分享facebooktext文本(String)Images图片数组url链接地址(String)urlTitle标题链接地址(String)urlName名称链接地址(String)attachementUrl附加链接地址(String)hasTag标签(String)quote引用(String)SSDKContentType type分享类型分享小程序参数setWeChatMiniProgramtitle标题(String)desc描述(String)webUrlweb地址(String)path小程序页面路径(String)thumbImage缩略图(String)hdThumbImage高清缩略图(String)imageUrlAndroid图片Url地址(String)userName小程序原始ID(String)withShareTicket分享标签(bool)miniProgramType小程序类型(int)ShareSDKPlatform subPlatform分享平台分享到微信setWechattext文本(String)title标题(String)url链接(String)thumbImage缩略图(String)images图片数组ios使用musicFileURL音乐文件url地址(String)extInfo附加信息(String)imageUrl图片链接(String)fileData文件流(String)emoticonData表情流(String)fileExtension文件扩展(String)sourceFileData源文件流(String)SSDKContentType contentType分享类型ShareSDKPlatform subPlatform分享平台分享到绿洲setOasistext文本(String)title标题(String)assetLoacallds相册地址(List)image图片链接或图片数组(List或String)video视频地址(String)fileExtension视频格式(String)type分享类型(只支持image或video)SSDKContentTypeShareSDKPlatform subPlatform分享平台SSDKMap params = SSDKMap()

  ..setOasis(
      "title",
      "text",
      null,
      "http://wx4.sinaimg.cn/large/006tkBCzly1fy8hfqdoy6j30dw0dw759.jpg",
      "",
      "",
      SSDKContentTypes.image);

SharesdkPlugin.share(ShareSDKPlatforms.oasis, params,
    (SSDKResponseState state, dynamic userdata, dynamic contentEntity,
        SSDKError error) {
  showAlert(state, error.rawData, context);
});

新增对原生FacebookSDK 的支持(SSDKFacebookShareType)新增跳转到原生分享和在app内分享native跳转到原生分享sheetapp内分享class SSDKFacebookShareTypes extends Object {
static SSDKFacebookShareType get native => SSDKFacebookShareType(value: 1);
static SSDKFacebookShareType get sheet => SSDKFacebookShareType(value: 2);
}


中关村科金
136 声望13 粉丝

北京中关村科金技术有限公司(简称“中关村科金”)是国内领先的对话式AI技术解决方案提供商,成立于2014年,注册资本14亿元,总部位于北京,在上海、重庆、深圳、杭州、成都等地设有分支机构,公司规模近千人,其...