mirror of
https://github.com/RxReader/wechat_kit.git
synced 2025-05-19 16:26:06 +08:00
整理
This commit is contained in:
@ -9,7 +9,6 @@ import android.content.pm.ProviderInfo;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import com.tencent.mm.opensdk.constants.Build;
|
||||
|
92
lib/src/model/qrauth.dart
Executable file
92
lib/src/model/qrauth.dart
Executable file
@ -0,0 +1,92 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'qrauth.g.dart';
|
||||
|
||||
abstract class QrauthResp {
|
||||
const QrauthResp();
|
||||
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
@override
|
||||
String toString() => const JsonEncoder.withIndent(' ').convert(toJson());
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class GotQrcodeResp extends QrauthResp {
|
||||
const GotQrcodeResp({
|
||||
required this.imageData,
|
||||
}) : super();
|
||||
|
||||
factory GotQrcodeResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$GotQrcodeRespFromJson(json);
|
||||
|
||||
@JsonKey(fromJson: _byteArrayFromJson)
|
||||
final Uint8List imageData;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$GotQrcodeRespToJson(this);
|
||||
|
||||
static Uint8List _byteArrayFromJson(Object? json) {
|
||||
return json! as Uint8List;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class QrcodeScannedResp extends QrauthResp {
|
||||
const QrcodeScannedResp();
|
||||
|
||||
factory QrcodeScannedResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$QrcodeScannedRespFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$QrcodeScannedRespToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class FinishResp extends QrauthResp {
|
||||
const FinishResp({
|
||||
required this.errorCode,
|
||||
this.authCode,
|
||||
}) : super();
|
||||
|
||||
factory FinishResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$FinishRespFromJson(json);
|
||||
|
||||
/// Auth成功
|
||||
static const int ERRORCODE_OK = 0;
|
||||
|
||||
/// 普通错误
|
||||
static const int ERRORCODE_NORMAL = -1;
|
||||
|
||||
/// 网络错误
|
||||
static const int ERRORCODE_NETWORK = -2;
|
||||
|
||||
/// 获取二维码失败
|
||||
static const int ERRORCODE_GETQRCODEFAILED = -3;
|
||||
|
||||
/// 用户取消授权
|
||||
static const int ERRORCODE_CANCEL = -4;
|
||||
|
||||
/// 超时
|
||||
static const int ERRORCODE_TIMEOUT = -5;
|
||||
|
||||
@JsonKey(defaultValue: ERRORCODE_OK)
|
||||
final int errorCode;
|
||||
final String? authCode;
|
||||
|
||||
bool get isSuccessful => errorCode == ERRORCODE_OK;
|
||||
|
||||
bool get isCancelled => errorCode == ERRORCODE_CANCEL;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$FinishRespToJson(this);
|
||||
}
|
38
lib/src/model/qrauth.g.dart
Normal file
38
lib/src/model/qrauth.g.dart
Normal file
@ -0,0 +1,38 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'qrauth.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GotQrcodeResp _$GotQrcodeRespFromJson(Map<String, dynamic> json) {
|
||||
return GotQrcodeResp(
|
||||
imageData: GotQrcodeResp._byteArrayFromJson(json['imageData']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GotQrcodeRespToJson(GotQrcodeResp instance) =>
|
||||
<String, dynamic>{
|
||||
'imageData': instance.imageData,
|
||||
};
|
||||
|
||||
QrcodeScannedResp _$QrcodeScannedRespFromJson(Map<String, dynamic> json) {
|
||||
return QrcodeScannedResp();
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$QrcodeScannedRespToJson(QrcodeScannedResp instance) =>
|
||||
<String, dynamic>{};
|
||||
|
||||
FinishResp _$FinishRespFromJson(Map<String, dynamic> json) {
|
||||
return FinishResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
authCode: json['authCode'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$FinishRespToJson(FinishResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'authCode': instance.authCode,
|
||||
};
|
@ -1,49 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'qrauth_resp.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class QrauthResp {
|
||||
const QrauthResp({
|
||||
required this.errorCode,
|
||||
this.authCode,
|
||||
});
|
||||
|
||||
factory QrauthResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$QrauthRespFromJson(json);
|
||||
|
||||
/// Auth成功
|
||||
static const int ERRORCODE_OK = 0;
|
||||
|
||||
/// 普通错误
|
||||
static const int ERRORCODE_NORMAL = -1;
|
||||
|
||||
/// 网络错误
|
||||
static const int ERRORCODE_NETWORK = -2;
|
||||
|
||||
/// 获取二维码失败
|
||||
static const int ERRORCODE_GETQRCODEFAILED = -3;
|
||||
|
||||
/// 用户取消授权
|
||||
static const int ERRORCODE_CANCEL = -4;
|
||||
|
||||
/// 超时
|
||||
static const int ERRORCODE_TIMEOUT = -5;
|
||||
|
||||
@JsonKey(defaultValue: ERRORCODE_OK)
|
||||
final int errorCode;
|
||||
final String? authCode;
|
||||
|
||||
bool get isSuccessful => errorCode == ERRORCODE_OK;
|
||||
|
||||
bool get isCancelled => errorCode == ERRORCODE_CANCEL;
|
||||
|
||||
Map<String, dynamic> toJson() => _$QrauthRespToJson(this);
|
||||
|
||||
@override
|
||||
String toString() => const JsonEncoder.withIndent(' ').convert(toJson());
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'qrauth_resp.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
QrauthResp _$QrauthRespFromJson(Map<String, dynamic> json) {
|
||||
return QrauthResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
authCode: json['authCode'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$QrauthRespToJson(QrauthResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'authCode': instance.authCode,
|
||||
};
|
66
lib/src/model/req.dart
Normal file
66
lib/src/model/req.dart
Normal file
@ -0,0 +1,66 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'req.g.dart';
|
||||
|
||||
abstract class BaseReq {
|
||||
const BaseReq({
|
||||
required this.openId,
|
||||
});
|
||||
|
||||
final String openId;
|
||||
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
@override
|
||||
String toString() => const JsonEncoder.withIndent(' ').convert(toJson());
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class LaunchFromWXReq extends BaseReq {
|
||||
const LaunchFromWXReq({
|
||||
required String openId,
|
||||
this.messageAction,
|
||||
this.messageExt,
|
||||
required this.lang,
|
||||
required this.country,
|
||||
}) : super(openId: openId);
|
||||
|
||||
factory LaunchFromWXReq.fromJson(Map<String, dynamic> json) =>
|
||||
_$LaunchFromWXReqFromJson(json);
|
||||
|
||||
final String? messageAction;
|
||||
final String? messageExt;
|
||||
final String lang;
|
||||
final String country;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$LaunchFromWXReqToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class ShowMessageFromWXReq extends BaseReq {
|
||||
const ShowMessageFromWXReq({
|
||||
required String openId,
|
||||
this.messageAction,
|
||||
this.messageExt,
|
||||
required this.lang,
|
||||
required this.country,
|
||||
}) : super(openId: openId);
|
||||
|
||||
factory ShowMessageFromWXReq.fromJson(Map<String, dynamic> json) =>
|
||||
_$ShowMessageFromWXReqFromJson(json);
|
||||
|
||||
final String? messageAction;
|
||||
final String? messageExt;
|
||||
final String lang;
|
||||
final String country;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$ShowMessageFromWXReqToJson(this);
|
||||
}
|
46
lib/src/model/req.g.dart
Normal file
46
lib/src/model/req.g.dart
Normal file
@ -0,0 +1,46 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'req.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
LaunchFromWXReq _$LaunchFromWXReqFromJson(Map<String, dynamic> json) {
|
||||
return LaunchFromWXReq(
|
||||
openId: json['openId'] as String,
|
||||
messageAction: json['messageAction'] as String?,
|
||||
messageExt: json['messageExt'] as String?,
|
||||
lang: json['lang'] as String,
|
||||
country: json['country'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$LaunchFromWXReqToJson(LaunchFromWXReq instance) =>
|
||||
<String, dynamic>{
|
||||
'openId': instance.openId,
|
||||
'messageAction': instance.messageAction,
|
||||
'messageExt': instance.messageExt,
|
||||
'lang': instance.lang,
|
||||
'country': instance.country,
|
||||
};
|
||||
|
||||
ShowMessageFromWXReq _$ShowMessageFromWXReqFromJson(Map<String, dynamic> json) {
|
||||
return ShowMessageFromWXReq(
|
||||
openId: json['openId'] as String,
|
||||
messageAction: json['messageAction'] as String?,
|
||||
messageExt: json['messageExt'] as String?,
|
||||
lang: json['lang'] as String,
|
||||
country: json['country'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$ShowMessageFromWXReqToJson(
|
||||
ShowMessageFromWXReq instance) =>
|
||||
<String, dynamic>{
|
||||
'openId': instance.openId,
|
||||
'messageAction': instance.messageAction,
|
||||
'messageExt': instance.messageExt,
|
||||
'lang': instance.lang,
|
||||
'country': instance.country,
|
||||
};
|
205
lib/src/model/resp.dart
Executable file
205
lib/src/model/resp.dart
Executable file
@ -0,0 +1,205 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'resp.g.dart';
|
||||
|
||||
abstract class BaseResp {
|
||||
const BaseResp({
|
||||
required this.errorCode,
|
||||
this.errorMsg,
|
||||
});
|
||||
|
||||
/// 成功
|
||||
static const int ERRORCODE_SUCCESS = 0;
|
||||
|
||||
/// 普通错误类型
|
||||
static const int ERRORCODE_COMMON = -1;
|
||||
|
||||
/// 用户点击取消并返回
|
||||
static const int ERRORCODE_USERCANCEL = -2;
|
||||
|
||||
/// 发送失败
|
||||
static const int ERRORCODE_SENTFAIL = -3;
|
||||
|
||||
/// 授权失败
|
||||
static const int ERRORCODE_AUTHDENY = -4;
|
||||
|
||||
/// 微信不支持
|
||||
static const int ERRORCODE_UNSUPPORT = -5;
|
||||
|
||||
/// 错误码
|
||||
@JsonKey(defaultValue: ERRORCODE_SUCCESS)
|
||||
final int errorCode;
|
||||
|
||||
/// 错误提示字符串
|
||||
final String? errorMsg;
|
||||
|
||||
bool get isSuccessful => errorCode == ERRORCODE_SUCCESS;
|
||||
|
||||
bool get isCancelled => errorCode == ERRORCODE_USERCANCEL;
|
||||
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
@override
|
||||
String toString() => const JsonEncoder.withIndent(' ').convert(toJson());
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class AuthResp extends BaseResp {
|
||||
const AuthResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
this.code,
|
||||
this.state,
|
||||
this.lang,
|
||||
this.country,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory AuthResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$AuthRespFromJson(json);
|
||||
|
||||
final String? code;
|
||||
final String? state;
|
||||
final String? lang;
|
||||
final String? country;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$AuthRespToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class OpenUrlResp extends BaseResp {
|
||||
const OpenUrlResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory OpenUrlResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$OpenUrlRespFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$OpenUrlRespToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class ShareMsgResp extends BaseResp {
|
||||
const ShareMsgResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory ShareMsgResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$ShareMsgRespFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$ShareMsgRespToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class SubscribeMsgResp extends BaseResp {
|
||||
const SubscribeMsgResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
this.templateId,
|
||||
this.scene,
|
||||
this.action,
|
||||
this.reserved,
|
||||
this.openId,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory SubscribeMsgResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$SubscribeMsgRespFromJson(json);
|
||||
|
||||
final String? templateId;
|
||||
final int? scene;
|
||||
final String? action;
|
||||
final String? reserved;
|
||||
final String? openId;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$SubscribeMsgRespToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class LaunchMiniProgramResp extends BaseResp {
|
||||
const LaunchMiniProgramResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
this.extMsg,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory LaunchMiniProgramResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$LaunchMiniProgramRespFromJson(json);
|
||||
|
||||
final String? extMsg;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$LaunchMiniProgramRespToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class OpenCustomerServiceChatResp extends BaseResp {
|
||||
const OpenCustomerServiceChatResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory OpenCustomerServiceChatResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$OpenCustomerServiceChatRespFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$OpenCustomerServiceChatRespToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class PayResp extends BaseResp {
|
||||
const PayResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
this.returnKey,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory PayResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$PayRespFromJson(json);
|
||||
|
||||
final String? returnKey;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$PayRespToJson(this);
|
||||
}
|
122
lib/src/model/resp.g.dart
Normal file
122
lib/src/model/resp.g.dart
Normal file
@ -0,0 +1,122 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'resp.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
AuthResp _$AuthRespFromJson(Map<String, dynamic> json) {
|
||||
return AuthResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
code: json['code'] as String?,
|
||||
state: json['state'] as String?,
|
||||
lang: json['lang'] as String?,
|
||||
country: json['country'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$AuthRespToJson(AuthResp instance) => <String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
'code': instance.code,
|
||||
'state': instance.state,
|
||||
'lang': instance.lang,
|
||||
'country': instance.country,
|
||||
};
|
||||
|
||||
OpenUrlResp _$OpenUrlRespFromJson(Map<String, dynamic> json) {
|
||||
return OpenUrlResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$OpenUrlRespToJson(OpenUrlResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
};
|
||||
|
||||
ShareMsgResp _$ShareMsgRespFromJson(Map<String, dynamic> json) {
|
||||
return ShareMsgResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$ShareMsgRespToJson(ShareMsgResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
};
|
||||
|
||||
SubscribeMsgResp _$SubscribeMsgRespFromJson(Map<String, dynamic> json) {
|
||||
return SubscribeMsgResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
templateId: json['templateId'] as String?,
|
||||
scene: json['scene'] as int?,
|
||||
action: json['action'] as String?,
|
||||
reserved: json['reserved'] as String?,
|
||||
openId: json['openId'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$SubscribeMsgRespToJson(SubscribeMsgResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
'templateId': instance.templateId,
|
||||
'scene': instance.scene,
|
||||
'action': instance.action,
|
||||
'reserved': instance.reserved,
|
||||
'openId': instance.openId,
|
||||
};
|
||||
|
||||
LaunchMiniProgramResp _$LaunchMiniProgramRespFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return LaunchMiniProgramResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
extMsg: json['extMsg'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$LaunchMiniProgramRespToJson(
|
||||
LaunchMiniProgramResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
'extMsg': instance.extMsg,
|
||||
};
|
||||
|
||||
OpenCustomerServiceChatResp _$OpenCustomerServiceChatRespFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return OpenCustomerServiceChatResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$OpenCustomerServiceChatRespToJson(
|
||||
OpenCustomerServiceChatResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
};
|
||||
|
||||
PayResp _$PayRespFromJson(Map<String, dynamic> json) {
|
||||
return PayResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
returnKey: json['returnKey'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$PayRespToJson(PayResp instance) => <String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
'returnKey': instance.returnKey,
|
||||
};
|
@ -1,33 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_sdk_resp.dart';
|
||||
|
||||
part 'wechat_auth_resp.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class WechatAuthResp extends WechatSdkResp {
|
||||
const WechatAuthResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
this.code,
|
||||
this.state,
|
||||
this.lang,
|
||||
this.country,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory WechatAuthResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$WechatAuthRespFromJson(json);
|
||||
|
||||
final String? code;
|
||||
final String? state;
|
||||
final String? lang;
|
||||
final String? country;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$WechatAuthRespToJson(this);
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'wechat_auth_resp.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
WechatAuthResp _$WechatAuthRespFromJson(Map<String, dynamic> json) {
|
||||
return WechatAuthResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
code: json['code'] as String?,
|
||||
state: json['state'] as String?,
|
||||
lang: json['lang'] as String?,
|
||||
country: json['country'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WechatAuthRespToJson(WechatAuthResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
'code': instance.code,
|
||||
'state': instance.state,
|
||||
'lang': instance.lang,
|
||||
'country': instance.country,
|
||||
};
|
@ -1,28 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_sdk_req.dart';
|
||||
|
||||
part 'wechat_launch_from_wx_req.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class WechatLaunchFromWXReq extends WechatSdkReq {
|
||||
const WechatLaunchFromWXReq({
|
||||
required String openId,
|
||||
this.messageAction,
|
||||
this.messageExt,
|
||||
required this.lang,
|
||||
required this.country,
|
||||
}) : super(openId: openId);
|
||||
|
||||
factory WechatLaunchFromWXReq.fromJson(Map<String, dynamic> json) =>
|
||||
_$WechatLaunchFromWXReqFromJson(json);
|
||||
|
||||
final String? messageAction;
|
||||
final String? messageExt;
|
||||
final String lang;
|
||||
final String country;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$WechatLaunchFromWXReqToJson(this);
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'wechat_launch_from_wx_req.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
WechatLaunchFromWXReq _$WechatLaunchFromWXReqFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return WechatLaunchFromWXReq(
|
||||
openId: json['openId'] as String,
|
||||
messageAction: json['messageAction'] as String?,
|
||||
messageExt: json['messageExt'] as String?,
|
||||
lang: json['lang'] as String,
|
||||
country: json['country'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WechatLaunchFromWXReqToJson(
|
||||
WechatLaunchFromWXReq instance) =>
|
||||
<String, dynamic>{
|
||||
'openId': instance.openId,
|
||||
'messageAction': instance.messageAction,
|
||||
'messageExt': instance.messageExt,
|
||||
'lang': instance.lang,
|
||||
'country': instance.country,
|
||||
};
|
@ -1,26 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_sdk_resp.dart';
|
||||
|
||||
part 'wechat_launch_mini_program_resp.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class WechatLaunchMiniProgramResp extends WechatSdkResp {
|
||||
const WechatLaunchMiniProgramResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
this.extMsg,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory WechatLaunchMiniProgramResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$WechatLaunchMiniProgramRespFromJson(json);
|
||||
|
||||
final String? extMsg;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$WechatLaunchMiniProgramRespToJson(this);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'wechat_launch_mini_program_resp.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
WechatLaunchMiniProgramResp _$WechatLaunchMiniProgramRespFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return WechatLaunchMiniProgramResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
extMsg: json['extMsg'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WechatLaunchMiniProgramRespToJson(
|
||||
WechatLaunchMiniProgramResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
'extMsg': instance.extMsg,
|
||||
};
|
@ -1,26 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_sdk_resp.dart';
|
||||
|
||||
part 'wechat_pay_resp.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class WechatPayResp extends WechatSdkResp {
|
||||
const WechatPayResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
this.returnKey,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory WechatPayResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$WechatPayRespFromJson(json);
|
||||
|
||||
final String? returnKey;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$WechatPayRespToJson(this);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'wechat_pay_resp.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
WechatPayResp _$WechatPayRespFromJson(Map<String, dynamic> json) {
|
||||
return WechatPayResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
returnKey: json['returnKey'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WechatPayRespToJson(WechatPayResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
'returnKey': instance.returnKey,
|
||||
};
|
@ -1,24 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'wechat_sdk_req.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class WechatSdkReq {
|
||||
const WechatSdkReq({
|
||||
required this.openId,
|
||||
});
|
||||
|
||||
factory WechatSdkReq.fromJson(Map<String, dynamic> json) =>
|
||||
_$WechatSdkReqFromJson(json);
|
||||
|
||||
final String openId;
|
||||
|
||||
Map<String, dynamic> toJson() => _$WechatSdkReqToJson(this);
|
||||
|
||||
@override
|
||||
String toString() => const JsonEncoder.withIndent(' ').convert(toJson());
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'wechat_sdk_req.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
WechatSdkReq _$WechatSdkReqFromJson(Map<String, dynamic> json) {
|
||||
return WechatSdkReq(
|
||||
openId: json['openId'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WechatSdkReqToJson(WechatSdkReq instance) =>
|
||||
<String, dynamic>{
|
||||
'openId': instance.openId,
|
||||
};
|
@ -1,52 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'wechat_sdk_resp.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class WechatSdkResp {
|
||||
const WechatSdkResp({
|
||||
required this.errorCode,
|
||||
this.errorMsg,
|
||||
});
|
||||
|
||||
factory WechatSdkResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$WechatSdkRespFromJson(json);
|
||||
|
||||
/// 成功
|
||||
static const int ERRORCODE_SUCCESS = 0;
|
||||
|
||||
/// 普通错误类型
|
||||
static const int ERRORCODE_COMMON = -1;
|
||||
|
||||
/// 用户点击取消并返回
|
||||
static const int ERRORCODE_USERCANCEL = -2;
|
||||
|
||||
/// 发送失败
|
||||
static const int ERRORCODE_SENTFAIL = -3;
|
||||
|
||||
/// 授权失败
|
||||
static const int ERRORCODE_AUTHDENY = -4;
|
||||
|
||||
/// 微信不支持
|
||||
static const int ERRORCODE_UNSUPPORT = -5;
|
||||
|
||||
/// 错误码
|
||||
@JsonKey(defaultValue: ERRORCODE_SUCCESS)
|
||||
final int errorCode;
|
||||
|
||||
/// 错误提示字符串
|
||||
final String? errorMsg;
|
||||
|
||||
bool get isSuccessful => errorCode == ERRORCODE_SUCCESS;
|
||||
|
||||
bool get isCancelled => errorCode == ERRORCODE_USERCANCEL;
|
||||
|
||||
Map<String, dynamic> toJson() => _$WechatSdkRespToJson(this);
|
||||
|
||||
@override
|
||||
String toString() => const JsonEncoder.withIndent(' ').convert(toJson());
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'wechat_sdk_resp.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
WechatSdkResp _$WechatSdkRespFromJson(Map<String, dynamic> json) {
|
||||
return WechatSdkResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WechatSdkRespToJson(WechatSdkResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
};
|
@ -1,28 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_sdk_req.dart';
|
||||
|
||||
part 'wechat_show_message_from_wx_req.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class WechatShowMessageFromWXReq extends WechatSdkReq {
|
||||
const WechatShowMessageFromWXReq({
|
||||
required String openId,
|
||||
this.messageAction,
|
||||
this.messageExt,
|
||||
required this.lang,
|
||||
required this.country,
|
||||
}) : super(openId: openId);
|
||||
|
||||
factory WechatShowMessageFromWXReq.fromJson(Map<String, dynamic> json) =>
|
||||
_$WechatShowMessageFromWXReqFromJson(json);
|
||||
|
||||
final String? messageAction;
|
||||
final String? messageExt;
|
||||
final String lang;
|
||||
final String country;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$WechatShowMessageFromWXReqToJson(this);
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'wechat_show_message_from_wx_req.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
WechatShowMessageFromWXReq _$WechatShowMessageFromWXReqFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return WechatShowMessageFromWXReq(
|
||||
openId: json['openId'] as String,
|
||||
messageAction: json['messageAction'] as String?,
|
||||
messageExt: json['messageExt'] as String?,
|
||||
lang: json['lang'] as String,
|
||||
country: json['country'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WechatShowMessageFromWXReqToJson(
|
||||
WechatShowMessageFromWXReq instance) =>
|
||||
<String, dynamic>{
|
||||
'openId': instance.openId,
|
||||
'messageAction': instance.messageAction,
|
||||
'messageExt': instance.messageExt,
|
||||
'lang': instance.lang,
|
||||
'country': instance.country,
|
||||
};
|
@ -1,34 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_sdk_resp.dart';
|
||||
|
||||
part 'wechat_subscribe_msg_resp.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
)
|
||||
class WechatSubscribeMsgResp extends WechatSdkResp {
|
||||
const WechatSubscribeMsgResp({
|
||||
required int errorCode,
|
||||
String? errorMsg,
|
||||
this.templateId,
|
||||
this.scene,
|
||||
this.action,
|
||||
this.reserved,
|
||||
this.openId,
|
||||
}) : super(
|
||||
errorCode: errorCode,
|
||||
errorMsg: errorMsg,
|
||||
);
|
||||
|
||||
factory WechatSubscribeMsgResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$WechatSubscribeMsgRespFromJson(json);
|
||||
|
||||
final String? templateId;
|
||||
final int? scene;
|
||||
final String? action;
|
||||
final String? reserved;
|
||||
final String? openId;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$WechatSubscribeMsgRespToJson(this);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'wechat_subscribe_msg_resp.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
WechatSubscribeMsgResp _$WechatSubscribeMsgRespFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return WechatSubscribeMsgResp(
|
||||
errorCode: json['errorCode'] as int? ?? 0,
|
||||
errorMsg: json['errorMsg'] as String?,
|
||||
templateId: json['templateId'] as String?,
|
||||
scene: json['scene'] as int?,
|
||||
action: json['action'] as String?,
|
||||
reserved: json['reserved'] as String?,
|
||||
openId: json['openId'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WechatSubscribeMsgRespToJson(
|
||||
WechatSubscribeMsgResp instance) =>
|
||||
<String, dynamic>{
|
||||
'errorCode': instance.errorCode,
|
||||
'errorMsg': instance.errorMsg,
|
||||
'templateId': instance.templateId,
|
||||
'scene': instance.scene,
|
||||
'action': instance.action,
|
||||
'reserved': instance.reserved,
|
||||
'openId': instance.openId,
|
||||
};
|
@ -6,13 +6,9 @@ import 'dart:typed_data';
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wechat_kit/src/model/qrauth/qrauth_resp.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_auth_resp.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_launch_from_wx_req.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_launch_mini_program_resp.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_pay_resp.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_sdk_resp.dart';
|
||||
import 'package:wechat_kit/src/model/sdk/wechat_subscribe_msg_resp.dart';
|
||||
import 'package:wechat_kit/src/model/qrauth.dart';
|
||||
import 'package:wechat_kit/src/model/req.dart';
|
||||
import 'package:wechat_kit/src/model/resp.dart';
|
||||
import 'package:wechat_kit/src/wechat_constant.dart';
|
||||
|
||||
///
|
||||
@ -48,6 +44,7 @@ class Wechat {
|
||||
'openCustomerServiceChat';
|
||||
static const String _METHOD_PAY = 'pay';
|
||||
static const String _METHOD_LAUNCHFROMWX = 'launchFromWX';
|
||||
static const String _METHOD_SHOWMESSAGEFROMWX = 'showMessageFromWX';
|
||||
|
||||
static const String _METHOD_ONAUTHRESP = 'onAuthResp';
|
||||
static const String _METHOD_ONOPENURLRESP = 'onOpenUrlResp';
|
||||
@ -100,55 +97,22 @@ class Wechat {
|
||||
static const String _ARGUMENT_KEY_CORPID = 'corpId';
|
||||
static const String _ARGUMENT_KEY_PARTNERID = 'partnerId';
|
||||
static const String _ARGUMENT_KEY_PREPAYID = 'prepayId';
|
||||
|
||||
// static const String _ARGUMENT_KEY_NONCESTR = 'noncestr';
|
||||
// static const String _ARGUMENT_KEY_TIMESTAMP = 'timestamp';
|
||||
static const String _ARGUMENT_KEY_PACKAGE = 'package';
|
||||
static const String _ARGUMENT_KEY_SIGN = 'sign';
|
||||
|
||||
static const String _ARGUMENT_KEY_RESULT_IMAGEDATA = 'imageData';
|
||||
|
||||
static const String _SCHEME_FILE = 'file';
|
||||
|
||||
late final MethodChannel _channel =
|
||||
const MethodChannel('v7lin.github.io/wechat_kit')
|
||||
..setMethodCallHandler(_handleMethod);
|
||||
|
||||
final StreamController<WechatLaunchFromWXReq>
|
||||
_launchFromWXReqStreamController =
|
||||
StreamController<WechatLaunchFromWXReq>.broadcast();
|
||||
final StreamController<BaseReq> _reqStreamController =
|
||||
StreamController<BaseReq>.broadcast();
|
||||
|
||||
final StreamController<WechatAuthResp> _authRespStreamController =
|
||||
StreamController<WechatAuthResp>.broadcast();
|
||||
final StreamController<BaseResp> _respStreamController =
|
||||
StreamController<BaseResp>.broadcast();
|
||||
|
||||
final StreamController<WechatSdkResp> _openUrlRespStreamController =
|
||||
StreamController<WechatSdkResp>.broadcast();
|
||||
|
||||
final StreamController<WechatSdkResp> _shareMsgRespStreamController =
|
||||
StreamController<WechatSdkResp>.broadcast();
|
||||
|
||||
final StreamController<WechatSubscribeMsgResp>
|
||||
_subscribeMsgRespStreamController =
|
||||
StreamController<WechatSubscribeMsgResp>.broadcast();
|
||||
|
||||
final StreamController<WechatLaunchMiniProgramResp>
|
||||
_launchMiniProgramRespStreamController =
|
||||
StreamController<WechatLaunchMiniProgramResp>.broadcast();
|
||||
|
||||
final StreamController<WechatSdkResp>
|
||||
_openCustomerServiceChatRespStreamController =
|
||||
StreamController<WechatSdkResp>.broadcast();
|
||||
|
||||
final StreamController<WechatPayResp> _payRespStreamController =
|
||||
StreamController<WechatPayResp>.broadcast();
|
||||
|
||||
final StreamController<Uint8List> _authGotQrcodeRespStreamController =
|
||||
StreamController<Uint8List>.broadcast();
|
||||
|
||||
final StreamController<String> _authQrcodeScannedRespStreamController =
|
||||
StreamController<String>.broadcast();
|
||||
|
||||
final StreamController<QrauthResp> _authFinishRespStreamController =
|
||||
final StreamController<QrauthResp> _qrauthStreamController =
|
||||
StreamController<QrauthResp>.broadcast();
|
||||
|
||||
/// 向微信注册应用
|
||||
@ -170,103 +134,70 @@ class Wechat {
|
||||
switch (call.method) {
|
||||
// onReq
|
||||
case _METHOD_LAUNCHFROMWX:
|
||||
_launchFromWXReqStreamController.add(WechatLaunchFromWXReq.fromJson(
|
||||
_reqStreamController.add(LaunchFromWXReq.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
case _METHOD_SHOWMESSAGEFROMWX:
|
||||
_reqStreamController.add(ShowMessageFromWXReq.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
// onResp
|
||||
case _METHOD_ONAUTHRESP:
|
||||
_authRespStreamController.add(WechatAuthResp.fromJson(
|
||||
_respStreamController.add(AuthResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
case _METHOD_ONOPENURLRESP:
|
||||
_openUrlRespStreamController.add(WechatSdkResp.fromJson(
|
||||
_respStreamController.add(OpenUrlResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
case _METHOD_ONSHAREMSGRESP:
|
||||
_shareMsgRespStreamController.add(WechatSdkResp.fromJson(
|
||||
_respStreamController.add(ShareMsgResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
case _METHOD_ONSUBSCRIBEMSGRESP:
|
||||
_subscribeMsgRespStreamController.add(WechatSubscribeMsgResp.fromJson(
|
||||
_respStreamController.add(SubscribeMsgResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
case _METHOD_ONLAUNCHMINIPROGRAMRESP:
|
||||
_launchMiniProgramRespStreamController.add(
|
||||
WechatLaunchMiniProgramResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>)
|
||||
.cast<String, dynamic>()));
|
||||
_respStreamController.add(LaunchMiniProgramResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
case _METHOD_ONOPENCUSTOMERSERVICECHATRESP:
|
||||
_openCustomerServiceChatRespStreamController.add(WechatSdkResp.fromJson(
|
||||
_respStreamController.add(OpenCustomerServiceChatResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
case _METHOD_ONPAYRESP:
|
||||
_payRespStreamController.add(WechatPayResp.fromJson(
|
||||
_respStreamController.add(PayResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
// Qrauth
|
||||
// onQrauth
|
||||
case _METHOD_ONAUTHGOTQRCODE:
|
||||
_authGotQrcodeRespStreamController
|
||||
.add(call.arguments[_ARGUMENT_KEY_RESULT_IMAGEDATA] as Uint8List);
|
||||
_qrauthStreamController.add(GotQrcodeResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
case _METHOD_ONAUTHQRCODESCANNED:
|
||||
_authQrcodeScannedRespStreamController.add('QrcodeScanned');
|
||||
_qrauthStreamController.add(const QrcodeScannedResp());
|
||||
break;
|
||||
case _METHOD_ONAUTHFINISH:
|
||||
_authFinishRespStreamController.add(QrauthResp.fromJson(
|
||||
_qrauthStreamController.add(FinishResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// 登录
|
||||
Stream<WechatAuthResp> authResp() {
|
||||
return _authRespStreamController.stream;
|
||||
///
|
||||
Stream<BaseReq> reqStream() {
|
||||
return _reqStreamController.stream;
|
||||
}
|
||||
|
||||
/// 打开浏览器
|
||||
Stream<WechatSdkResp> openUrlResp() {
|
||||
return _openUrlRespStreamController.stream;
|
||||
///
|
||||
Stream<BaseResp> respStream() {
|
||||
return _respStreamController.stream;
|
||||
}
|
||||
|
||||
/// 分享
|
||||
Stream<WechatSdkResp> shareMsgResp() {
|
||||
return _shareMsgRespStreamController.stream;
|
||||
}
|
||||
|
||||
/// 一次性订阅消息
|
||||
Stream<WechatSubscribeMsgResp> subscribeMsgResp() {
|
||||
return _subscribeMsgRespStreamController.stream;
|
||||
}
|
||||
|
||||
/// 打开小程序
|
||||
Stream<WechatLaunchMiniProgramResp> launchMiniProgramResp() {
|
||||
return _launchMiniProgramRespStreamController.stream;
|
||||
}
|
||||
|
||||
/// 打开微信客服
|
||||
Stream<WechatSdkResp> openCustomerServiceChatResp() {
|
||||
return _openCustomerServiceChatRespStreamController.stream;
|
||||
}
|
||||
|
||||
/// 支付
|
||||
Stream<WechatPayResp> payResp() {
|
||||
return _payRespStreamController.stream;
|
||||
}
|
||||
|
||||
/// 扫码登录 - 获取二维码
|
||||
Stream<Uint8List> authGotQrcodeResp() {
|
||||
return _authGotQrcodeRespStreamController.stream;
|
||||
}
|
||||
|
||||
/// 扫码登录 - 用户扫描二维码
|
||||
Stream<String> authQrcodeScannedResp() {
|
||||
return _authQrcodeScannedRespStreamController.stream;
|
||||
}
|
||||
|
||||
/// 扫码登录 - 用户点击授权
|
||||
Stream<QrauthResp> authFinishResp() {
|
||||
return _authFinishRespStreamController.stream;
|
||||
/// 扫码登录
|
||||
Stream<QrauthResp> authGotQrcodeResp() {
|
||||
return _qrauthStreamController.stream;
|
||||
}
|
||||
|
||||
/// 检测微信是否已安装
|
||||
|
@ -1,10 +1,7 @@
|
||||
library wechat_kit;
|
||||
|
||||
export 'src/model/qrauth/qrauth_resp.dart';
|
||||
export 'src/model/sdk/wechat_auth_resp.dart';
|
||||
export 'src/model/sdk/wechat_launch_mini_program_resp.dart';
|
||||
export 'src/model/sdk/wechat_pay_resp.dart';
|
||||
export 'src/model/sdk/wechat_sdk_resp.dart';
|
||||
export 'src/model/sdk/wechat_subscribe_msg_resp.dart';
|
||||
export 'src/model/qrauth.dart';
|
||||
export 'src/model/req.dart';
|
||||
export 'src/model/resp.dart';
|
||||
export 'src/wechat.dart';
|
||||
export 'src/wechat_constant.dart';
|
||||
|
@ -89,18 +89,20 @@ void main() {
|
||||
});
|
||||
|
||||
test('auth', () async {
|
||||
final StreamSubscription<WechatAuthResp> sub =
|
||||
Wechat.instance.authResp().listen((WechatAuthResp resp) {
|
||||
expect(resp.errorCode, WechatSdkResp.ERRORCODE_USERCANCEL);
|
||||
final StreamSubscription<BaseResp> sub =
|
||||
Wechat.instance.respStream().listen((BaseResp resp) {
|
||||
expect(resp.runtimeType, AuthResp);
|
||||
expect(resp.errorCode, BaseResp.ERRORCODE_USERCANCEL);
|
||||
});
|
||||
await Wechat.instance.auth(scope: <String>[WechatScope.SNSAPI_USERINFO]);
|
||||
await sub.cancel();
|
||||
});
|
||||
|
||||
test('share', () async {
|
||||
final StreamSubscription<WechatSdkResp> sub =
|
||||
Wechat.instance.shareMsgResp().listen((WechatSdkResp resp) {
|
||||
expect(resp.errorCode, WechatSdkResp.ERRORCODE_SUCCESS);
|
||||
final StreamSubscription<BaseResp> sub =
|
||||
Wechat.instance.respStream().listen((BaseResp resp) {
|
||||
expect(resp.runtimeType, ShareMsgResp);
|
||||
expect(resp.errorCode, BaseResp.ERRORCODE_SUCCESS);
|
||||
});
|
||||
await Wechat.instance
|
||||
.shareText(scene: WechatScene.SESSION, text: 'share text');
|
||||
@ -108,9 +110,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('pay', () async {
|
||||
final StreamSubscription<WechatPayResp> sub =
|
||||
Wechat.instance.payResp().listen((WechatPayResp resp) {
|
||||
expect(resp.errorCode, WechatSdkResp.ERRORCODE_USERCANCEL);
|
||||
final StreamSubscription<BaseResp> sub =
|
||||
Wechat.instance.respStream().listen((BaseResp resp) {
|
||||
expect(resp.runtimeType, PayResp);
|
||||
expect(resp.errorCode, BaseResp.ERRORCODE_USERCANCEL);
|
||||
});
|
||||
await Wechat.instance.pay(
|
||||
appId: 'mock',
|
||||
|
Reference in New Issue
Block a user