“DaisyWu” 7f1642b09f 1,修复星锁点分享界面少了发送密码到、分享
2,修复星锁类型选择的文字,少了句号。系统短信多了那字,是软件里。
3,修复接收者少了通讯录的头像。及选择通讯录相关逻辑操作
4,修复建议限制50位。接收者如是汉字或位数不够,英文弹框,通通锁提示操作失败。
5,星星锁电子钥匙、密码模块发送成功后,发送短信、邮箱接入最新API,解决发送不成功问题
2024-07-08 18:18:20 +08:00

131 lines
4.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:io';
import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_entity.dart';
import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart';
import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/tools/baseGetXController.dart';
import 'package:star_lock/tools/commonDataManage.dart';
import 'package:url_launcher/url_launcher.dart';
class SendEmailNotificationLogic extends BaseGetXController {
final SendEmailNotificationState state = SendEmailNotificationState();
//获取电子钥匙通知模板 渠道1短信 2邮箱
Future<void> getKeyNoticeTemplate() async {
final SendEmailNotificationEntity entity;
if (state.unlockType.value == 1) {
entity = await ApiRepository.to.getKeyNoticeTemplate(
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0,
keyId: state.getKeyId.value,
channelType: state.channelType.value);
} else {
entity = await ApiRepository.to.getPwdNoticeTemplate(
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0,
keyboardPwdId: state.getKeyId.value,
channelType: state.channelType.value);
}
if (entity.errorCode!.codeIsSuccessful) {
state.emailTemplateList.value =
entity.data?.list ?? <EmailNotificationItem>[];
state.currentNotifyItem.value = state.emailTemplateList.first;
state.templateContentController.text =
state.currentNotifyItem.value.template ?? '';
state.emailTemplateList.refresh();
state.currentNotifyItem.refresh();
}
}
//发送短信、邮件通知 channelType--1短信 2邮件 opisAPKFileName
Future<void> keyNoticeSubmitRequest() async {
if (state.receiverController.text.isEmpty &&
state.getReceiver.value.isEmpty) {
showToast('请输入接收者');
return;
}
final SendEmailNotificationEntity entity;
if (state.unlockType.value == 1) {
entity = await ApiRepository.to.keyNoticeSubmit(
receiverName: state.getReceiver.value.isEmpty
? state.receiverController.text
: state.getReceiver.value,
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0,
keyId: state.getKeyId.value,
channelType: state.channelType.value,
openDoorType: state.unlockType.value,
templateType: state.currentNotifyItem.value.type ?? '',
countryCode: state.countryCode.value,
);
} else {
entity = await ApiRepository.to.pwdNoticeSubmit(
receiverName: state.getReceiver.value.isEmpty
? state.receiverController.text
: state.getReceiver.value,
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0,
keyboardPwdId: state.getKeyId.value,
channelType: state.channelType.value,
openDoorType: state.unlockType.value,
templateType: state.currentNotifyItem.value.type ?? '',
countryCode: state.countryCode.value,
);
}
if (entity.errorCode!.codeIsSuccessful) {
showToast('发送成功');
Get.back();
}
}
//发送邮件、短信
Future<void> sendPersonalSMSOrEmail() async {
if (state.receiverController.text.isEmpty &&
state.getReceiver.value.isEmpty) {
showToast('请输入接收者');
return;
}
if (state.channelType.value == 1) {
Uri smsUri;
//短信
final String phoneNumber = state.getReceiver.value.isEmpty
? state.receiverController.text
: state.getReceiver.value;
final String message = state.templateContentController.text;
if (Platform.isAndroid) {
smsUri = Uri(
scheme: 'sms',
path: phoneNumber,
query: 'body=${Uri.encodeComponent(message)}',
);
} else {
smsUri =
Uri.parse('sms:$phoneNumber&body=${Uri.encodeComponent(message)}');
}
if (await canLaunchUrl(smsUri)) {
await launchUrl(smsUri);
} else {
throw 'Could not launch $smsUri';
}
} else if (state.channelType.value == 2) {
//邮箱
final Uri emailUri = Uri(
scheme: 'mailto',
path: state.getReceiver.value.isEmpty
? state.receiverController.text
: state.getReceiver.value,
queryParameters: <String, String>{
'subject': state.currentNotifyItem.value.name ?? '',
'body': state.templateContentController.text,
},
);
if (await canLaunchUrl(emailUri)) {
await launchUrl(emailUri);
} else {
throw 'Could not launch $emailUri';
}
}
}
}