flutter_wx_message 0.0.38 copy "flutter_wx_message: ^0.0.38" to clipboard
flutter_wx_message: ^0.0.38 copied to clipboard

Flutter plugin for wechat,get contacts,get chat message.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_wx_message/flutter_wx_message.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  //  初始化插件
  final _wx = FlutterWxMessage();
  // demo
  String _platformVersion = 'Unknown';
  // 是否显示进度
  int _isShow = 0;
  int _rate = 0;
  String _tail = "";

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Map getOptions(){
    //获取通话记录和录音&&上传
    String _t = "5db2b9e8283b0c383768aadc.5b516f8793d1a8b2564633a7f56538d5"; //此处自行替换
    String env = "dev"; //此处自行替换(录音文件存储目录:prod:正式 test:测试 dev:开发)
    String identification = "27b5eaebf20d4777"; //此处自行替换
    Map map = {
      "_t": _t,
      // "domain": "http://192.168.110.14:9514",  //此处自行替换
      "domain": "https://dtms-h5.kyhgw.cn",
      //此处自行替换
      "endpoint": "https://oss-cn-beijing.aliyuncs.com",
      //oss区域对应域名(固定)
      "bucketName": "kingchem",
      //bucketName(固定)
      "identification": identification,
      //此处替换
      "stsServer": "/api/audio/securityToken",
      //获取oss鉴权信息(域名+接口地址+当前登录token)

      "time": 86400 * 4 * 1000,
      //通话录音-时间范围
      "dir": "dtms/" + env + "/audio/" + identification + "/",
      //通话录音-录音文件上传目录
      "uploadAlways": 0,
      //通话录音-(未实现)缓存是否已上传录音文件:0是,1不
      "logsPush": "/api/audio/logsPush",
      //通话录音-运行时日志推送
      "callSaveServer": "/mobile/call/saveLog",
      //通话录音-通话记录上传
      "audioStatusServer": "/mobile/call/noticeUpload",
      //通话录音-更新录音状态接口

      "wxContactsSave": "/api/wechat/wxContactsSave",
      //微信信息-好友同步接口
      "wxMessagesSave": "/api/wechat/wxMessagesSave",
      //微信信息-消息同步接口
      "wxRconversationSave": "/api/wechat/wxRconversationSave",
      //微信信息-会话同步接口
      "wxSyncCnfMy": "/api/wechat/wxSyncCnfMy",
      //微信信息-同步配置-我的
      "wxDir": 'dtms/$env/wx/',
      //微信信息-文件上传目录
      "wxBackupType": "ALL",
      //微信信息-备份类型(ALL全量 INCREMENT增量 *DAYS多少天[1DAYS、3DAYS、7DAYS、10DAYS])
      "wxBackupTime": 15,
      //微信信息-备份时间(等待备份后再运行)
      "wxWaitTime": 10,
      //微信信息-同步间隔(防止重复运行、每次循环休眠)
      "wxTimeout": 15,
      //微信信息-重试间隔(异常崩溃、无响应)
      "isSync": 1,
      //微信信息-是否同步(0否,1是)
      "wxMsgChatroom": 0,
      //微信信息-消息是否读取群消息(0否,1是)
      "wxMsgResourceUpload": 1,
      //微信信息-是否上传消息资源文件(0否,1是)
      "wxMsgSize": 1000,
      //微信信息-消息分页数
      "wxMsgPage": 1,
      //微信信息-获取数据初始页面
      "wxLoop": 500000,
      //微信信息-循环同步次数
    };
    return map;
  }

  // 启动微信数据获取
  Future<String> startWxTask() async{
    String platformVersion = 'Failed to get platform version.';
    try {
      platformVersion = await _wx.getPlatformVersion() ?? 'Unknown platform version';
      _wx.appTask(getOptions());
    } on PlatformException {}
    return platformVersion;
  }

  // 异步获取状态:微信数据获取
  Future<String> getStatusWxTask() async{
    String json = '{"isShow":0,"rate":0}';
    try {
      // 查询状态
      try {
        json = await _wx.getWxStatus(getOptions()) ?? json;
      } on PlatformException {}
    } on PlatformException {}
    return json;
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.

    // 启动微信数据获取
    String platformVersion = await startWxTask();

    // 定时器
    const timeout = const Duration(seconds: 3);
    int count = 0;
    int max = 10000;
    Timer.periodic(timeout, (timer) async {
      count++;
      // 异步获取状态:微信数据获取
      String json = await getStatusWxTask();
      Map data = jsonDecode(json);
      print("isShow:########################");
      print("res:flutter:json: "+json);
      // print(data['isShow']);
      // print(ps['rate']);
      // print(data['tail']);

      // 更新UI数据
      setState(() {
        _isShow = data['isShow'];
        _rate = data['rate'];
        _tail = data['tail'];
        // for()

        // _tail = data['tail'].toString();
      });
      if (count >= max) timer.cancel(); // 取消定时器
    });

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(

          child: Column(
            children: [
              Container(
                color: Color(0xffd5faf4),
                width: 380,
                height: 40,
                child: Text('Running on: $_platformVersion\n'),
              ),
              // 微信状态显示到页面
              if(_isShow>0) Container(
                child: Column(
                  children: [
                    Container(
                      margin: const EdgeInsets.only(top:10),
                      color: Colors.redAccent,
                      width: 380,
                      height: 10,
                      child: Row(
                        children: [
                          Container(width: 380*_rate/100, height: 10, color: Color(0xff00b2aa)),
                          Container(width: 380-380*_rate/100, height: 10, color: Color(0xffff671f))
                        ],
                      )
                    ),
                    Container(
                      color: Color(0xff8bdddd),
                      width: 380,
                      child: Text('进度:'+_rate.toString()+"%",style: TextStyle(color:Color(0xffffffff)),textAlign: TextAlign.center,    ),
                    ),
                    Container(
                      padding: EdgeInsets.all(10),
                      color: Color(0xffd5faf4),
                      width: 380,
                      height: 300,
                      child: Text(_tail,style: TextStyle(fontSize: 12),),
                    )
                  ],
                )
              )
              // 微信状态显示到页面
            ]
          )
          // child: Text('Running on: $_platformVersion\n'),
        //   child: new MaterialButton(
        //     color: Colors.blue,
        //     child: new Text('点我'),
        //     onPressed: () {
        //         showDialog<Null>(
        //             context: context,
        //             builder: (BuildContext context) {
        //                 return new SimpleDialog(
        //                     title: new Text('选择'),
        //                     children: <Widget>[
        //                         new SimpleDialogOption(
        //                             child: new Text('选项 1'),
        //                             onPressed: () {
        //                                 Navigator.of(context).pop();
        //                             },
        //                         ),
        //                         new SimpleDialogOption(
        //                             child: new Text('选项 2'),
        //                             onPressed: () {
        //                                 Navigator.of(context).pop();
        //                             },
        //                         ),
        //                     ],
        //                 );
        //             },
        //         ).then((val) {
        //             print(val);
        //         });
        //     },
        // ),
        ),
      ),
    );
  }
}
1
likes
0
points
34
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin for wechat,get contacts,get chat message.

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_wx_message

Packages that implement flutter_wx_message