mirror of
https://github.com/RxReader/tencent_kit.git
synced 2025-06-20 18:57:11 +08:00
格式化
This commit is contained in:
@ -15,16 +15,22 @@ class TencentApi {
|
||||
required String openid,
|
||||
required String accessToken,
|
||||
}) {
|
||||
return HttpClient().getUrl(Uri.parse('https://graph.qq.com/user/get_user_info?access_token=$accessToken&oauth_consumer_key=$appId&openid=$openid')).then((HttpClientRequest request) {
|
||||
return HttpClient()
|
||||
.getUrl(Uri.parse(
|
||||
'https://graph.qq.com/user/get_user_info?access_token=$accessToken&oauth_consumer_key=$appId&openid=$openid'))
|
||||
.then((HttpClientRequest request) {
|
||||
return request.close();
|
||||
}).then((HttpClientResponse response) async {
|
||||
if (response.statusCode == HttpStatus.ok) {
|
||||
final ContentType? contentType = response.headers.contentType;
|
||||
final Encoding encoding = Encoding.getByName(contentType?.charset) ?? utf8;
|
||||
final Encoding encoding =
|
||||
Encoding.getByName(contentType?.charset) ?? utf8;
|
||||
final String content = await encoding.decodeStream(response);
|
||||
return TencentUserInfoResp.fromJson(json.decode(content) as Map<String, dynamic>);
|
||||
return TencentUserInfoResp.fromJson(
|
||||
json.decode(content) as Map<String, dynamic>);
|
||||
}
|
||||
throw HttpException('HttpResponse statusCode: ${response.statusCode}, reasonPhrase: ${response.reasonPhrase}.');
|
||||
throw HttpException(
|
||||
'HttpResponse statusCode: ${response.statusCode}, reasonPhrase: ${response.reasonPhrase}.');
|
||||
});
|
||||
}
|
||||
|
||||
@ -34,12 +40,16 @@ class TencentApi {
|
||||
required String accessToken,
|
||||
String unionid = '1',
|
||||
}) {
|
||||
return HttpClient().getUrl(Uri.parse('https://graph.qq.com/oauth2.0/me?access_token=$accessToken&unionid=$unionid')).then((HttpClientRequest request) {
|
||||
return HttpClient()
|
||||
.getUrl(Uri.parse(
|
||||
'https://graph.qq.com/oauth2.0/me?access_token=$accessToken&unionid=$unionid'))
|
||||
.then((HttpClientRequest request) {
|
||||
return request.close();
|
||||
}).then((HttpClientResponse response) async {
|
||||
if (response.statusCode == HttpStatus.ok) {
|
||||
final ContentType? contentType = response.headers.contentType;
|
||||
final Encoding encoding = Encoding.getByName(contentType?.charset) ?? utf8;
|
||||
final Encoding encoding =
|
||||
Encoding.getByName(contentType?.charset) ?? utf8;
|
||||
final String callback = await encoding.decodeStream(response);
|
||||
// 腾讯有毒 callback( $json );
|
||||
final RegExp exp = RegExp(r'callback\( (.*) \)\;');
|
||||
@ -47,11 +57,13 @@ class TencentApi {
|
||||
if (match?.groupCount == 1) {
|
||||
final String? content = match!.group(1);
|
||||
if (content != null) {
|
||||
return TencentUnionidResp.fromJson(json.decode(content) as Map<String, dynamic>);
|
||||
return TencentUnionidResp.fromJson(
|
||||
json.decode(content) as Map<String, dynamic>);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw HttpException('HttpResponse statusCode: ${response.statusCode}, reasonPhrase: ${response.reasonPhrase}.');
|
||||
throw HttpException(
|
||||
'HttpResponse statusCode: ${response.statusCode}, reasonPhrase: ${response.reasonPhrase}.');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,13 @@ class _HomeState extends State<Home> {
|
||||
),
|
||||
body: ListView(
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text('3.1.0 之后的版本请先获取权限'),
|
||||
onTap: () async {
|
||||
await Tencent.setIsPermissionGranted(granted: true);
|
||||
_showTips('授权', '已授权获取设备信息/同意隐私协议');
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text('注册APP'),
|
||||
onTap: () async {
|
||||
@ -80,17 +87,11 @@ class _HomeState extends State<Home> {
|
||||
ListTile(
|
||||
title: Text('环境检查'),
|
||||
onTap: () async {
|
||||
final String content = 'QQ install: ${await Tencent.isQQInstalled()}\nTIM install: ${await Tencent.isTIMInstalled()}';
|
||||
final String content =
|
||||
'QQ install: ${await Tencent.isQQInstalled()}\nTIM install: ${await Tencent.isTIMInstalled()}';
|
||||
_showTips('环境检查', content);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text('3.1.0 之后的版本请先获取权限'),
|
||||
onTap: () async {
|
||||
await Tencent.setIsPermissionGranted(granted: true);
|
||||
_showTips('授权', '已授权获取设备信息/同意隐私协议');
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text('登录'),
|
||||
onTap: () {
|
||||
@ -102,14 +103,17 @@ class _HomeState extends State<Home> {
|
||||
ListTile(
|
||||
title: Text('获取用户信息'),
|
||||
onTap: () async {
|
||||
if ((_loginResp?.isSuccessful ?? false) && !(_loginResp!.isExpired ?? true)) {
|
||||
final TencentUserInfoResp userInfo = await TencentApi.getUserInfo(
|
||||
if ((_loginResp?.isSuccessful ?? false) &&
|
||||
!(_loginResp!.isExpired ?? true)) {
|
||||
final TencentUserInfoResp userInfo =
|
||||
await TencentApi.getUserInfo(
|
||||
appId: _TENCENT_APPID,
|
||||
openid: _loginResp!.openid!,
|
||||
accessToken: _loginResp!.accessToken!,
|
||||
);
|
||||
if (userInfo.isSuccessful) {
|
||||
_showTips('用户信息', '${userInfo.nickname} - ${userInfo.gender} - ${userInfo.genderType}');
|
||||
_showTips('用户信息',
|
||||
'${userInfo.nickname} - ${userInfo.gender} - ${userInfo.genderType}');
|
||||
} else {
|
||||
_showTips('用户信息', '${userInfo.ret} - ${userInfo.msg}');
|
||||
}
|
||||
@ -119,14 +123,17 @@ class _HomeState extends State<Home> {
|
||||
ListTile(
|
||||
title: Text('获取UnionID'),
|
||||
onTap: () async {
|
||||
if ((_loginResp?.isSuccessful ?? false) && !(_loginResp!.isExpired ?? true)) {
|
||||
if ((_loginResp?.isSuccessful ?? false) &&
|
||||
!(_loginResp!.isExpired ?? true)) {
|
||||
final TencentUnionidResp unionid = await TencentApi.getUnionId(
|
||||
accessToken: _loginResp!.accessToken!,
|
||||
);
|
||||
if (unionid.isSuccessful) {
|
||||
_showTips('UnionID', '${unionid.clientId} - ${unionid.openid} - ${unionid.unionid}');
|
||||
_showTips('UnionID',
|
||||
'${unionid.clientId} - ${unionid.openid} - ${unionid.unionid}');
|
||||
} else {
|
||||
_showTips('UnionID', '${unionid.error} - ${unionid.errorDescription}');
|
||||
_showTips('UnionID',
|
||||
'${unionid.error} - ${unionid.errorDescription}');
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -152,7 +159,8 @@ class _HomeState extends State<Home> {
|
||||
ListTile(
|
||||
title: Text('图片分享'),
|
||||
onTap: () async {
|
||||
final File file = await DefaultCacheManager().getSingleFile('https://www.baidu.com/img/bd_logo1.png?where=super');
|
||||
final File file = await DefaultCacheManager().getSingleFile(
|
||||
'https://www.baidu.com/img/bd_logo1.png?where=super');
|
||||
await Tencent.shareImage(
|
||||
scene: TencentScene.SCENE_QQ,
|
||||
imageUri: Uri.file(file.path),
|
||||
|
Reference in New Issue
Block a user