Commit 81370b9f by YKai

feat:登录接口对接,动态更换网关,参数加密

parent d0225c89
...@@ -34,8 +34,8 @@ class LoginApiRequestUtil { ...@@ -34,8 +34,8 @@ class LoginApiRequestUtil {
/** /**
* 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定 * 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定
*/ */
fun checkPhoneStatus(map :Map<String,String>,phone: String, countryCode: String?): Observable<BaseResponse<ChcekPhoneResponeBean>> { fun checkPhoneStatus(phone: String, countryCode: String?): Observable<BaseResponse<ChcekPhoneResponeBean>> {
return getUserApi().checkPhoneStatus(map,phone, countryCode!!) return getUserApi().checkPhoneStatus(phone, countryCode!!)
} }
/** /**
......
package com.yidianling.user.http;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5 {
public static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
public static String toHexString(byte[] b) {
StringBuffer sb = new StringBuffer(b.length * 2);
for (int i = 0; i < b.length; i++) {
sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
sb.append(HEX_DIGITS[b[i] & 0x0f]);
}
return sb.toString();
}
/**
* md5加密字符串
*
* @param s
* @return
*/
public static String md5(String s) {
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
return toHexString(messageDigest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}
...@@ -194,7 +194,7 @@ interface UserApi { ...@@ -194,7 +194,7 @@ interface UserApi {
*/ */
@GET("login/v2/phone_detection") @GET("login/v2/phone_detection")
@Headers(YDL_DOMAIN+ YDL_DOMAIN_LOGIN_BASE_URL,LOGIN_USER_PORT) @Headers(YDL_DOMAIN+ YDL_DOMAIN_LOGIN_BASE_URL,LOGIN_USER_PORT)
fun checkPhoneStatus(@HeaderMap headMap:Map<String,String>,@Query("phone") phone: String, @Query("countryCode") countryCode: String): Observable<BaseResponse<ChcekPhoneResponeBean>> fun checkPhoneStatus(@Query("phone") phone: String, @Query("countryCode") countryCode: String): Observable<BaseResponse<ChcekPhoneResponeBean>>
/** /**
* 验证重置密码的短信验证码 * 验证重置密码的短信验证码
......
...@@ -118,8 +118,7 @@ public class AccountSettingActivity extends BaseActivity implements View.OnClick ...@@ -118,8 +118,7 @@ public class AccountSettingActivity extends BaseActivity implements View.OnClick
return; return;
} }
showProgressDialog(); showProgressDialog();
Map<String,String> map = EncryptionParams.getParams("/api/api/login/v2/phone_detection"); LoginApiRequestUtil.Companion.checkPhoneStatus(UserHelper.INSTANCE.getUserInfo().getUserInfo().getPhone(), UserHelper.INSTANCE.getUserInfo().getUserInfo().getCountry_code())
LoginApiRequestUtil.Companion.checkPhoneStatus(map,UserHelper.INSTANCE.getUserInfo().getUserInfo().getPhone(), UserHelper.INSTANCE.getUserInfo().getUserInfo().getCountry_code())
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(response -> { .subscribe(response -> {
......
...@@ -396,8 +396,7 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont ...@@ -396,8 +396,7 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
return@setOnClickListener return@setOnClickListener
} }
if (checkPhone()) { if (checkPhone()) {
val map = EncryptionParams.getParams("/api/api/login/v2/phone_detection") mPresenter.checkPhoneStatus(userPhoneNumber!!, countryCode!!, isUmengLoginState)
mPresenter.checkPhoneStatus(map,userPhoneNumber!!, countryCode!!, isUmengLoginState)
} }
} }
......
...@@ -97,7 +97,7 @@ interface ILoginContract { ...@@ -97,7 +97,7 @@ interface ILoginContract {
/** /**
* 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定 * 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定
*/ */
fun checkPhoneStatus(map: Map<String,String>,phone: String, countryCode: String, isBind: Boolean) fun checkPhoneStatus(phone: String, countryCode: String, isBind: Boolean)
/** /**
* 通过一键认证服务登陆 * 通过一键认证服务登陆
...@@ -120,7 +120,7 @@ interface ILoginContract { ...@@ -120,7 +120,7 @@ interface ILoginContract {
/** /**
* 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定 * 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定
*/ */
fun checkPhoneStatus(map: Map<String,String>,phone: String, countryCode: String): Observable<BaseResponse<ChcekPhoneResponeBean>> fun checkPhoneStatus(phone: String, countryCode: String): Observable<BaseResponse<ChcekPhoneResponeBean>>
/** /**
......
...@@ -48,8 +48,8 @@ class LoginModelImpl : ILoginContract.Model { ...@@ -48,8 +48,8 @@ class LoginModelImpl : ILoginContract.Model {
/** /**
* 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定 * 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定
*/ */
override fun checkPhoneStatus(map:Map<String,String>,phone: String, countryCode: String): Observable<BaseResponse<ChcekPhoneResponeBean>> { override fun checkPhoneStatus(phone: String, countryCode: String): Observable<BaseResponse<ChcekPhoneResponeBean>> {
return LoginApiRequestUtil.checkPhoneStatus(map,phone, countryCode) return LoginApiRequestUtil.checkPhoneStatus(phone, countryCode)
} }
/** /**
......
...@@ -131,9 +131,9 @@ class LoginPresenterImpl(view: ILoginContract.View) : BasePresenter<ILoginContra ...@@ -131,9 +131,9 @@ class LoginPresenterImpl(view: ILoginContract.View) : BasePresenter<ILoginContra
*@param isBind 是否是第三方登录成功后的绑定操作 *@param isBind 是否是第三方登录成功后的绑定操作
*/ */
@SuppressLint("CheckResult") @SuppressLint("CheckResult")
override fun checkPhoneStatus(map: Map<String,String>,phone: String, countryCode: String, isBind: Boolean) { override fun checkPhoneStatus(phone: String, countryCode: String, isBind: Boolean) {
mView.showLoading(true) mView.showLoading(true)
mModel.checkPhoneStatus(map,phone, countryCode) mModel.checkPhoneStatus(phone, countryCode)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
......
...@@ -2,11 +2,9 @@ package com.ydl.ydlcommon.base.config; ...@@ -2,11 +2,9 @@ package com.ydl.ydlcommon.base.config;
import android.os.Build; import android.os.Build;
import android.support.annotation.RequiresApi; import android.support.annotation.RequiresApi;
import android.util.Log;
import com.ydl.burypointlib.MD5Util; import com.ydl.burypointlib.MD5Util;
import com.ydl.ydlcommon.base.BaseApp; import com.ydl.ydlcommon.utils.LogUtil;
import com.yidianling.common.tools.RxAppTool;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
...@@ -22,29 +20,24 @@ import java.util.stream.Collectors; ...@@ -22,29 +20,24 @@ import java.util.stream.Collectors;
*/ */
public class EncryptionParams { public class EncryptionParams {
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
public static Map<String,String> getParams(String path){ public static String getSign(String path,String timestamp){
String timestamp = String.valueOf(System.currentTimeMillis()); //值应该为毫秒数的字符串形式
Map<String,String> map = new HashMap<>(); Map<String,String> map = new HashMap<>();
map.put("timestamp",timestamp); map.put("timestamp",timestamp);
map.put("path",path); map.put("path",path);
map.put("version", RxAppTool.getAppVersionName(BaseApp.Companion.getApp())); map.put("version", "1.0.0");
List<String> storedKeys = Arrays.stream(map.keySet() List<String> storedKeys = Arrays.stream(map.keySet()
.toArray(new String[]{})) .toArray(new String[]{}))
.sorted(Comparator.naturalOrder()) .sorted(Comparator.naturalOrder())
.collect(Collectors.toList()); .collect(Collectors.toList());
String sign = storedKeys.stream() String sign = storedKeys.stream()
.map(key -> String.join("", key, map.get(key))) .map(key -> key+map.get(key))
.collect(Collectors.joining()).trim() .collect(Collectors.joining()).trim()
.concat(HttpConfig.Companion.getENCRYPTION_APP_SECRET()); .concat(HttpConfig.Companion.getENCRYPTION_APP_SECRET());
LogUtil.e("sign",sign);
sign = MD5Util.md5(sign).toUpperCase(); sign = MD5Util.md5(sign).toUpperCase();
Log.e("sign",sign); LogUtil.e("sign",sign);
Map<String,String> headersMap = new HashMap<>(); return sign;
headersMap.put("appKey",HttpConfig.Companion.getENCRYPTION_APP_KEY());
headersMap.put("sign",sign);
headersMap.put("timestamp",timestamp);
return headersMap;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment