Ver código fonte

对接现有接口

316044749 7 anos atrás
pai
commit
eba3dbf3cb

+ 62 - 0
app/src/main/java/com/ynstkz/shitu/android/activity/LoginActivity.java

@@ -4,19 +4,27 @@ import android.content.Intent;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
+import android.text.TextUtils;
 import android.util.Log;
+import android.util.Patterns;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import com.common.library.okhttp.callback.Callback;
+import com.google.gson.Gson;
 import com.ynstkz.shitu.android.R;
 import com.ynstkz.shitu.android.base.TitleBarActivity;
+import com.ynstkz.shitu.android.bean.LoginBean;
+import com.ynstkz.shitu.android.data.RequestGroup;
 import com.ynstkz.shitu.android.utils.StatusBarUtil;
 
 import butterknife.Bind;
 import butterknife.ButterKnife;
+import okhttp3.Call;
+import okhttp3.Response;
 
 /**
  * 作者:fuchangle on 2018/1/31 16:29
@@ -93,5 +101,59 @@ public class LoginActivity extends TitleBarActivity {
                 startActivity(new Intent(LoginActivity.this, FindPasswordActivity.class));
             }
         });
+        //登陆
+        btnLogin.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                String userName = editUsername.getText().toString().trim();
+                String userPwd = editPassword.getText().toString().trim();
+                if(verifyData(userName, userPwd)){
+                    login(userName,userPwd);
+                }
+            }
+        });
+    }
+
+    /**
+     * 登陆
+     * @param userName
+     * @param userPwd
+     */
+    private void login(String userName, String userPwd){
+
+        RequestGroup.login(userName, userPwd, new Callback() {
+            @Override
+            public Object parseNetworkResponse(Response response, int id) throws Exception {
+                return new Gson().fromJson(response.body().string(), LoginBean.class);
+            }
+
+            @Override
+            public void onError(Call call, Exception e, int id) {
+
+            }
+
+            @Override
+            public void onResponse(Object response, int id) {
+
+            }
+        });
+    }
+
+    /**
+     * 校验数据
+     * @param userName
+     * @param userPwd
+     * @return
+     */
+    private boolean verifyData(String userName, String userPwd){
+        if(TextUtils.isEmpty(userName)){
+            showToast("用户名不能为空!");
+            return false;
+        }
+        if(TextUtils.isEmpty(userPwd)){
+            showToast("密码不能为空!");
+            return false;
+        }
+        return true;
     }
 }

+ 122 - 1
app/src/main/java/com/ynstkz/shitu/android/activity/RegisterSubmitActivity.java

@@ -3,18 +3,46 @@ package com.ynstkz.shitu.android.activity;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
+import android.text.TextUtils;
+import android.util.Patterns;
 import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.TextView;
 
+import com.amap.api.navi.view.PoiInputResItemWidget;
+import com.common.library.okhttp.callback.Callback;
+import com.google.gson.Gson;
 import com.ynstkz.shitu.android.R;
 import com.ynstkz.shitu.android.base.TitleBarActivity;
+import com.ynstkz.shitu.android.bean.RegisterBean;
+import com.ynstkz.shitu.android.data.RequestGroup;
 import com.ynstkz.shitu.android.utils.StatusBarUtil;
 
+import butterknife.Bind;
+import okhttp3.Call;
+import okhttp3.Response;
+
 /**
  * 注册提交
  * 作者:fuchangle on 2018/2/7 14:26
  */
 
-public class RegisterSubmitActivity extends TitleBarActivity{
+public class RegisterSubmitActivity extends TitleBarActivity {
+
+    @Bind(R.id.iv_cancel)
+    ImageView ivCancel;
+    @Bind(R.id.tv_login)
+    TextView tvLogin;
+    @Bind(R.id.edit_username)
+    EditText editUsername;
+    @Bind(R.id.edit_password)
+    EditText editPassword;
+    @Bind(R.id.edit_password_again)
+    EditText editPasswordAgain;
+    @Bind(R.id.btn_register)
+    Button btnRegister;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -23,10 +51,103 @@ public class RegisterSubmitActivity extends TitleBarActivity{
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             setStatusBarColor(this, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
         }
+        initView();
+        initData();
+        setListener();
     }
 
     @Override
     protected int getLayoutId() {
         return R.layout.activity_register_submint;
     }
+
+    private void initView(){
+
+    }
+
+    private void initData(){
+
+    }
+
+    private void setListener(){
+
+        /**
+         * 注册
+         */
+        btnRegister.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                String mobile = "18561761886";
+                String userName = editUsername.getText().toString().trim();
+                String pwd = editPassword.getText().toString().trim();
+                String rePwd = editPasswordAgain.getText().toString().trim();
+                if(verifyData(mobile, userName, pwd, rePwd)){
+                    register(mobile, userName, pwd, rePwd);
+                }
+            }
+        });
+    }
+
+    /**
+     * 注册
+     * @param mobile
+     * @param userName
+     * @param pwd
+     * @param rePwd
+     */
+    private void register(String mobile, String userName, String pwd, final String rePwd){
+
+        RequestGroup.register(mobile, userName, pwd, rePwd, new Callback() {
+            @Override
+            public Object parseNetworkResponse(Response response, int id) throws Exception {
+                return new Gson().fromJson(response.body().string(), RegisterBean.class);
+            }
+
+            @Override
+            public void onError(Call call, Exception e, int id) {
+                showToast(getString(R.string.error_msg));
+            }
+
+            @Override
+            public void onResponse(Object response, int id) {
+                RegisterBean bean = (RegisterBean)response;
+            }
+        });
+    }
+
+    /**
+     * 校验数据
+     * @param mobile
+     * @param userName
+     * @param pwd
+     * @param rePwd
+     * @return
+     */
+    private boolean verifyData(String mobile, String userName, String pwd, String rePwd){
+        if(TextUtils.isEmpty(mobile)){
+            showToast("手机号码不能为空!");
+            return false;
+        }
+        if(!Patterns.PHONE.matcher(mobile).matches()){
+            showToast("手机号码不正确!");
+            return false;
+        }
+        if(TextUtils.isEmpty(userName)){
+            showToast("用户名不能为空!");
+            return false;
+        }
+        if(TextUtils.isEmpty(pwd)){
+            showToast("密码不能为空!");
+            return false;
+        }
+        if(TextUtils.isEmpty(rePwd)){
+            showToast("确认密码不能为空!");
+            return false;
+        }
+        if(!pwd.equals(rePwd)){
+            showToast("密码输入不一致");
+            return false;
+        }
+        return true;
+    }
 }

+ 5 - 0
app/src/main/java/com/ynstkz/shitu/android/application/STApplication.java

@@ -3,6 +3,8 @@ package com.ynstkz.shitu.android.application;
 import android.app.Application;
 import android.content.Context;
 
+import com.common.library.okhttp.OkHttpUtils;
+
 /**
  * 作者:fuchangle on 2018/1/27 21:56
  */
@@ -15,6 +17,9 @@ public class STApplication extends Application{
     public void onCreate() {
         super.onCreate();
         context = getApplicationContext();
+        if(com.common.library.Constants.DEVELOP_MODE){
+            OkHttpUtils.getInstance().debug("okhttp", true);
+        }
     }
 
     public static Context getContext(){

+ 11 - 0
app/src/main/java/com/ynstkz/shitu/android/bean/LoginBean.java

@@ -0,0 +1,11 @@
+package com.ynstkz.shitu.android.bean;
+
+import com.ynstkz.shitu.android.base.BaseBean;
+
+/**
+ * 作者:fuchangle on 2018/2/21 16:54
+ */
+
+public class LoginBean extends BaseBean{
+
+}

+ 12 - 0
app/src/main/java/com/ynstkz/shitu/android/bean/RegisterBean.java

@@ -0,0 +1,12 @@
+package com.ynstkz.shitu.android.bean;
+
+import com.ynstkz.shitu.android.base.BaseBean;
+
+/**
+ * 作者:fuchangle on 2018/2/12 17:54
+ */
+
+public class RegisterBean extends BaseBean{
+
+
+}

+ 196 - 0
app/src/main/java/com/ynstkz/shitu/android/data/RequestGroup.java

@@ -0,0 +1,196 @@
+package com.ynstkz.shitu.android.data;
+
+import com.common.library.okhttp.OkHttpUtils;
+import com.common.library.okhttp.callback.Callback;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 作者:fuchangle on 2018/2/12 17:33
+ */
+
+public class RequestGroup {
+
+    /***
+     * 获取系统级参数
+     *
+     * @return
+     */
+    public static Map<String, String> getSystemParams() {
+        Map<String, String> params = new HashMap<>();
+        return params;
+    }
+
+    /**
+     * 注册
+     * @param mobile
+     * @param userName
+     * @param pwd
+     * @param rePwd
+     */
+    public static void register(String mobile, String userName, String pwd, String rePwd, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("mobile", mobile);
+        params.put("userName", userName);
+        params.put("pwd", pwd);
+        params.put("rePwd", rePwd);
+        OkHttpUtils.post().url(UrlCat.URL_REGISTER).params(params).build().execute(callback);
+    }
+
+    /**
+     * 登陆
+     * @param userName
+     * @param userPwd
+     * @param callback
+     */
+    public static void login(String userName, String userPwd, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("userName", userName);
+        params.put("userPwd", userPwd);
+        OkHttpUtils.post().url(UrlCat.URL_LOGIN).params(params).build().execute(callback);
+    }
+
+    /**
+     * 获取更新
+     */
+    public static void getAppVersion(Callback callback){
+        Map<String, String> params = getSystemParams();
+        OkHttpUtils.get().url(UrlCat.URL_APP_VERSION).params(params).build().execute(callback);
+    }
+
+    /**
+     * 发送短信
+     * @param type
+     * @param mobile
+     */
+    public static void snedSms(String type, String mobile, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("type", type);
+        params.put("mobile", mobile);
+        OkHttpUtils.post().url(UrlCat.URL_SMS_SEND).params(params).build().execute(callback);
+    }
+
+    /**
+     * 发送短信
+     * @param type
+     * @param mobile
+     */
+    public static void verifySms(String type, String mobile, String code, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("type", type);
+        params.put("mobile", mobile);
+        params.put("code", code);
+        OkHttpUtils.post().url(UrlCat.URL_SMS_VERIFY).params(params).build().execute(callback);
+    }
+
+    /**
+     * 获取banner
+     * @param callback
+     */
+    public static void getBannerList(Callback callback){
+        Map<String, String> params = getSystemParams();
+        OkHttpUtils.get().url(UrlCat.URL_INDEX_BANNER).params(params).build().execute(callback);
+    }
+
+    /**
+     * 身份认证
+     * @param isParent
+     * @param realName
+     * @param idCardNum
+     */
+    public static void userAuth(String isParent, String realName, String idCardNum, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("isParent", isParent);
+        params.put("realName", realName);
+        params.put("idCardNum", idCardNum);
+        OkHttpUtils.post().url(UrlCat.URL_USER_AUTH).params(params).build().execute(callback);
+    }
+
+    /**
+     * 修改密码
+     * @param mobile
+     * @param pwd
+     * @param rePwd
+     */
+    public static void userFindPwd(String mobile, String pwd, String rePwd, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("mobile", mobile);
+        params.put("pwd", pwd);
+        params.put("rePwd", rePwd);
+        OkHttpUtils.post().url(UrlCat.URL_USER_FINDPWD).params(params).build().execute(callback);
+    }
+
+    /**
+     * 用户详情
+     */
+    public static void userInfo(Callback callback){
+        Map<String, String> params = getSystemParams();
+        OkHttpUtils.post().url(UrlCat.URL_USER_INFO).params(params).build().execute(callback);
+    }
+
+    /**
+     * 手机号,验证码登录
+     * @param mobile
+     * @param code
+     */
+    public static void loginCode(String mobile, String code, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("mobile", mobile);
+        params.put("code", code);
+        OkHttpUtils.post().url(UrlCat.URL_LOGIN_CODE).params(params).build().execute(callback);
+    }
+
+    /**
+     * 三方登录
+     * @param thirdId
+     * @param thirdType
+     */
+    public static void loginThird(String thirdId, String thirdType, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("thirdId", thirdId);
+        params.put("thirdType", thirdType);
+        OkHttpUtils.post().url(UrlCat.URL_LOGIN_THIRD).params(params).build().execute(callback);
+    }
+
+    /**
+     * 修改头像
+     * @param headPic
+     * @param callback
+     */
+    public static void userResetHeadpic(String headPic, Callback callback){
+        Map<String, String> params = getSystemParams();
+        OkHttpUtils.post().url(UrlCat.URL_USER_HEADPIC).params(params).build().execute(callback);
+    }
+
+    /**
+     * 修改手机号
+     * @param mobile
+     */
+    public static void userResetMobile(String mobile, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("mobile", mobile);
+        OkHttpUtils.post().url(UrlCat.URL_USER_RESET_MOBILE).params(params).build().execute(callback);
+    }
+
+    /**
+     * 修改密码
+     */
+    public static void userResetPwd(String oldPwd, String pwd, String rePwd, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("oldPwd", oldPwd);
+        params.put("pwd", pwd);
+        params.put("rePwd", rePwd);
+        OkHttpUtils.post().url(UrlCat.URL_USER_RESET_PWD).params(params).build().execute(callback);
+    }
+
+    /**修改用户名
+     * @param userName
+     * @param callback
+     */
+    public static void userResetUsername(String userName, Callback callback){
+        Map<String, String> params = getSystemParams();
+        params.put("userName", userName);
+        OkHttpUtils.post().url(UrlCat.URL_USER_RESET_USERNAME).params(params).build().execute(callback);
+    }
+}

+ 1 - 1
app/src/main/java/com/ynstkz/shitu/android/data/SharedPreferencesUtils.java

@@ -15,7 +15,7 @@ public class SharedPreferencesUtils {
      * @return
      */
     public static boolean isLogin(){
-        return (Boolean)SharedPreferencesDao.get(IS_LOGIN, true);
+        return (Boolean)SharedPreferencesDao.get(IS_LOGIN, false);
     }
 
     public static void setLocation (String location){

+ 85 - 0
app/src/main/java/com/ynstkz/shitu/android/data/UrlCat.java

@@ -0,0 +1,85 @@
+package com.ynstkz.shitu.android.data;
+
+/**
+ * 作者:fuchangle on 2018/2/12 17:30
+ */
+
+public class UrlCat {
+
+    private static final String HOST = "http://60.205.218.197/";
+
+    /**
+     * 注册
+     */
+    public static final String URL_REGISTER = HOST + "api/user/register";
+
+    /**
+     * 登录
+     */
+    public static final String URL_LOGIN = HOST + "api/user/login/pwd";
+
+    /**
+     * 版本更新
+     */
+    public static final String URL_APP_VERSION = HOST + "api/app/version";
+
+    /**
+     * 发送验证码
+     */
+    public static final String URL_SMS_SEND = HOST + "api/sms/send";
+
+    /**
+     * 验证码校验
+     */
+    public static final String URL_SMS_VERIFY = HOST + "api/sms/verify";
+
+    /**
+     * banner
+     */
+    public static final String URL_INDEX_BANNER = HOST + "api/index/banner/list";
+
+    /**
+     * 身份认证
+     */
+    public static final String URL_USER_AUTH = HOST + "api/user/authentication";
+
+    /**
+     * 忘记密码
+     */
+    public static final String URL_USER_FINDPWD = "api/user/find/pwd";
+
+    /**
+     * 用户信息
+     */
+    public static final String URL_USER_INFO = "api/user/info";
+
+    /**
+     * 手机号-验证那登录
+     */
+    public static final String URL_LOGIN_CODE = "api/user/login/code";
+
+    /**
+     * 三方登录
+     */
+    public static final String URL_LOGIN_THIRD = "api/user/login/third";
+
+    /**
+     * 修改头像
+     */
+    public static final String URL_USER_HEADPIC = "api/user/reset/headpic";
+
+    /**
+     * 修改手机号
+     */
+    public static final String URL_USER_RESET_MOBILE = "api/user/reset/mobile";
+
+    /**
+     * 修改密码
+     */
+    public static final String URL_USER_RESET_PWD = "api/user/reset/pwd";
+
+    /**
+     * 修改用户名
+     */
+    public static final String URL_USER_RESET_USERNAME = "api/user/reset/username";
+}

+ 4 - 1
app/src/main/res/layout/activity_bindthreeaccount.xml

@@ -1,6 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical" android:layout_width="match_parent"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
     android:layout_height="match_parent">
 
+    <include layout="@layout/view_title"/>
+
 </LinearLayout>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -3,4 +3,5 @@
     <string name="lab_home">首页</string>
     <string name="lab_nearby">附近</string>
     <string name="lab_usercenter">我</string>
+    <string name="error_msg">服务器连接失败,请稍后再试</string>
 </resources>

+ 1 - 0
library/build.gradle

@@ -26,4 +26,5 @@ dependencies {
     compile 'com.android.support:recyclerview-v7:26.1.0'
     compile 'com.android.support:appcompat-v7:26.1.0'
     compile 'com.squareup.okhttp3:okhttp:3.3.1'
+    compile 'com.google.code.gson:gson:2.8.0'
 }

+ 10 - 0
library/src/main/java/com/common/library/Constants.java

@@ -0,0 +1,10 @@
+package com.common.library;
+
+/**
+ * 作者:fuchangle on 2018/2/12 18:04
+ */
+
+public class Constants {
+
+    public static boolean DEVELOP_MODE = true;
+}

+ 13 - 0
library/src/main/java/com/common/library/okhttp/OkHttpUtils.java

@@ -10,6 +10,7 @@ import com.common.library.okhttp.builder.PostFileBuilder;
 import com.common.library.okhttp.builder.PostFormBuilder;
 import com.common.library.okhttp.builder.PostStringBuilder;
 import com.common.library.okhttp.callback.Callback;
+import com.common.library.okhttp.log.LoggerInterceptor;
 import com.common.library.okhttp.request.RequestCall;
 import com.common.library.okhttp.utils.Platform;
 import okhttp3.Call;
@@ -55,6 +56,18 @@ public class OkHttpUtils
         return mInstance;
     }
 
+    /**
+     * showResponse may cause error, but you can try .
+     *
+     * @param tag
+     * @param showResponse
+     * @return
+     */
+    public OkHttpUtils debug(String tag, boolean showResponse) {
+        mOkHttpClient = getOkHttpClient().newBuilder().addInterceptor(new LoggerInterceptor(tag, showResponse)).build();
+        return this;
+    }
+
     public static OkHttpUtils getInstance()
     {
         return initClient(null);

+ 7 - 0
library/src/main/java/com/common/library/okhttp/builder/PostFormBuilder.java

@@ -1,11 +1,14 @@
 package com.common.library.okhttp.builder;
 
+import android.util.Log;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.common.library.Constants;
 import com.common.library.okhttp.request.PostFormRequest;
 import com.common.library.okhttp.request.RequestCall;
 
@@ -19,6 +22,10 @@ public class PostFormBuilder extends OkHttpRequestBuilder<PostFormBuilder> imple
     @Override
     public RequestCall build()
     {
+        if(Constants.DEVELOP_MODE){
+            Log.i("okhttp",new StringBuilder("url= ").append(url).append("?")
+                    .append(params).toString());
+        }
         return new PostFormRequest(url, tag, params, headers, files,id).build();
     }
 

+ 8 - 17
library/src/main/java/com/common/library/okhttp/log/LoggerInterceptor.java

@@ -55,11 +55,6 @@ public class LoggerInterceptor implements Interceptor
             Log.e(tag, "========response'log=======");
             Response.Builder builder = response.newBuilder();
             Response clone = builder.build();
-            Log.e(tag, "url : " + clone.request().url());
-            Log.e(tag, "code : " + clone.code());
-            Log.e(tag, "protocol : " + clone.protocol());
-            if (!TextUtils.isEmpty(clone.message()))
-                Log.e(tag, "message : " + clone.message());
 
             if (showResponse)
             {
@@ -69,23 +64,20 @@ public class LoggerInterceptor implements Interceptor
                     MediaType mediaType = body.contentType();
                     if (mediaType != null)
                     {
-                        Log.e(tag, "responseBody's contentType : " + mediaType.toString());
                         if (isText(mediaType))
                         {
                             String resp = body.string();
-                            Log.e(tag, "responseBody's content : " + resp);
+                            Log.i(tag, "responseBody's content : " + resp);
 
                             body = ResponseBody.create(mediaType, resp);
                             return response.newBuilder().body(body).build();
                         } else
                         {
-                            Log.e(tag, "responseBody's content : " + " maybe [file part] , too large too print , ignored!");
                         }
                     }
                 }
             }
 
-            Log.e(tag, "========response'log=======end");
         } catch (Exception e)
         {
 //            e.printStackTrace();
@@ -101,12 +93,12 @@ public class LoggerInterceptor implements Interceptor
             String url = request.url().toString();
             Headers headers = request.headers();
 
-            Log.e(tag, "========request'log=======");
-            Log.e(tag, "method : " + request.method());
-            Log.e(tag, "url : " + url);
+            Log.i(tag, "========request'log=======");
+            Log.i(tag, "method : " + request.method());
+            Log.i(tag, "url : " + url);
             if (headers != null && headers.size() > 0)
             {
-                Log.e(tag, "headers : " + headers.toString());
+                Log.i(tag, "headers : " + headers.toString());
             }
             RequestBody requestBody = request.body();
             if (requestBody != null)
@@ -114,17 +106,16 @@ public class LoggerInterceptor implements Interceptor
                 MediaType mediaType = requestBody.contentType();
                 if (mediaType != null)
                 {
-                    Log.e(tag, "requestBody's contentType : " + mediaType.toString());
+                    Log.i(tag, "requestBody's contentType : " + mediaType.toString());
                     if (isText(mediaType))
                     {
-                        Log.e(tag, "requestBody's content : " + bodyToString(request));
+                        Log.i(tag, "requestBody's content : " + bodyToString(request));
                     } else
                     {
-                        Log.e(tag, "requestBody's content : " + " maybe [file part] , too large too print , ignored!");
+                        Log.i(tag, "requestBody's content : " + " maybe [file part] , too large too print , ignored!");
                     }
                 }
             }
-            Log.e(tag, "========request'log=======end");
         } catch (Exception e)
         {
 //            e.printStackTrace();