Skip to content
Snippets Groups Projects

Verify OTP screen- FE -ECAP1-24

1 file
+ 25
37
Compare changes
  • Side-by-side
  • Inline
+ 25
37
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'dart:math' as math;
import 'package:dio/dio.dart';
import 'package:exide_crr/utils/miscellaneous.dart';
import 'package:exide_crr/constants/app_constants.dart';
import 'package:exide_crr/controller/base_controller.dart';
import 'package:exide_crr/data/app_env.dart';
@@ -25,6 +22,10 @@ final httpClient = http.Client();
class AllHttpRequest {
static String? apiUrl = AppEnvironment.baseApiUrl;
static String? baseUrlForSendOtp = "https://http.myvfirst.com/smpp";
static String? smsData =
"The OTP to get your Free Exide Sunday Ro of Top Solar Solution Proposal is";
Map<String, String> formDataHeader = {
"Content-type": "application/x-www-form-urlencoded"
};
@@ -108,76 +109,63 @@ class AllHttpRequest {
}
/// Send otp api calls
static const auth =
"eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2FwaS5teXZhbHVlZmlyc3QuY29tL3BzbXMiLCJzdWIiOiJkZW1vZmFoZWVtaHRwIiwiZXhwIjozMjIzODg5MTA4fQ.fPUvq3OTlcUVQv8Qg4I3m1MKjfMFI7yESTVJPQUvmI8";
late GetToken generatedAuth;
Future generateAuth() async {
try {
//Generate authorization token for send otp
String url =
'https://http.myvfirst.com/smpp/api/sendsms/token?action=generate';
String username = 'Exidehtptrans1';
String password = '_<P)>lnL0{';
///Generate authorization token for send otp
String url = '$baseUrlForSendOtp/api/sendsms/token?action=generate';
// String username = 'Exidehtptrans1';
// String password = '_<P)>lnL0{';
String basicAuth =
'Basic ${base64.encode(utf8.encode('$username:$password'))}';
'Basic ${base64.encode(utf8.encode('${AppConstants.username}:${AppConstants.password}'))}';
Map<String, String>? headers = {
"Content-type": "application/json",
"Authorization": basicAuth
};
Uri uri = Uri.parse(url);
// make POST request
var response = await http.post(uri,
headers: headers, body: json.encode({"old_token": auth}));
var response = await http.post(uri, headers: headers);
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON.
/// If the call to the server was successful, parse the JSON.
generatedAuth = GetToken.fromJson(jsonDecode(response.body));
///Use generatedAuth to send SMS
sendOtp();
} else {
Fluttertoast.showToast(msg: apiError.tr);
throw Error();
}
} catch (e) {
Fluttertoast.showToast(msg: apiError.tr);
throw Error();
throw Error();
}
}
String generateOTP() {
final math.Random random = math.Random();
final int otp = 1000 + random.nextInt(9000); // Ensures a 4-digit number
return otp.toString();
}
Future sendOtp() async {
try {
final baseController = Get.find<BaseController>();
baseController.generatedOtp.value = generateOTP();
//Send locally generated 4 digit otp to api
// set up POST request arguments
String url =
'https://http.myvfirst.com/smpp/sendsms?to=919945215727&from=ExideB&text=The OTP to get your Free Exide Sunday Ro of Top Solar Solution Proposal is ${baseController.generatedOtp.value} -EXIDE';
///Locally generated 4 digit otp
baseController.generatedOtp.value = Miscellaneous.generateOTP();
///Static smsData along with generated otp
var smsContent='$smsData ${baseController.generatedOtp.value} -EXIDE';
///Set up POST request arguments
String url = '$baseUrlForSendOtp/sendsms?to=${baseController.userPhoneNumber}&from=ExideB&text=$smsContent';
Map<String, String>? headers = {
"Content-type": "application/json",
"Authorization": "Bearer ${generatedAuth.token}",
};
Uri uri = Uri.parse(url);
// make POST request
var response = await http.post(uri, headers: headers);
print(response.body);
if (response.statusCode == 200) {
// // If the call to the server was successful, parse the JSON.
// Fluttertoast.showToast(msg: apiError.tr);
///If success do nothing
} else {
Fluttertoast.showToast(msg: apiError.tr);
throw Error();
}
} catch (e) {
Fluttertoast.showToast(msg: apiError.tr);
@@ -604,7 +592,7 @@ class AllHttpRequest {
case 500:
default:
throw FetchDataException(responseJson['message'] ??
'${AppConstants.communicationError} : ${response.statusCode}');
' Error occurred while Communication with Server with StatusCode : ${response.statusCode}');
}
}
Loading