Преглед на файлове

Hook backend interface -- 挂后台接口(issue50: #14335)

Ray Zhang преди 4 години
родител
ревизия
a730a847cb

+ 1 - 1
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/Network.java

@@ -186,7 +186,7 @@ public class Network {
             // 获取返回数据
             int responseCode = connection.getResponseCode();
 
-            Log.i(TAG, "getJson: " + "Request " + url + "Get Response Code" + responseCode);
+            Log.i(TAG, "getJson: " + "Request " + url + " Get Response Code" + responseCode);
             
             if(connection.getResponseCode() == 200){
                 InputStream is = connection.getInputStream();

+ 1 - 1
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/Const.java

@@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 public class Const {
 
-    public static final boolean FAKE_DATA = true;
+    public static final boolean FAKE_DATA = false;
 
     public static final int MY_PERMISSIONS_REQUEST = 1;
     private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);

+ 2 - 2
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/RootActivity.java

@@ -489,9 +489,9 @@ public class RootActivity extends BasicActivity {
 
             String msg=null;
             if(request)
-                msg="Apex Mobile needs some essential permissions.";
+                msg="RA TradeFiling needs some essential permissions.";
             else
-                msg="Apex Mobile will quit because missing some essential permissions.\nPlease check your system setting.";
+                msg="RA TradeFiling will quit because missing some essential permissions.\nPlease check your system setting.";
 
             if(missing) {
                 final boolean finalRequest = request;

+ 3 - 3
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/TradeFilingApplication.java

@@ -472,7 +472,7 @@ public class TradeFilingApplication extends Application implements RAProviderHel
 	{
 		m_bauthorized = bauthorized;
 	}
-	public static void login( String user, String pass,JSONObject json)
+	public void login( String user, String pass,JSONObject json)
 	{
 //		m_sessionid = sid;
 		m_user = user;
@@ -501,8 +501,8 @@ public class TradeFilingApplication extends Application implements RAProviderHel
 		try
 		{
 
-			editor.putString("user", AES.encrypt("apexu", m_user));
-			editor.putString("password", AES.encrypt("apexp", m_password));
+			editor.putString("user", AES.encrypt("rau", m_user));
+			editor.putString("password", AES.encrypt("rap", m_password));
 			editor.putBoolean("autologin", true);
 //			editor.putString("sessionid", AES.encrypt("apexp", m_sessionid));
 

+ 1 - 1
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/dataprovider/OfflineDataProvider.java

@@ -34,7 +34,7 @@ public class OfflineDataProvider {
         JSONObject commObj = getJsonFromAsset(TradeFilingApplication.get_instance().getApplicationContext(),"login.json");
 
 
-        TradeFilingApplication.login(
+        TradeFilingApplication.getInstance().login(
                 user, password,commObj);
         return commObj;
     }

+ 156 - 145
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/dataprovider/OnlineDataProvider.java

@@ -52,7 +52,7 @@ public class OnlineDataProvider extends com.usai.redant.rautils.utils.Network
 																													// out
 																													// 20
 																													// secs
-	private static final int	SO_TIMEOUT						= 30 * 1000;										// so
+//	private static final int	SO_TIMEOUT						= 30 * 1000;										// so
 																													// time
 																													// out
 																													// 20
@@ -68,34 +68,47 @@ public class OnlineDataProvider extends com.usai.redant.rautils.utils.Network
 
 
 	//DEBUG
-//	public static String		BASE_URL						= "http://10.0.0.123:8888";
+	public static String		BASE_URL						= "http://192.168.0.149/ACE_ISF_NEW";
 
 	//RELEASE
-	public static String		BASE_URL						= "https://ra.apexshipping.com";
+//	public static String		BASE_URL						= "https://ra.united-us.net/doc/bk";
 
 
 //	URL
-	public static String		URL_HOME						= BASE_URL+"/main_new_29.php";
-	public static String		URL_LOGIN						= BASE_URL+"/main_new_29.php";
+	public static String		URL_LOGIN						= BASE_URL+"/loginMobile.php";
+	public static String		URL_CHANGE_PASS						= BASE_URL+"/loginMobile.php";
+	public static String		URL_LOGOUT						= BASE_URL+"/loginMobile.php";
+	public static String		URL_RETRIEVE_PASS						= BASE_URL+"/loginMobile.php";
+	public static String		URL_SIGNUP						= BASE_URL+"/loginMobile.php";
+
+
+	public static String		URL_HOME						= BASE_URL+"/mobileMain.php";
+	public static String		URL_SEARCH_RESULT					= BASE_URL+"/resultMobile.php";
+
+	public static String		URL_REQUEST_DETAIL					= BASE_URL+"/resultMobile.php";
+
+	public static String		URL_UPLOAD_IMG					= BASE_URL+"";
+	public static String		URL_SAVE_EDITOR					= BASE_URL+"/editorMobile_v1.php";
+	public static String		URL_EDIT					= BASE_URL+"/editorMobile_v1.php";
+	public static String		URL_CADEDATE					= BASE_URL+"/resultMobile_v1.php";
+
+
 
-	public static String		URL_HISTORY						= BASE_URL+"/main_new_29.php";
-	public static String		URL_KPI							= BASE_URL+"/main_new_29.php";
 	public static String		URL_UPDATE_AUTH					= BASE_URL+"/main_new_29.php";
 	public static String		URL_REQUEST_COUNT				= BASE_URL+"/main_new_29.php";
 	public static String		URL_REQUEST_RECORDS				= BASE_URL+"/main_new_29.php";
-	public static String		URL_RETRIEVE_PASS				= BASE_URL+"/main_new_29.php";
+
 	public static String		URL_ANNOUNCEMENTS				= BASE_URL+"/mobile_news.php";
 	public static String		URL_NEWS						= BASE_URL+"/mobile_news.php";
 	public static String		URL_LOCATIONS					= BASE_URL+"/mobile_news26.php";
 	public static String		URL_PUSH						= BASE_URL+"/main_new_29.php";
 	public static String		URL_LOG							= BASE_URL+"/mobile_news.php";
-	public static String		URL_SEND_COMM_EMAIL				= BASE_URL+"/main_new_29.php";
 	public static String		URL_CHECK_UPDATE				= BASE_URL+"/main_new_29.php";
 
 
 	public static String		URL_UPLOAD_SQL					= BASE_URL+"/main_new_29.php";
-	public static String		URL_FETCH_RESULT				= BASE_URL+"/main_new_29.php";
-	public static String		URL_SAVE_RESULT					= BASE_URL+"/main_new_29.php";
+//	public static String		URL_FETCH_RESULT				= BASE_URL+"/main_new_29.php";
+//	public static String		URL_SAVE_RESULT					= BASE_URL+"/main_new_29.php";
 
 	public static String		URL_PRIVACY_POLICY					= "http://united-us.net/privacy.html";
 
@@ -123,44 +136,6 @@ public class OnlineDataProvider extends com.usai.redant.rautils.utils.Network
 //	public static String		URL_FETCH_RESULT				= "http://192.168.0.138:8899/main_new_29.php";
 //	public static String		URL_SAVE_RESULT					= "http://192.168.0.138:8899/main_new_29.php";
 //
-private static void prepareParams(Bundle params) {
-	if (params == null) {
-		params = new Bundle();
-	}
-
-	String password = params.getString("password");
-
-	String user = params.getString("name");
-	if (user == null) {
-		user = TradeFilingApplication.get_user();
-		if (!TextUtils.isEmpty(user)) {
-			params.putString("name",user);
-		}
-	}
-
-	if (password == null) {
-		password = TradeFilingApplication.get_pass();
-		if (!TextUtils.isEmpty(password)) {
-			params.putString("password",password);
-		}
-	}
-
-	Locale curLocale = TradeFilingApplication.get_instance().getResources().getConfiguration().locale;
-	String languageCode = curLocale.getLanguage();
-	if (languageCode != null) {
-		params.putString("language",languageCode);
-	}
-
-	String company = TradeFilingApplication.get_company_list().optJSONObject(TradeFilingApplication.get_current_company_index()).optString("id");
-
-	if(TextUtils.isEmpty(params.getString("company"))&&!TextUtils.isEmpty(company))
-	{
-		params.putString("company",company);
-	}
-
-
-	params.putString("platform","android");
-}
 
 
 	public static JSONObject request_login(String user, String password)
@@ -168,17 +143,16 @@ private static void prepareParams(Bundle params) {
 
 		Bundle params = new Bundle();
 
-		user = TradeFilingApplication.get_user();
-		password = TradeFilingApplication.get_pass();
+		params.putString("action","login");
 
 		if (user != null) {
-			params.putString("name",user); // "WMoy059hzweXPSC74plhBA=="
+			params.putString("user",user); // "WMoy059hzweXPSC74plhBA=="
 		}
 		if (password != null) {
 			params.putString("password",password); // "CzADM7u51eNR7ScfQtJw7w=="
 		}
 
-		prepareParams(params);
+
 
 		String jsonStr = getJson(URL_LOGIN,params);
 //        if (jsonStr == null || jsonStr.isEmpty()) {
@@ -198,6 +172,84 @@ private static void prepareParams(Bundle params) {
 
 		return handleJson(jsonStr);
 	}
+
+	public static JSONObject request_home() {
+
+		Bundle params = new Bundle();
+		params.putString("action","dashboardMobile");
+
+//		boolean personMode = TradeFilingApplication.get_instance().getPersonMode();
+//		if (personMode) {
+//			params.putString("personal_mode","true");
+//		} else {
+//			params.putString("personal_mode","false");
+//		}
+
+		String jstr = getJson(URL_HOME,params);
+
+		return handleJson(jstr);
+//		Log.d("Network", "request_home: " + jstr);
+//		try {
+//
+//			if (jstr == null || jstr.length() <= 0)
+//			{
+//				JSONObject resultJson = new JSONObject();
+//				resultJson.put("err_msg","Net Error. Cannot connect to server for now. Please retry later.");
+//				resultJson.put("result",RESULT_NET_ERROR);
+//				return resultJson;
+//			}
+//
+//			JSONObject jsobj = new JSONObject(jstr);
+//			return jsobj;
+//
+//		} catch (JSONException e) {
+//			e.printStackTrace();
+//		}
+
+//		return null;
+	}
+
+	public static JSONObject request_detail(Bundle params)
+	{
+		if(params==null)
+			params = new Bundle();
+		params.putString("action","detail");
+
+//		boolean personMode = TradeFilingApplication.get_instance().getPersonMode();
+//		if (personMode) {
+//			params.putString("personal_mode","true");
+//		} else {
+//			params.putString("personal_mode","false");
+//		}
+
+		String jstr = getJson(URL_REQUEST_DETAIL,params);
+
+		return handleJson(jstr);
+
+//		return null;
+	}
+	public static JSONObject request_result(Bundle params)
+	{
+		if(params==null)
+			params = new Bundle();
+		params.putString("action","result");
+
+//		boolean personMode = TradeFilingApplication.get_instance().getPersonMode();
+//		if (personMode) {
+//			params.putString("personal_mode","true");
+//		} else {
+//			params.putString("personal_mode","false");
+//		}
+
+		String jstr = getJson(URL_SEARCH_RESULT,params);
+
+		return handleJson(jstr);
+
+//		return null;
+	}
+
+
+
 	public static JSONObject request_signup(String user, String password)
 	{
 		return null;
@@ -382,60 +434,28 @@ private static void prepareParams(Bundle params) {
 		return RESULT_NET_ERROR;
 	}
 
-	public static int retrieve_pass(String user, String email)
+	public static JSONObject retrieve_pass(String user, String email)
 	{
 		String TAG = "net_dbg@retrieve_pass";
 		Log.d(TAG, "u:" + user + ";e:" + email);
-		if (!OnlineDataProvider.NetworkIsAvailable())
-		{
-			Log.d(TAG, "network not available!");
-			return OnlineDataProvider.RESULT_NET_NOTAVAILABLE; // network not available
-		}
+//		if (!OnlineDataProvider.NetworkIsAvailable())
+//		{
+//			Log.d(TAG, "network not available!");
+//			return OnlineDataProvider.RESULT_NET_NOTAVAILABLE; // network not available
+//		}
 		Bundle parms = new Bundle();
 		parms.putString("user", user);
 		parms.putString("email", email);
-		parms.putString("module_name", "Retrieve Password");
-		parms.putString("action", "handset_search");
-		String jstr = getJson(OnlineDataProvider.URL_RETRIEVE_PASS, parms);
+		parms.putString("action", "retrievePassword");
+
 		/*
 		 * error occur while get authorization info from server. include can not
 		 * reach server , wrong parms ,server get wrong , etc.
 		 */
-		if (jstr == null || jstr.length() <= 0)
-		{
-			Log.d(TAG, "json is wrong");
-			return OnlineDataProvider.RESULT_NET_ERROR;
-		}
-		JSONObject jsobj;
 
-		// array = new JSONArray(json);
-		try
-		{
-			jsobj = new JSONObject(jstr);
-			if (jsobj.length() > 0)
-			{
-				int iresult = jsobj.getInt("result");
+		String jstr = getJson(URL_HOME,parms);
 
-				if (iresult != OnlineDataProvider.AP_USER_AUTH)
-				{
-					// user not authorized return
-					Log.d(TAG,
-							"USER NOT AUTHORIZED CODE="
-									+ jsobj.getInt("result"));
-					return RESULT_FALSE;
-				}
-				return RESULT_TRUE;
-
-			}
-			return RESULT_NET_ERROR;
-		}
-		catch (JSONException e)
-		{
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-		return RESULT_NET_ERROR;
+		return handleJson(jstr);
 	}
 
 	public static void prepare_addtional_params(Bundle params) {
@@ -443,18 +463,49 @@ private static void prepareParams(Bundle params) {
 			params = new Bundle();
 		}
 
-		String user = TradeFilingApplication.get_user();
-		if (user != null && params.getString("user") == null) {
-			params.putString("user",user);
+		String password = params.getString("password");
+
+		String user = params.getString("user");
+		if (user == null) {
+			user = TradeFilingApplication.get_user();
+			if (!TextUtils.isEmpty(user)) {
+				params.putString("user",user);
+			}
+		}
+
+		if (password == null) {
+			password = TradeFilingApplication.get_pass();
+			if (!TextUtils.isEmpty(password)) {
+				params.putString("password",password);
+			}
+		}
+
+		Locale curLocale = TradeFilingApplication.get_instance().getResources().getConfiguration().locale;
+		String languageCode = curLocale.getLanguage();
+		if (languageCode != null) {
+			params.putString("language",languageCode);
 		}
 
-		String pwd = TradeFilingApplication.get_pass();
-		if (pwd != null && params.getString("pwd") == null) {
-			params.putString("pwd",pwd);
+		params.putString("os","android");
+
+
+		params.putString("app_ver",SHORT_VER);
+		params.putString("deviceid", RAUtil.getDeviceId(TradeFilingApplication.get_instance().getApplicationContext()));
+
+		int company_idx=TradeFilingApplication.get_current_company_index();
+		if(TradeFilingApplication.get_company_list()==null)
+			return;
+		JSONObject company_json = TradeFilingApplication.get_company_list().optJSONObject(company_idx);
+		if(company_json!=null)
+		{
+			String company = company_json.optString("id");
+
+			if(TextUtils.isEmpty(params.getString("company"))&&!TextUtils.isEmpty(company))
+			{
+				params.putString("company",company);
+			}
 		}
 
-		params.putString("os","Android");
-		params.putString("app_short_ver",SHORT_VER);
 
 	}
 
@@ -1007,8 +1058,8 @@ private static void prepareParams(Bundle params) {
 				// ApexTrackingApplication.put_user(user);
 				// ApexTrackingApplication.put_password(pass);
 				// ApexTrackingApplication.put_authorization(true);
-				TradeFilingApplication.login(
-						user, pass,jsobj);
+//				TradeFilingApplication.login(
+//						user, pass,jsobj);
 //				Log.d(TAG, "sessionid=" + objheader.getString("sessionid"));
 				// JSONObject objupdate = array.getJSONObject(3); // whether
 				// need
@@ -1464,47 +1515,7 @@ private static void prepareParams(Bundle params) {
 
 		return null;
 	}
-	public static JSONObject request_detail(Bundle params)
-	{
-		return null;
-	}
-	public static JSONObject request_result(Bundle params)
-	{
-		return null;
-	}
-	public static JSONObject request_home() {
 
-		Bundle params = new Bundle();
-		params.putString("action","hand_new_home_list");
-		params.putBoolean("request_location",true);
-		boolean personMode = TradeFilingApplication.get_instance().getPersonMode();
-		if (personMode) {
-			params.putString("personal_mode","true");
-		} else {
-			params.putString("personal_mode","false");
-		}
-
-		String jstr = getJson(URL_HOME,params);
-		Log.d("Network", "request_home: " + jstr);
-		try {
-
-			if (jstr == null || jstr.length() <= 0)
-			{
-				JSONObject resultJson = new JSONObject();
-				resultJson.put("err_msg","Net Error. Cannot connect to server for now. Please retry later.");
-				resultJson.put("result",RESULT_NET_ERROR);
-				return resultJson;
-			}
-
-			JSONObject jsobj = new JSONObject(jstr);
-			return jsobj;
-
-		} catch (JSONException e) {
-			e.printStackTrace();
-		}
-
-		return null;
-	}
 
 
 

+ 18 - 2
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/dataprovider/RADataProvider.java

@@ -27,9 +27,25 @@ public class RADataProvider {
 //    public static final int		RESULT_UPDATE_USERAUTH_ERROR	= -11;
 //    public static final int		RESULT_SESSION_EXPIRED			= -13;
 //    public static final int		RESULT_VER_LOW					= -15;
-    public static int retrieve_pass(String user, String email)
+    public static JSONObject retrieve_pass(String user, String email)
     {
-        return 0;
+
+        if(FAKE_DATA)
+        {
+            try
+            {
+                return new JSONObject("{\"result\":2}");
+            } catch (JSONException e)
+            {
+                e.printStackTrace();
+                return null;
+            }
+        }
+        else
+        {
+            return OnlineDataProvider.retrieve_pass(user,email);
+        }
+
     }
     public static JSONArray loadSavedDetail()
     {

+ 3 - 2
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/home/HomeFragment.java

@@ -643,7 +643,8 @@ public class HomeFragment extends Fragment
         {
             try
             {
-                JSONObject totaljson=json.getJSONObject("total");
+
+                JSONObject totaljson=json.optJSONObject("total");
 
                 String headertext = "<center><font size=5 color=white><b>In 30 Days</b>";
 
@@ -706,7 +707,7 @@ public class HomeFragment extends Fragment
 
 //                    mHeaderModel.setValuesForKeysWithJSON(json);
                 }
-            } catch (JSONException e)
+            } catch (Exception e)
             {
                 e.printStackTrace();
             }

+ 8 - 5
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/login/LoginFragment.java

@@ -164,8 +164,8 @@ public class LoginFragment extends Fragment/* implements OnClickListener */
 		String p = pref.getString("password", null);
 		if (u != null && p != null) {
 			try {
-				m_etName.setText(AES.decrypt("apexu", u));
-				m_etPassword.setText(AES.decrypt("apexp", p));
+				m_etName.setText(AES.decrypt("rau", u));
+				m_etPassword.setText(AES.decrypt("rap", p));
 				m_cbSave.setChecked(true);
 			} catch (Exception e) {
 				// TODO Auto-generated catch block
@@ -396,15 +396,15 @@ public class LoginFragment extends Fragment/* implements OnClickListener */
 						case RESULT_TRUE:
 						{
 							SharedPreferences pref = TradeFilingApplication.get_instance()
-									.getSharedPreferences("Apex", 0);
+									.getSharedPreferences("RA TradeFiling", 0);
 							SharedPreferences.Editor editor = pref.edit();
 
 							try {
 								if (/*m_cbSave.isChecked()*/ true) {
 									editor.putString("user",
-											AES.encrypt("apexu", m_sUser.toLowerCase()));
+											AES.encrypt("rau", m_sUser.toLowerCase()));
 									editor.putString("password",
-											AES.encrypt("apexp", m_sPassword));
+											AES.encrypt("rap", m_sPassword));
 									editor.putBoolean("autologin", true);
 								} else {
 									editor.putString("user", null);
@@ -422,6 +422,9 @@ public class LoginFragment extends Fragment/* implements OnClickListener */
 							editor.commit();
 
 							TradeFilingApplication.getInstance().shouldCheckCache = true;
+							TradeFilingApplication.getInstance().login(m_sUser,m_sPassword,jsobj);
+
+
 
 							if(mCallBack!=null)
 								mCallBack.onLogin();

+ 35 - 5
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/login/RetrievePasswordActivity.java

@@ -31,6 +31,10 @@ import com.usai.ratradefiling.R;
 import com.usai.ratradefiling.dataprovider.OnlineDataProvider;
 import com.usai.ratradefiling.dataprovider.RADataProvider;
 
+import org.json.JSONObject;
+
+import static com.usai.redant.rautils.utils.Network.RESULT_FAILED_WITH_MESSAGE;
+
 
 /**
  * Activity which displays a login screen to the user, offering registration as
@@ -290,13 +294,13 @@ public class RetrievePasswordActivity extends AppCompatActivity
 	 */
 	public class UserLoginTask extends AsyncTask<Void, Void, Boolean>
 	{
-		int	errorcode;
+		JSONObject json;
 
 		@Override
 		protected Boolean doInBackground(Void... params)
 		{
-			errorcode = RADataProvider.retrieve_pass(m_sUser, m_sEmail);
-			if (errorcode == OnlineDataProvider.RESULT_TRUE)
+			json = RADataProvider.retrieve_pass(m_sUser, m_sEmail);
+			if (json.optInt("result") == OnlineDataProvider.RESULT_TRUE)
 				return true;
 			else
 			{
@@ -349,7 +353,9 @@ public class RetrievePasswordActivity extends AppCompatActivity
 			}
 			else
 			{
-				switch (errorcode)
+
+				int code=json.optInt("result");
+				switch (code)
 				{
 					case OnlineDataProvider.RESULT_NET_NOTAVAILABLE:
 					{
@@ -403,12 +409,36 @@ public class RetrievePasswordActivity extends AppCompatActivity
 						builder.create().show();
 						return;
 
+					}
+					case RESULT_FAILED_WITH_MESSAGE:
+					{
+						Builder builder = new Builder(
+								RetrievePasswordActivity.this);
+						builder.setMessage(json.optString("err_msg"));
+
+						builder.setTitle(getString(R.string.str_retrieve_failed));
+
+						builder.setPositiveButton(getString(android.R.string.ok), new OnClickListener()
+						{
+
+							@Override
+							public void onClick(DialogInterface dialog,
+												int which)
+							{
+								dialog.dismiss();
+
+								// RetrievePasswordActivity.this.finish();
+							}
+						});
+						builder.create().show();
+						return;
+
 					}
 					default:
 					{
 						Toast toast = Toast.makeText(getApplicationContext(),
 								getText(R.string.msg_net_resulterror) + ":"
-										+ errorcode, Toast.LENGTH_LONG);
+										+ code, Toast.LENGTH_LONG);
 						toast.setGravity(Gravity.CENTER, 0, 0);
 						toast.show();
 						break;