tencent_kit 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

tencent_kit #

Build Status Codecov GitHub Tag Pub Package License

flutter版腾讯(QQ)SDK

flutter toolkit #

dart/flutter 私服 #

docs #

android #

...
android {
    ...
    defaultConfig{
        ...
        manifestPlaceholders = [TENCENT_APP_ID: "${appId}"]
        ...
    }
    ...
}
...
# 混淆已打入 Library,随 Library 引用,自动添加到 apk 打包混淆
<!-- 腾讯有毒吧,文档都不写,SDK里居然写死 android:authorities 为 com.tencent.tauth.fileprovider,而非不同应用不同 android:authorities -->
<manifest>
    <!-- targetSdkVersion >= 29, 豁免 Android Q 的外部存储沙箱限制 -->
    <application android:requestLegacyExternalStorage="true">
    </application>
</manifest>

ios #

在Xcode中,选择你的工程设置项,选中“TARGETS”一栏,在“info”标签栏的“URL type“添加“URL scheme”为你所注册的应用程序id

URL Types
tencent: identifier=tencent schemes=tencent${appId}
iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装。

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>wtloginmqq2</string>
    <string>mqqopensdkapiV3</string>
    <string>mqqwpa</string>
    <string>mqqopensdkapiV2</string>
    <string>mqqOpensdkSSoLogin</string>
    <string>mqq</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
Universal Links

Capabilities -> Associated Domain -> Domain -> applinks:${your applinks}

flutter #

分享类型说说(图/文/视频)文本图片音乐视频网页
QQ不支持不支持支持支持不支持支持
QZone支持不支持不支持不支持不支持支持
  • snapshot
dependencies:
  tencent_kit:
    git:
      url: https://github.com/v7lin/fake_tencent.git
  • release
dependencies:
  tencent_kit: ^${latestTag}
  • example

示例

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

1.0.4 - 2019.12.16 #

  • 适配 Android Q 本地分享适配(别问为什么,腾讯有毒!)

1.0.3 - 2019.12.05 #

  • 升级 Android SDK
  • 适配 Android Q 本地分享(targetSdkVersion >= 29,且不豁免外部存储沙箱限制)

1.0.2 - 2019.12.02 #

  • 优化
  • Objective-C 代码格式化

1.0.1 - 2019.11.26 #

  • 优化

1.0.0 - 2019.11.14 #

  • 更名 tencent_kit
  • 升级 Android/iOS SDK
  • 添加 Android 代码静态检查
  • 获取用户信息改走API接口
  • 新增获取UnionId功能

0.3.4 - 2019.9.10 #

  • gradle兼容

0.3.3 - 2019.7.12 #

  • 简化

0.3.2 - 2019.6.18 #

  • AndroidX兼容

0.3.1 - 2019.6.12 #

  • 修正网页分享无描述

0.3.0 - 2019.5.24 #

  • 优化
  • 自动化发布

0.2.0 - 2019.3.26 #

  • 不再自动设置 AccessToken

0.1.0 - 2019.3.19 #

  • 规范 fake_tencent 代码

0.0.1 - 2019.3.1 #

  • android/ios tencent

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:okhttp_kit/okhttp_kit.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart' as path_provider;
import 'package:tencent_kit/tencent_kit.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> {
  static const String _TENCENT_APPID = '222222';

  Tencent _tencent = Tencent()..registerApp(appId: _TENCENT_APPID);

  StreamSubscription<TencentLoginResp> _login;
  StreamSubscription<TencentShareResp> _share;

  TencentLoginResp _loginResp;

  @override
  void initState() {
    super.initState();
    _login = _tencent.loginResp().listen(_listenLogin);
    _share = _tencent.shareResp().listen(_listenShare);
  }

  void _listenLogin(TencentLoginResp resp) {
    _loginResp = resp;
    String content = 'login: ${resp.openid} - ${resp.accessToken}';
    _showTips('登录', content);
  }

  void _listenShare(TencentShareResp resp) {
    String content = 'share: ${resp.ret} - ${resp.msg}';
    _showTips('分享', content);
  }

  @override
  void dispose() {
    if (_login != null) {
      _login.cancel();
    }
    if (_share != null) {
      _share.cancel();
    }
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('TencentKit Demo'),
      ),
      body: ListView(
        children: <Widget>[
          ListTile(
            title: const Text('环境检查'),
            onTap: () async {
              String content = 'tencent: ${await _tencent.isInstalled()}';
              _showTips('环境检查', content);
            },
          ),
          ListTile(
            title: const Text('登录'),
            onTap: () {
              _tencent.login(
                scope: [TencentScope.GET_SIMPLE_USERINFO],
              );
            },
          ),
          ListTile(
            title: const Text('获取用户信息'),
            onTap: () async {
              if (_loginResp != null &&
                  _loginResp.isSuccessful() &&
                  !_loginResp.isExpired()) {
                TencentUserInfoResp userInfo = await _tencent.getUserInfo(
                  appId: _TENCENT_APPID,
                  openid: _loginResp.openid,
                  accessToken: _loginResp.accessToken,
                );
                if (userInfo.isSuccessful()) {
                  _showTips('用户信息',
                      '${userInfo.nickname} - ${userInfo.gender} - ${userInfo.genderType}');
                } else {
                  _showTips('用户信息', '${userInfo.ret} - ${userInfo.msg}');
                }
              }
            },
          ),
          ListTile(
            title: const Text('获取UnionID'),
            onTap: () async {
              if (_loginResp != null &&
                  _loginResp.isSuccessful() &&
                  !_loginResp.isExpired()) {
                TencentUnionidResp unionid = await _tencent.getUnionId(
                  accessToken: _loginResp.accessToken,
                );
                if (unionid.isSuccessful()) {
                  _showTips('UnionID',
                      '${unionid.clientId} - ${unionid.openid} - ${unionid.unionid}');
                } else {
                  _showTips('UnionID',
                      '${unionid.error} - ${unionid.errorDescription}');
                }
              }
            },
          ),
          ListTile(
            title: const Text('分享文字'),
            onTap: () {
              _tencent.shareMood(
                scene: TencentScene.SCENE_QZONE,
                summary: '分享测试',
              );
            },
          ),
          ListTile(
            title: const Text('图片分享'),
            onTap: () async {
              OkHttpClient client = OkHttpClientBuilder().build();
              Response resp = await client
                  .newCall(RequestBuilder()
                      .get()
                      .url(HttpUrl.parse(
                          'https://www.baidu.com/img/bd_logo1.png?where=super'))
                      .build())
                  .enqueue();
              if (resp.isSuccessful()) {
                Directory saveDir = Platform.isIOS
                    ? await path_provider.getApplicationDocumentsDirectory()
                    : await path_provider.getExternalStorageDirectory();
                File saveFile = File(path.join(saveDir.path, 'timg.png'));
                if (!saveFile.existsSync()) {
                  saveFile.createSync(recursive: true);
                  saveFile.writeAsBytesSync(
                    await resp.body().bytes(),
                    flush: true,
                  );
                }
                await _tencent.shareImage(
                  scene: TencentScene.SCENE_QQ,
                  imageUri: Uri.file(saveFile.path),
                );
              }
            },
          ),
          ListTile(
            title: const Text('分享链接'),
            onTap: () {
              _tencent.shareWebpage(
                scene: TencentScene.SCENE_QQ,
                title: 'title',
                targetUrl: 'https://www.baidu.com/',
              );
            },
          ),
        ],
      ),
    );
  }

  void _showTips(String title, String content) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text(title),
          content: Text(content),
        );
      },
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  tencent_kit: ^1.0.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:tencent_kit/tencent_kit.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.7
  • Flutter: 1.12.13+hotfix.9

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
json_annotation >=2.0.0 <4.0.0 3.0.1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
build_runner any
flutter_test
json_serializable any
okhttp_kit ^1.0.0
path ^1.6.4
path_provider ^1.4.0
pedantic any