У меня проблемы с аутентификацией по номеру телефона. Verify_otp генерирует уникальный код для любого проверенного номера - PullRequest
0 голосов
/ 01 апреля 2019

У меня проблемы с аутентификацией по номеру телефона. Verify_otp генерирует уникальный код для любого проверенного номера. Но самая большая проблема заключается в том, что он генерирует код, только если числа начинаются с 6599 ..... с номера 6598 .... он больше не генерирует код.

Я не могу найти розетку для него, чтобы принять любой номер телефона.

это часть файла RegistrationModel.java

public static class OTP_Details{


        /**
         * status : 2
         * message : Otp Sent to phone for Verification
         * otp : 2017
         * auto_otp : 1
         */

        private int status;
        private String message;
        private String otp;
        private int auto_otp;

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public String getOtp() {
            return otp;
        }

        public void setOtp(String otp) {
            this.otp = otp;
        }

        public int getAuto_otp() {
            return auto_otp;
        }

        public void setAuto_otp(int auto_otp) {
            this.auto_otp = auto_otp;
        }
    }
}

Ответы [ 3 ]

0 голосов
/ 01 апреля 2019

Это Activity_forgotpass_verify_otp.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.motofacil.passageiro.ForgotPass_Verify_OTP">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/pure_white"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/otp_back"
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:gravity="center"
            android:visibility="invisible">

            <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:src="@drawable/ic_left_sort"
                android:tint="@color/icons_8_muted_grey"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center">

            <com.motofacil.passageiro.accounts.TypefaceDosisRegular
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/verifyOTP"
                android:textColor="@color/icons_8_muted_grey"
                android:textSize="16dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="50dp"
            android:layout_height="match_parent" />
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/icons_8_muted_grey" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/login_banner"></ImageView>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#bf000000"></RelativeLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical">

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/icons_8_muted_grey" />

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1">




                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center|top"
                    android:layout_marginTop="20dp"
                    android:gravity="center"
                    android:orientation="vertical">

                    <LinearLayout
                        android:id="@+id/phone_layout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="25dp"
                        android:layout_marginLeft="15dp"
                        android:background="@drawable/shapes_white_transparent"
                        android:layout_marginRight="15dp"
                        android:gravity="center"
                        android:orientation="horizontal">


                        <com.hbb20.CountryCodePicker
                            android:id="@+id/otp_ccp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            app:hideNameCode="true"
                            app:keyboardAutoPopOnSearch="false"
                            app:showFlag="false"
                            android:layout_marginLeft="5dp"
                            app:defaultCode="55"
                            app:textSize="15dp"/>

                        <EditText
                            android:id="@+id/edt_enter_phone"
                            android:layout_width="match_parent"
                            android:layout_height="40dp"
                            android:layout_marginLeft="10dp"
                            android:background="@android:color/transparent"
                            android:ems="10"
                            android:drawableTint="@color/icons_8_muted_grey"
                            android:gravity="center|left"
                            android:hint="Enter Phone Number"
                            android:inputType="phone"
                            android:maxLength="10"
                            android:minLines="1"
                            android:padding="5dp"
                            android:textColor="@color/pure_black"
                            android:textSize="17dp" />

                    </LinearLayout>

                    <!--
                                        <View
                                            android:layout_width="match_parent"
                                            android:layout_height="0.85dp"
                                            android:layout_marginBottom="10dp"
                                            android:layout_marginLeft="15dp"
                                            android:layout_marginRight="15dp"
                                            android:layout_marginTop="6dp"
                                            android:background="@color/icons_8_muted_yellow" />-->
                    <Button
                        android:id="@+id/generate_otp"
                        android:layout_marginTop="20dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/generateOTP" />

                    <TextView
                        android:id="@+id/otp_txt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="35dp"
                        android:layout_marginLeft="15dp"
                        android:layout_marginRight="15dp"
                        android:text="@string/otp_text"
                        android:textColor="@color/pure_white"
                        android:textSize="17dp" />



                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginBottom="70dp"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="40dp"
                            android:gravity="center"
                            android:layout_marginLeft="15dp"
                            android:layout_marginRight="15dp"
                            android:layout_marginTop="30dp"
                            android:background="@drawable/shapes_white_transparent"
                            android:orientation="horizontal">




                            <EditText
                                android:id="@+id/otp_edt"
                                android:layout_width="match_parent"
                                android:layout_height="fill_parent"
                                android:background="@android:color/transparent"
                                android:drawableTint="@color/icons_8_muted_grey"
                                android:gravity="center|left"
                                android:hint="@string/enter_otp"
                                android:inputType="number"
                                android:paddingLeft="10dp"
                                android:textColor="@color/pure_black"
                                android:textSize="17dp" />


                            <TextView
                                android:id="@+id/otp_verifier_txt"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginBottom="20dp"
                                android:gravity="center|right"
                                android:padding="10dp"
                                android:text="Email not valid"
                                android:textColor="@color/icons_8_muted_red"
                                android:visibility="gone"/>


                        </LinearLayout>


                    </LinearLayout>

                </LinearLayout>
            </ScrollView>

            <LinearLayout
                android:id="@+id/otp_submit"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@color/colorPrimary"
                android:gravity="center">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/submitOTP"
                    android:textColor="@color/pure_white"
                    android:textSize="16dp" />
            </LinearLayout>

        </LinearLayout>
    </FrameLayout>



</LinearLayout>
0 голосов
/ 01 апреля 2019

Готово! Я представил ниже файлы, которые я перечислил. После набора номера телефона и нажатия кнопки «Отправить», код, который возвращается, всегда является кодом 2017, то есть первым кодом, который я отправил, но он отправляет этот код только в 2017 году, если цифры начинаются следующим образом: 6599 .... если номер это так например: 6598 .... он не генерирует код 2017 и не может продолжить регистрацию.

0 голосов
/ 01 апреля 2019

Это Vetify_otp

package com.motofacil.passageiro;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.motofacil.passageiro.accounts.RegistrationModel;
import com.motofacil.passageiro.accounts.ResultCheckMessage;
import com.motofacil.passageiro.accounts.ResultChecker;
import com.motofacil.passageiro.manager.ApiManager;
import com.motofacil.passageiro.manager.SessionManager;
import com.motofacil.passageiro.samwork.Config;
import com.motofacil.passageiro.urls.Apis;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hbb20.CountryCodePicker;

import java.util.HashMap;


public class Verify_OTP extends AppCompatActivity implements ApiManager.APIFETCHER {

    ApiManager apiManager ;
    GsonBuilder gsonBuilder;
    RegistrationModel.OTP_Details otp_details;
    private TextView otpError_txt;
    private EditText otp_input, edt_enter_phone;
    private LinearLayout submit_otp_layout;
    SessionManager sessionManager ;
    Gson gson;
    String code, input_phone_number, otp;
    CountryCodePicker codePicker;
    private static final int KEY_REGISTER = 110;
    Button generate_otp;
    LinearLayout submit_otp;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        gsonBuilder = new GsonBuilder();
        gson = gsonBuilder.create();
        apiManager = new ApiManager(this , this , this  );
        sessionManager = new SessionManager(Verify_OTP.this);
        otp_details = new RegistrationModel.OTP_Details();
        setContentView(R.layout.activity_verify__otp);

        gsonBuilder = new GsonBuilder();
        gson = gsonBuilder.create();

        submit_otp = (LinearLayout) findViewById(R.id.otp_submit);
        generate_otp = (Button) findViewById(R.id.generate_otp);
        edt_enter_phone = (EditText)findViewById(R.id.edt_enter_phone);
        otp_input = (EditText)findViewById(R.id.otp_edt);
        otpError_txt = (TextView)findViewById(R.id.otp_verifier_txt);
        submit_otp_layout = (LinearLayout)findViewById(R.id.otp_submit);
        codePicker = (CountryCodePicker)findViewById(R.id.otp_ccp);

        submit_otp.setEnabled(false);

        generate_otp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                input_phone_number = edt_enter_phone.getText().toString().trim();
                Log.e("input_phone_number====", input_phone_number);
                code = codePicker.getSelectedCountryCodeWithPlus();
                Log.e("COUNTRY_CODE_PICKER===", code);
                if (input_phone_number.equals("")){
                    Toast.makeText(Verify_OTP.this, R.string.required_field_missing, Toast.LENGTH_SHORT).show();
                }else {
                    getOTP(code+input_phone_number);

                }
            }
        });

        submit_otp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (otp_input.getText().toString().equals("")) {
                    Toast.makeText(Verify_OTP.this, R.string.required_field_missing, Toast.LENGTH_SHORT).show();
                } else if (!otp_input.getText().toString().equals(otp)) {
                   // Toast.makeText(Verify_OTP.this, R.string.invalid_otp, Toast.LENGTH_SHORT).show();

                    Intent intent = new Intent();
                    intent.putExtra("phone_number", code + input_phone_number);
                    setResult(Activity.RESULT_OK, intent);
                     finish();
                } else {
                    Intent intent = new Intent();
                    intent.putExtra("phone_number", code + input_phone_number);
                    setResult(Activity.RESULT_OK, intent);
                    finish();


                }
            }
            });
    }


    private void getOTP(String phone) {
        HashMap<String , String > bodyparameters  = new HashMap<String, String>();
        bodyparameters.put("phone" , phone);
        bodyparameters.put("flag" ,"1");
        apiManager.execution_method_post(Config.ApiKeys.KEY_VERIFY_OTP ,""+  Apis.SEND_OTP, bodyparameters, true,ApiManager.ACTION_SHOW_TOP_BAR);
    }




    @Override
    public void onFetchComplete(Object script, String APINAME) {

        if(APINAME.equals(""+Config.ApiKeys.KEY_VERIFY_OTP)){
            submit_otp.setEnabled(true);
            RegistrationModel.OTP_Details otp_response = gson.fromJson("" + script, RegistrationModel.OTP_Details.class);
            //  finilalizeActivity();
            Log.e("**OTP_SCRIPT-----", String.valueOf(otp_response.getMessage() + otp_response.getOtp() + otp_response.getStatus()));
            otp = otp_response.getOtp();

            Log.d("otp==normal sign up==", otp);
            otp_input.setText(""+otp);
            otp_input.requestFocus();
            if(otp_response.getAuto_otp() == 1){
                otp_input.setText(""+otp);
            }

        }else {
            try{ResultChecker rcheck = gson.fromJson("" + script, ResultChecker.class);
                Log.e("**OTP_SCRIPT-----", String.valueOf(script));

                if(rcheck.getResult() == 1){
                    Log.e("**RCHHECKK---", String.valueOf(rcheck.getResult()));
                    RegistrationModel.OTP_Details otp_response = gson.fromJson("" + script, RegistrationModel.OTP_Details.class);
                }else {
                    ResultCheckMessage rr = gson.fromJson("" + script, ResultCheckMessage.class);
                    Toast.makeText(this, ""+rr.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }catch (Exception e){}
        }



    }


    @Override
    public void onFetchResultZero(String s) {

    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...