Commit 8737ae5d authored by 李增强's avatar 李增强

Initial commit

parents
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: 1aafb3a8b9b0c36241c5f5b34ee914770f015818
channel: unknown
project_type: package
## [0.0.1] - TODO: Add release date.
* TODO: Describe initial release.
TODO: Add your license here.
# qm_tj
俏梦统计
## Getting Started
This project is a starting point for a Dart
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
library qm_tj;
import 'dart:convert';
import 'src/db.dart';
import 'src/http.dart';
import 'package:crypto/crypto.dart' as crypto;
class QMTJ {
static DB _db;
static String _appStartUpId;
static void init() async {
_appStartUpId = _md5(_getDateNow().toString());
_db = new DB();
await _db.init();
}
/// APP 启动
static void appStart({int source, Map<String, dynamic> extras}) async {
int type = 1;
int disappearTime = 0;
int appearTime = _getDateNow();
String id = _appStartUpId;
await _db.db.insert("app_tj", {
"id": id,
"type": type,
"source": source,
"disappear_time": disappearTime,
"appear_time": appearTime,
"extras": json.encode(extras),
});
}
/// APP 可见
static void appAppear({int source, Map<String, dynamic> extras}) async {
// APP进入前台,重新生成启动id
_appStartUpId = _md5(_getDateNow().toString());
int type = 2;
int disappearTime = 0;
int appearTime = _getDateNow();
String id = _appStartUpId;
await _db.db.insert("app_tj", {
"id": id,
"type": type,
"source": source,
"disappear_time": disappearTime,
"appear_time": appearTime,
"extras": json.encode(extras),
});
}
/// APP 不可见
static void appDisappear() {
_db.db.update("app_tj", {"disappear_time": _getDateNow()},
where: "id = ?", whereArgs: [_appStartUpId]);
}
/// PAGE 可见
static void pageAppear(
{int source,
String pageId,
String lastPageId,
Map<String, dynamic> extras}) async {
String extrasStr = json.encode(extras);
String id = _md5("${pageId}_${lastPageId}_$extrasStr");
int disappearTime = 0;
int appearTime = _getDateNow();
await _db.db.insert("page_tj", {
"id": id,
"source": source,
"page_id": pageId,
"last_page_id": lastPageId,
"appear_time": appearTime,
"disappear_time": disappearTime,
"extras": extrasStr,
});
}
/// PAGE 不可见
static void pageDisappear(
{String pageId, String lastPageId, Map<String, dynamic> extras}) async {
String extrasStr = json.encode(extras);
String id = _md5("${pageId}_${lastPageId}_$extrasStr");
await _db.db.update(
"page_tj",
{
"disappear_time": _getDateNow(),
},
where: "id = ? ",
whereArgs: [id]);
}
/// 点击
/// [pageId] 页面id
/// [clickId] 点击id
/// [extras] 点击参数
static void tap(
{int source,
String pageId,
String clickId,
Map<String, dynamic> extras}) async {
int clickTime = _getDateNow();
String extrasStr = json.encode(extras);
String id = _md5("${pageId}_${clickId}_${extrasStr}_${clickTime}");
await _db.db.insert("tap_tj", {
"id": id,
"source": source,
"page_id": pageId,
"click_id": clickId,
"click_time": clickTime,
"extras": extrasStr,
});
}
/// 曝光
/// [pageId] 页面id
/// [exposureId] 曝光id
/// [extras] 曝光参数
static void exposure(
{int source,
String pageId,
String exposureId,
Map<String, dynamic> extras}) async {
int exposureTime = _getDateNow();
String extrasStr = json.encode(extras);
String id = _md5("${pageId}_${exposureId}_${extrasStr}_${exposureTime}");
await _db.db.insert("exposure_tj", {
"id": id,
"source": source,
"page_id": pageId,
"exposure_id": exposureId,
"exposure_time": exposureTime,
"extras": extrasStr,
});
}
/// 获取当前时间戳,单位:秒
static int _getDateNow() {
int now = (DateTime.now().millisecondsSinceEpoch / 1000).floor();
return now;
}
// md5编码
static String _md5(String data) {
var bytes = utf8.encode(data);
var digest = crypto.md5.convert(bytes);
return digest.toString();
}
}
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
import 'sql.dart';
class DB {
int _version = 1;
Database db;
/// 打开数据库
Future init() async {
var databasesPath = await getDatabasesPath();
String path = join(
databasesPath,
'qm_tj.db',
);
db = await openDatabase(path, version: _version,
onCreate: (Database db, int version) async {
await db.execute(SQL_APP_TJ_TABLE);
await db.execute(SQL_PAGE_TJ_TABLE);
await db.execute(SQL_TAP_TJ_TABLE);
await db.execute(SQL_EXPOSURE_TJ_TABLE);
});
}
}
import 'dart:convert';
import 'dart:io';
/// http请求工具
class Http {
// http协议
String scheme;
// 请求ip域名
String host;
// 端口
int port;
HttpClient httpClient = new HttpClient();
Http({this.scheme, this.host, this.port});
/// 构建http post请求
Future<Map> post(String path, Map<String, dynamic> data) async {
// 构建uri
Uri uri =
Uri(scheme: this.scheme, host: this.host, port: this.port, path: path);
HttpClientRequest request = await httpClient.postUrl(uri);
request.headers.add("token", 'DB7837207BF1BD3BAFCEF02CC0B9C665');
// 添加post参数
request.add(utf8.encode(json.encode(data)));
// 发起请求
HttpClientResponse response = await request.close();
// 读取请求返回数据
String responseBody = await response.transform(utf8.decoder).join();
try {
// 数据转map格式
Map res = json.decode(responseBody);
return res;
} catch (e) {
return {};
}
}
}
//
// void main() async {
// int s = DateTime.now().millisecondsSinceEpoch;
// Http http = Http(scheme: "https", host: "klz.test.xiaomanxiong.cn");
// var a = await http.post("/api/V2.newyear/activity_rule", {});
// print(DateTime.now().millisecondsSinceEpoch - s);
// }
// app可见或者不可见, type 1 APP启动, 2 APP常规切换
String SQL_APP_TJ_TABLE = '''
CREATE TABLE app_tj (
id VARCHAR(32) ,
type TINYINT(4),
source INTEGER(10),
appear_time INTEGER(10),
disappear_time INTEGER(10),
extras VARCHAR(255),
PRIMARY KEY ("id")
)
''';
// 页面可见或者不可见
String SQL_PAGE_TJ_TABLE = '''
CREATE TABLE page_tj (
id VARCHAR(32) ,
source INTEGER(10),
page_id VARCHAR(255),
last_page_id VARCHAR(255),
appear_time INTEGER(10),
disappear_time INTEGER(10),
extras VARCHAR(255),
PRIMARY KEY ("id")
)
''';
// 点击
String SQL_TAP_TJ_TABLE = '''
CREATE TABLE tap_tj (
id VARCHAR(32) ,
source INTEGER(10),
page_id VARCHAR(255),
click_id VARCHAR(255),
click_time INTEGER(10),
extras VARCHAR(255),
PRIMARY KEY ("id")
)
''';
// 曝光
String SQL_EXPOSURE_TJ_TABLE = '''
CREATE TABLE exposure_tj (
id VARCHAR(32) ,
source INTEGER(10),
page_id VARCHAR(255),
exposure_id VARCHAR(255),
exposure_time INTEGER(10),
extras VARCHAR(255),
PRIMARY KEY ("id")
)
''';
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.5.0-nullsafety.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0-nullsafety.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0-nullsafety.3"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0-nullsafety.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.15.0-nullsafety.3"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.1"
crypto:
dependency: "direct main"
description:
name: crypto
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.4"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0-nullsafety.1"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.10-nullsafety.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0-nullsafety.3"
path:
dependency: "direct main"
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.0-nullsafety.1"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.0-nullsafety.2"
sqflite:
dependency: "direct main"
description:
name: sqflite
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.2+2"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.3"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0-nullsafety.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0-nullsafety.1"
synchronized:
dependency: transitive
description:
name: synchronized
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.0+2"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0-nullsafety.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.19-nullsafety.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0-nullsafety.3"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.10.2 <2.11.0"
flutter: ">=1.22.2 <2.0.0"
name: qm_tj
description: 俏梦统计
version: 0.0.1
author:
homepage:
environment:
sdk: ">=2.7.0 <3.0.0"
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
sqflite: ^1.3.2+2
path: ^1.6.4
crypto: 2.1.4
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment