登录功能
This commit is contained in:
parent
1f587d2d93
commit
cdd28fae20
|
|
@ -100,6 +100,10 @@
|
|||
</activity>
|
||||
|
||||
<!-- 当前使用的activity-->
|
||||
<activity
|
||||
android:name="com.bonus.canteen.activity.LoginActivity"
|
||||
android:configChanges="keyboardHidden|keyboard"
|
||||
android:windowSoftInputMode="adjustPan|stateHidden" />
|
||||
<activity
|
||||
android:name="com.bonus.canteen.activity.OperationActivity"
|
||||
android:configChanges="keyboardHidden|keyboard"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,158 @@
|
|||
package com.bonus.canteen.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.bonus.canteen.constants.AppConstants;
|
||||
import com.bonus.canteen.core.BaseActivity;
|
||||
import com.bonus.canteen.db.AppDatabase;
|
||||
import com.bonus.canteen.db.entity.base.LoginInfo;
|
||||
import com.bonus.canteen.utils.OkHttpService;
|
||||
import com.bonus.canteen.utils.ThreadPoolManager;
|
||||
import com.bonus.canteen.utils.WorkConfig;
|
||||
import com.xuexiang.xui.XUI;
|
||||
import com.xuexiang.xui.utils.XToastUtils;
|
||||
|
||||
import org.easydarwin.easypusher.R;
|
||||
import org.easydarwin.easypusher.databinding.ActivityLoginBinding;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class LoginActivity extends BaseActivity<ActivityLoginBinding> {
|
||||
public final OkHttpService service = new OkHttpService();
|
||||
|
||||
@Override
|
||||
protected ActivityLoginBinding viewBindingInflate(LayoutInflater inflater) {
|
||||
return ActivityLoginBinding.inflate(inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
XUI.initTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setupImmersiveMode();
|
||||
initView();
|
||||
}
|
||||
private void setupImmersiveMode() {
|
||||
View decorView = getWindow().getDecorView();
|
||||
int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||
}
|
||||
decorView.setSystemUiVisibility(flags);
|
||||
}
|
||||
public void initView() {
|
||||
initListener();
|
||||
}
|
||||
|
||||
public void initListener() {
|
||||
findViewById(R.id.btn_login).setOnClickListener(v -> {
|
||||
String userName = binding.etUsername.getText().toString();
|
||||
String password = binding.etPassword.getText().toString();
|
||||
checkParameters(userName,password);
|
||||
login(userName, password);
|
||||
});
|
||||
binding.tvForgetPassword.setOnClickListener(view -> XToastUtils.warning("请在后台管理端重置密码!"));
|
||||
}
|
||||
|
||||
private void login(String userName, String password) {
|
||||
ThreadPoolManager.getExecutor().execute(() -> {
|
||||
try {
|
||||
String url = WorkConfig.getPrefixesUrl() + "/auth/login";
|
||||
org.json.JSONObject json = new org.json.JSONObject();
|
||||
json.put("username", userName);
|
||||
json.put("password", password);
|
||||
json.put("verificationCode", "");
|
||||
json.put("code", "");
|
||||
json.put("phoneUuid", "");
|
||||
json.put("uuid", "");
|
||||
json.put("loginType", "USERNAME_PASSWORD");
|
||||
String jsonString = json.toString();
|
||||
Log.i("getPersonMessage jsonString", jsonString);
|
||||
// 定义 JSON 的 MediaType
|
||||
MediaType mediaType = MediaType.parse(AppConstants.MEDIA_TYPE);
|
||||
// 创建 RequestBody
|
||||
RequestBody body = RequestBody.create(mediaType, jsonString);
|
||||
String result = service.httpLoginPost(url, body, this);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
if (jsonObject.getIntValue("code") == 500){
|
||||
runOnUiThread(() -> XToastUtils.error(jsonObject.getString("msg")));
|
||||
return;
|
||||
}
|
||||
runOnUiThread(() -> XToastUtils.success("登录成功"));
|
||||
String data = jsonObject.getString("data");
|
||||
JSONObject dataJson = JSONObject.parseObject(data);
|
||||
AppDatabase.getDatabase(this).loginInfoDao().deleteAll();
|
||||
LoginInfo loginInfo = new LoginInfo();
|
||||
loginInfo.setUserName(userName);
|
||||
loginInfo.setUserPwd(password);
|
||||
loginInfo.setUserId("-1"); // 假设用户ID为1,实际应用中应从服务器获取
|
||||
loginInfo.setPhone("-1"); // 假设手机号为1234567890,实际应用中应从服务器获取
|
||||
loginInfo.setToken(dataJson.getString("access_token")); // 假设令牌为sample_token,实际应用中应从服务器获取
|
||||
AppDatabase.getDatabase(this).loginInfoDao().insert(loginInfo);
|
||||
startActivity(new Intent(this, InitializationActivity.class));
|
||||
finish();
|
||||
} else {
|
||||
XToastUtils.error("登录失败,请检查用户名和密码");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("LoginActivity", "Login error: ", e);
|
||||
XToastUtils.error("登录异常,请稍后再试");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkParameters(String userName, String password) {
|
||||
if (userName.isEmpty()) {
|
||||
XToastUtils.warning("用户名不能为空");
|
||||
return;
|
||||
}
|
||||
if (password.isEmpty()) {
|
||||
XToastUtils.warning("登录密码不能为空");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
View v = getCurrentFocus();
|
||||
if (v instanceof EditText) {
|
||||
int[] location = new int[2];
|
||||
v.getLocationOnScreen(location);
|
||||
float x = ev.getRawX() + v.getLeft() - location[0];
|
||||
float y = ev.getRawY() + v.getTop() - location[1];
|
||||
if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom()) {
|
||||
hideKeyboard(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
private void hideKeyboard(View view) {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1041,6 +1041,10 @@ public class OperationActivity extends BaseActivity<ActivityCanteenOperationBind
|
|||
binding.loginName.setText("未登录");
|
||||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.login_out_success));
|
||||
});
|
||||
//退出到登录页
|
||||
Intent intent = new Intent(OperationActivity.this, LoginActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
});
|
||||
dialog.dismiss();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -85,9 +85,9 @@ public class SplashActivity extends BaseSplashActivity implements CancelAdapt {
|
|||
}
|
||||
private void navigateToNextPage() {
|
||||
if (TokenUtils.hasToken()) {
|
||||
ActivityUtils.startActivity(InitializationActivity.class);
|
||||
ActivityUtils.startActivity(LoginActivity.class);
|
||||
} else {
|
||||
ActivityUtils.startActivity(InitializationActivity.class);
|
||||
ActivityUtils.startActivity(LoginActivity.class);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ public class MachineSaleActivity extends BaseActivity<MachineSaleOrderMainBindi
|
|||
tvMachineDiscountMoney.setText(Utils.conversionMoney(bean.getDiscountAmount(),true)+" 元");
|
||||
tvMachineRealMoney.setText(Utils.conversionMoney(bean.getAmountDue(),true)+" 元");
|
||||
tvRefundNum.setText(Utils.conversionMoney(bean.getRefundNum(),false));
|
||||
tvRefundMoney.setText(bean.getRefundAmount()+" 元");
|
||||
tvRefundMoney.setText(Utils.conversionMoney(bean.getAmountDue(),true)+" 元");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class OrderAdapter extends BaseAdapter {
|
|||
holder.machinePersonName.setText(bean.getUserName());
|
||||
holder.machineTotalAmount.setText(new BigDecimal(bean.getAmountDue()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP) + "");
|
||||
holder.machineRealAmount.setText(new BigDecimal(bean.getAmountDue()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP) + "");
|
||||
holder.refundAmount.setText(bean.getRefundAmount());
|
||||
holder.refundAmount.setText(new BigDecimal(bean.getRefundAmount()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP) + "");
|
||||
|
||||
if ("1".equals(bean.getPayStatus())) {
|
||||
if ("1".equals(bean.getIsOnline()) || "2".equals(bean.getIsOnline())) {
|
||||
|
|
@ -126,7 +126,7 @@ public class OrderAdapter extends BaseAdapter {
|
|||
holder.machineOrState.setTextColor(Color.RED);
|
||||
}
|
||||
} else if ("4".equals(bean.getPayStatus()) || "5".equals(bean.getPayStatus())) {
|
||||
holder.machineOrState.setText("【已退单】");
|
||||
holder.machineOrState.setText("【全退款】");
|
||||
if ("5".equals(bean.getPayStatus())) {
|
||||
if (bean.getRefundNum().equals(bean.getNum())){
|
||||
holder.machineOrState.setText("【全退款】");
|
||||
|
|
|
|||
|
|
@ -38,6 +38,9 @@ public class LoginInfo {
|
|||
@ColumnInfo
|
||||
private String userPwd;
|
||||
|
||||
@ColumnInfo
|
||||
private String token; // 登录令牌
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
@ -77,4 +80,10 @@ public class LoginInfo {
|
|||
public void setUserPwd(String userPwd) {
|
||||
this.userPwd = userPwd;
|
||||
}
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,7 +177,6 @@ public class UpdateBasicData {
|
|||
RequestBody body = RequestBody.create(mediaType, jsonString);
|
||||
String url = WorkConfig.getBaseUrl() + UrlConfig.GET_FACE_FEATURE_LIST;
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader("Authorization", OkHttpService.getToken())
|
||||
.post(body).build();
|
||||
try {
|
||||
String result = service.httpPost(url, body, context, request);
|
||||
|
|
|
|||
|
|
@ -18,20 +18,22 @@
|
|||
package com.bonus.canteen.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.bonus.canteen.activity.LoginActivity;
|
||||
import com.bonus.canteen.db.AppDatabase;
|
||||
import com.ccb.facedevice.sdk.utils.AppUtil;
|
||||
import com.xuexiang.xui.utils.XToastUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
|
|
@ -43,11 +45,6 @@ public class OkHttpService {
|
|||
|
||||
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
|
||||
private static String token ="eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjozNzkyNTg1Mjk2NDQ1NDgwOTYsInVzZXJfa2V5IjoiOTk2MjRlZTgtM2YwMy00OWFhLThlNTYtMTY1OTAxMGRlZmIwIiwidXNlcm5hbWUiOiJkZTU4ZjYzNjU3Y2RhOGVkYjZiZTg3NTExMGUyMDNmNCJ9.lak39NWRG10Kg1ly21vtRpRc8eT1wGwTVkNO_HhHKgC78pI0EGjqALiVQWalrmJgp8vlGGyfu65bMShYi5jlrw";
|
||||
|
||||
public static String getToken(){
|
||||
return token;
|
||||
}
|
||||
private volatile static OkHttpClient client;
|
||||
|
||||
public String encrypt(String v) {
|
||||
|
|
@ -77,147 +74,21 @@ public class OkHttpService {
|
|||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public String httpGet(String url) {
|
||||
try {
|
||||
URLEncoder.encode(url, "UTF-8");
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(30000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(10000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
return response.body().string();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String httpGets(String url) {
|
||||
try {
|
||||
URLEncoder.encode(url, "UTF-8");
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(30000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(10000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader("token",token)
|
||||
.build();
|
||||
Response response = client.newCall(request).execute();
|
||||
int code =response.code();
|
||||
if (code==200){
|
||||
return response.body().string();
|
||||
}else {
|
||||
return "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public String httpGetss(String url, FormBody body) {
|
||||
try {
|
||||
URLEncoder.encode(url, "UTF-8");
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(30000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(10000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader("token",token)
|
||||
.post(body)
|
||||
.build();
|
||||
Response response = client.newCall(request).execute();
|
||||
int code =response.code();
|
||||
if (code==200){
|
||||
return response.body().string();
|
||||
}else {
|
||||
return "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String httpLoginPost(String url, FormBody body) {
|
||||
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(10000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(10000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder().url(url).post(body).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
int statueCode = response.code();
|
||||
|
||||
if (statueCode == 200) {
|
||||
String json = response.body().string();
|
||||
Log.e(TAG, "json=" + response.toString());
|
||||
if (!StringHelper.isEmpty(json) && json.contains("OK")) {
|
||||
return json;
|
||||
}
|
||||
return json;
|
||||
} else {
|
||||
return statueCode+"";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, e.toString());
|
||||
//网络请求超时
|
||||
return "2021";
|
||||
}
|
||||
}
|
||||
|
||||
public String httpPost(String url, FormBody body, Context context) {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader("Authorization", token)
|
||||
.addHeader("machine-sn","2AD2435000620350")
|
||||
.post(body).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
int statueCode = response.code();
|
||||
Log.e(TAG, statueCode + "");
|
||||
if (statueCode == 200) {
|
||||
String json = response.body().string();
|
||||
Log.e(TAG, "json=" + response.toString());
|
||||
if (!StringHelper.isEmpty(json) && json.contains("OK")) {
|
||||
return json;
|
||||
}
|
||||
return json;
|
||||
}else if (statueCode==401){
|
||||
ThreadPoolManager.executeInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 在这里执行UI操作,如创建并显示AlertDialog
|
||||
// 使用JSON解析库解析主体内容
|
||||
JSONObject jsonResponse = null;
|
||||
try {
|
||||
String responseBody = response.body().string();
|
||||
jsonResponse = new JSONObject(responseBody);
|
||||
String message = jsonResponse.getString("message");
|
||||
if (message.contains("过期")){
|
||||
XToastUtils.warning("登录过期,请重新登录");
|
||||
}
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, e.toString());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public String httpPost(String url, RequestBody body, Context context,Request request) {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
Request.Builder builder = request.newBuilder().url(url).post(body);
|
||||
// 保留原有请求头
|
||||
for (String name : request.headers().names()) {
|
||||
for (String value : request.headers(name)) {
|
||||
builder.addHeader(name, value);
|
||||
}
|
||||
}
|
||||
builder.addHeader("machine-sn", Objects.requireNonNull(AppUtil.getSn(context)));
|
||||
builder.addHeader("Authorization", AppDatabase.getDatabase(context).loginInfoDao().getLoginInfoOne().getToken());
|
||||
request = builder.build();
|
||||
Response response = client.newCall(request).execute();
|
||||
int statueCode = response.code();
|
||||
Log.e(TAG, statueCode + "");
|
||||
|
|
@ -229,24 +100,24 @@ public class OkHttpService {
|
|||
}
|
||||
return json;
|
||||
}else if (statueCode==401){
|
||||
ThreadPoolManager.executeInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 在这里执行UI操作,如创建并显示AlertDialog
|
||||
// 使用JSON解析库解析主体内容
|
||||
JSONObject jsonResponse = null;
|
||||
try {
|
||||
String responseBody = response.body().string();
|
||||
jsonResponse = new JSONObject(responseBody);
|
||||
String message = jsonResponse.getString("message");
|
||||
if (message.contains("过期")){
|
||||
XToastUtils.warning("登录过期,请重新登录");
|
||||
}
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
ThreadPoolManager.executeInUIThread(() -> {
|
||||
// 在这里执行UI操作,如创建并显示AlertDialog
|
||||
// 使用JSON解析库解析主体内容
|
||||
JSONObject jsonResponse = null;
|
||||
try {
|
||||
String responseBody = response.body().string();
|
||||
jsonResponse = new JSONObject(responseBody);
|
||||
String message = jsonResponse.getString("message");
|
||||
if (message.contains("过期")){
|
||||
XToastUtils.warning("登录过期,请重新登录");
|
||||
Intent intent = new Intent(context, LoginActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -257,14 +128,61 @@ public class OkHttpService {
|
|||
}
|
||||
|
||||
public String httpPost(String url, RequestBody body, Context context) {
|
||||
try {
|
||||
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader("machine-sn", Objects.requireNonNull(AppUtil.getSn(context)))
|
||||
.addHeader("Authorization", AppDatabase.getDatabase(context).loginInfoDao().getLoginInfoOne().getToken())
|
||||
.post(body).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
int statueCode = response.code();
|
||||
Log.e(TAG, statueCode + "");
|
||||
if (statueCode == 200) {
|
||||
String json = response.body().string();
|
||||
Log.e(TAG, "json=" + response.toString());
|
||||
if (!StringHelper.isEmpty(json) && json.contains("OK")) {
|
||||
return json;
|
||||
}
|
||||
return json;
|
||||
}else if (statueCode==401){
|
||||
ThreadPoolManager.executeInUIThread(() -> {
|
||||
// 在这里执行UI操作,如创建并显示AlertDialog
|
||||
// 使用JSON解析库解析主体内容
|
||||
JSONObject jsonResponse = null;
|
||||
try {
|
||||
String responseBody = response.body().string();
|
||||
jsonResponse = new JSONObject(responseBody);
|
||||
String message = jsonResponse.getString("message");
|
||||
if (message.contains("过期")){
|
||||
XToastUtils.warning("登录过期,请重新登录");
|
||||
Intent intent = new Intent(context, LoginActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, e.toString());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public String httpLoginPost(String url, RequestBody body, Context context) {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader("Authorization", token)
|
||||
.addHeader("machine-sn","2AD2428001118585")
|
||||
.post(body).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
|
|
@ -304,132 +222,6 @@ public class OkHttpService {
|
|||
}
|
||||
return "";
|
||||
}
|
||||
public String httpPost(String url, FormBody body) {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder().url(url)
|
||||
.post(body).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
int statueCode = response.code();
|
||||
Log.e(TAG, statueCode + "");
|
||||
if (statueCode == 200) {
|
||||
String json = response.body().string();
|
||||
Log.e(TAG, "json=" + response.toString());
|
||||
if (!StringHelper.isEmpty(json) && json.contains("OK")) {
|
||||
return json;
|
||||
}
|
||||
return json;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, e.toString());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public String httpPostNoToken(String url, FormBody body) {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder().url(url)
|
||||
.post(body).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
int statueCode = response.code();
|
||||
Log.e(TAG, statueCode + "");
|
||||
if (statueCode == 200) {
|
||||
String json = response.body().string();
|
||||
Log.e(TAG, "json=" + response.toString());
|
||||
if (!StringHelper.isEmpty(json) && json.contains("OK")) {
|
||||
return json;
|
||||
}
|
||||
return json;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, e.toString());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String httpFilePost(String url, MultipartBody body) {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader("token",token)
|
||||
.post(body).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
int statueCode = response.code();
|
||||
Log.e(TAG, "statueCode=" + statueCode);
|
||||
if (statueCode == 200) {
|
||||
String json = response.body().string();
|
||||
Log.e(TAG, "json=" + response.toString());
|
||||
if (!StringHelper.isEmpty(json) && json.contains("OK")) {
|
||||
return json;
|
||||
}
|
||||
return json;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, e.toString());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String httpFilePostNoToken(String url, MultipartBody body) {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(60000, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder().url(url)
|
||||
.post(body).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
int statueCode = response.code();
|
||||
Log.e(TAG, "statueCode=" + statueCode);
|
||||
if (statueCode == 200) {
|
||||
String json = response.body().string();
|
||||
Log.e(TAG, "json=" + response.toString());
|
||||
if (!StringHelper.isEmpty(json) && json.contains("OK")) {
|
||||
return json;
|
||||
}
|
||||
return json;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, e.toString());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String syncPost(String url, String json) {
|
||||
RequestBody body = RequestBody.create(JSON, json);
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
// .addHeader("key", "SonBianDian")
|
||||
.build();
|
||||
try {
|
||||
Response response = getInstance().newCall(request).execute();
|
||||
return response.body().string();
|
||||
} catch (Exception e) {
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private OkHttpClient getInstance() {
|
||||
if (client == null) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class WorkConfig {
|
|||
//本地
|
||||
// protected static String baseUrl = "http://192.168.0.34:48380/smart-canteen";
|
||||
// protected static String prefixesUrl = "http://192.168.0.34:48380";
|
||||
protected static String baseUrl = "http://192.168.0.244:48380/smart-canteen";
|
||||
protected static String baseUrl = "http://192.168.0.34:48380/smart-canteen";
|
||||
protected static String prefixesUrl = "http://192.168.0.34:48380";
|
||||
protected static String fileUrl = "http://192.168.0.244:48380/lnyst/";
|
||||
protected static String updateUrl = "https://www.baidu.com";
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ public class RabbitMqMqttHelper {
|
|||
.orderDetailsDao().getOrderInfoListByOrderId(orderId, dishesId);
|
||||
if (orderDetailsInfo != null) {
|
||||
BigDecimal price = new BigDecimal(orderDetailsInfo.getPrice());
|
||||
BigDecimal money = price.multiply(BigDecimal.valueOf(refundNum)).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal money = price.multiply(BigDecimal.valueOf(refundNum)).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP);
|
||||
refundMoney = refundMoney.add(money);
|
||||
// 更新订单详情状态
|
||||
AppDatabase.getDatabase(context).orderDetailsDao()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/xui_transparent"/>
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="#A2A2A2"/> <!-- 浅灰色 -->
|
||||
<corners android:radius="5dp"/>
|
||||
</shape>
|
||||
|
|
@ -411,6 +411,7 @@
|
|||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/keyboard_main"
|
||||
android:visibility="gone"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (C) 2019 xuexiangjys(xuexiangjys@163.com)
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
-->
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#909090"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="500dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:padding="50dp"
|
||||
android:background="@drawable/btn_border_bg"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:contentDescription="@string/image_desc"
|
||||
android:src="@drawable/ic_canteen"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="28sp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textFontWeight="1000"
|
||||
android:text="@string/app_name"/>
|
||||
<EditText
|
||||
android:id="@+id/et_username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:autofillHints=""
|
||||
android:maxLength="20"
|
||||
android:text="admin"
|
||||
android:hint="@string/login_username"
|
||||
android:inputType="textPersonName"
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/edit_text_bg"/>
|
||||
<EditText
|
||||
android:id="@+id/et_password"
|
||||
android:text="Bonus$2028"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:autofillHints=""
|
||||
android:hint="@string/login_password"
|
||||
android:inputType="textPassword"
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/edit_text_bg"/>
|
||||
<com.xuexiang.xui.widget.layout.XUIButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="@string/login_login"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp"
|
||||
android:backgroundTint="@color/color_blue"
|
||||
android:id="@+id/btn_login"/>
|
||||
<TextView
|
||||
android:id="@+id/tv_forget_password"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:text="@string/login_forgot_password"
|
||||
android:textColor="@color/color_blue"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
|
@ -175,4 +175,9 @@
|
|||
|
||||
|
||||
<string name="wait_for_payment">等待支付</string>
|
||||
<string name="login_username">请输入用户名</string>
|
||||
<string name="image_desc">图标</string>
|
||||
<string name="login_password">请输入登录密码</string>
|
||||
<string name="login_forgot_password">忘记密码?</string>
|
||||
<string name="login_login">登录</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in New Issue