|
@@ -2,10 +2,13 @@ package com.mylove.okhttp;
|
|
|
|
|
|
import android.Manifest;
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Environment;
|
|
|
import android.util.Base64;
|
|
|
import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
@@ -23,6 +26,7 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.security.MessageDigest;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -40,79 +44,127 @@ public class MainActivity extends AppCompatActivity {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
// setContentView(R.layout.notification_contentview);
|
|
|
setContentView(R.layout.activity_main);
|
|
|
+// Jlog.d(MD5Utils.MD5Encode("123456"));
|
|
|
+// Jlog.d(encrypt("123456" + null));
|
|
|
+// Jlog.d(encrypt("123456"));
|
|
|
+// Jlog.d(getMd5_16("123456"));
|
|
|
+// Jlog.d(encrypt32("123456"));
|
|
|
+// Jlog.d(encryption("123456"));
|
|
|
+//
|
|
|
+// Jlog.d(string2MD5("123456"));
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ Jlog.d(MD5Utils.MD5Encode("8523697410hijklm" + MD5Utils.mapSort(map) + "1679铆风58611478"));
|
|
|
+
|
|
|
+
|
|
|
findViewById(R.id.but).setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
+ PermissionHelper.destroy();
|
|
|
PermissionHelper.with(MainActivity.this)
|
|
|
.setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
|
.request(new PermissionCallBack() {
|
|
|
@Override
|
|
|
public void onSuccess() {
|
|
|
-// Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
|
|
|
-// startActivity(intent);
|
|
|
- upload();
|
|
|
+ Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
|
|
|
+ startActivity(intent);
|
|
|
+// upload2();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
-// OkHttpUtil.getInstance(this).url("http://apitest.yanyi.online/app/update").getText(null).async(new OnOkHttpListener<Object>() {
|
|
|
-// @Override
|
|
|
-// public void onCompleted() {
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onSuccess(Object message) {
|
|
|
-// Jlog.d(message);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onFailure(Throwable t) {
|
|
|
-//
|
|
|
-// }
|
|
|
-// });
|
|
|
+ }
|
|
|
|
|
|
-// init();
|
|
|
-// PermissionHelper.getInstance(this).hasPermission(0x11, new PermissionCallBack() {
|
|
|
-// @Override
|
|
|
-// public void onPermissionSuccess(int permissionCode) {
|
|
|
-// downloadAPK();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onPermissionFailure(FailureMsg failureMsg) {
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onPermissionComplete(int permissionCode) {
|
|
|
-//
|
|
|
-// }
|
|
|
-// }, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
-// permissionHelper = new PermissionHelper(this, strings);
|
|
|
-// permissionHelper.hasPermission(new PermissionHelper.OnPermissionListener() {
|
|
|
-// @Override
|
|
|
-// public void onAllPermissionSuccess() {
|
|
|
-//// init();
|
|
|
-// downloadAPK();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onAllPermissionFailure() {
|
|
|
-//
|
|
|
-// }
|
|
|
-// });
|
|
|
-// String str = "<html></html>";
|
|
|
-// try {
|
|
|
-//// JSONObject jsonObject = new JSONObject(str);
|
|
|
-// JsonElement jsonParser = JsonParser.parseString(str);
|
|
|
-// Jlog.v(jsonParser.isJsonArray());
|
|
|
-// Jlog.v(jsonParser.isJsonObject());
|
|
|
-// Jlog.v(jsonParser.isJsonPrimitive());
|
|
|
-// Jlog.v(jsonParser.isJsonNull());
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
+ public String encryption(String plainText) {
|
|
|
+ String md5 = new String();
|
|
|
+ try {
|
|
|
+ MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
+ md.update(plainText.getBytes());
|
|
|
+ byte b[] = md.digest();
|
|
|
+
|
|
|
+ int i;
|
|
|
+
|
|
|
+ StringBuffer buf = new StringBuffer("");
|
|
|
+ for (int offset = 0; offset < b.length; offset++) {
|
|
|
+ i = b[offset];
|
|
|
+ if (i < 0)
|
|
|
+ i += 256;
|
|
|
+ if (i < 16)
|
|
|
+ buf.append("0");
|
|
|
+ buf.append(Integer.toHexString(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ md5 = buf.toString();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return md5;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getMd5_16(String string) {
|
|
|
+ return encrypt32(string).substring(8, 24);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String encrypt32(String encryptStr) {
|
|
|
+ MessageDigest md5;
|
|
|
+ try {
|
|
|
+ md5 = MessageDigest.getInstance("MD5");
|
|
|
+ byte[] md5Bytes = md5.digest(encryptStr.getBytes());
|
|
|
+ StringBuffer hexValue = new StringBuffer();
|
|
|
+ for (int i = 0; i < md5Bytes.length; i++) {
|
|
|
+ int val = ((int) md5Bytes[i]) & 0xff;
|
|
|
+ if (val < 16)
|
|
|
+ hexValue.append("0");
|
|
|
+ hexValue.append(Integer.toHexString(val));
|
|
|
+ }
|
|
|
+ encryptStr = hexValue.toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return encryptStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String md532(String source) {
|
|
|
+ char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
|
+ try {
|
|
|
+ byte[] strTemp = source.getBytes("UTF-8");
|
|
|
+
|
|
|
+ MessageDigest mdTemp = MessageDigest.getInstance("MD5");
|
|
|
+ mdTemp.update(strTemp);
|
|
|
+ byte[] md = mdTemp.digest();
|
|
|
+ int j = md.length;
|
|
|
+ char[] str = new char[j * 2];
|
|
|
+ int k = 0;
|
|
|
+ for (int i = 0; i < j; i++) {
|
|
|
+ byte b = md[i];
|
|
|
+
|
|
|
+ str[(k++)] = hexDigits[(b >> 4 & 0xF)];
|
|
|
+ str[(k++)] = hexDigits[(b & 0xF)];
|
|
|
+ }
|
|
|
+ return new String(str);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final String slat = "&%5123***&&%%$$#@";
|
|
|
+
|
|
|
+ public static String encrypt(String dataStr) {
|
|
|
+ try {
|
|
|
+ dataStr = dataStr + slat;
|
|
|
+ MessageDigest m = MessageDigest.getInstance("MD5");
|
|
|
+ m.update(dataStr.getBytes("UTF8"));
|
|
|
+ byte s[] = m.digest();
|
|
|
+ String result = "";
|
|
|
+ for (int i = 0; i < s.length; i++) {
|
|
|
+ result += Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
public void onClick(View view) {
|
|
@@ -125,25 +177,68 @@ public class MainActivity extends AppCompatActivity {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void upload2() {
|
|
|
+ String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/WeiXin/mmexport1679542887693.jpg";
|
|
|
+ File file = new File(path);
|
|
|
+ ImageView img = findViewById(R.id.img);
|
|
|
+ Bitmap bitmap = BitmapFactory.decodeFile(path);
|
|
|
+ img.setImageBitmap(bitmap);
|
|
|
+
|
|
|
+
|
|
|
+ String timestamp = System.currentTimeMillis() + "";
|
|
|
+ Map<String, Object> oMap = new HashMap<>();
|
|
|
+ oMap.put("yxdm", "123456");
|
|
|
+ oMap.put("sfzh", "139925199810233546");
|
|
|
+ String sign = MD5Utils.MD5Encode("8523697410hijklm" + sign2(oMap) + timestamp);
|
|
|
+// String sign = MD5Utils.MD5Encode("8523697410hijklm" + MD5Utils.mapSort(oMap) + timestamp);
|
|
|
+ Jlog.d(sign);
|
|
|
+ oMap.put("sign", sign);
|
|
|
+ oMap.put("timestamp", timestamp);
|
|
|
+ oMap.put("file", file);
|
|
|
+ for (Map.Entry<String, Object> entry : oMap.entrySet()) {
|
|
|
+ if (entry.getValue() instanceof File) {
|
|
|
+ Jlog.d(entry.getKey() + "=" + ((File) entry.getValue()).getName());
|
|
|
+ } else {
|
|
|
+ Jlog.d(entry.getKey() + "=" + entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ OkHttpUtil.getInstance(this).url("https://mp.idimage.com.cn/expo-bossapi/studentInfo/upload").postFileText(oMap).async(new OnOkHttpListener<Object>() {
|
|
|
+ @Override
|
|
|
+ public void onCompleted() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object message) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(Throwable t) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private void upload() {
|
|
|
String path = Environment.getExternalStorageDirectory() + "/DCIM/camera/IMG_20190620_082204.jpg";
|
|
|
String path1 = Environment.getExternalStorageDirectory() + "/tencent/micromsg/weixin/mmexport1528644702092.jpg";
|
|
|
File file = new File(path);
|
|
|
File file1 = new File(path1);
|
|
|
- Map<Object, Object> oMap = new HashMap<>();
|
|
|
- oMap.put("sn", "2023022100001_孟*杰_0034");
|
|
|
+ Map<String, Object> oMap = new HashMap<>();
|
|
|
+ oMap.put("sn", "2023022100001");
|
|
|
oMap.put("device_no", "123456");
|
|
|
oMap.put("appid", "37bU34uZPTUjzGZTsZ8eSh");
|
|
|
oMap.put("timestamp", System.currentTimeMillis() / 1000 + "");
|
|
|
oMap.put("sign", sign(oMap));
|
|
|
oMap.put("origin_image", fileToBase64(file));
|
|
|
oMap.put("photo_image", fileToBase64(file1));
|
|
|
- for (Map.Entry<Object, Object> entry : oMap.entrySet()) {
|
|
|
- if (entry.getValue().toString().length() <= 10) {
|
|
|
+ for (Map.Entry<String, Object> entry : oMap.entrySet()) {
|
|
|
+ if (entry.getValue().toString().length() <= 100) {
|
|
|
Jlog.d(entry.getKey() + "=" + entry.getValue());
|
|
|
|
|
|
} else {
|
|
|
- Jlog.d(entry.getKey() + "=" + (entry.getValue().toString().substring(0, 20)));
|
|
|
+ Jlog.d(entry.getKey() + "=" + (entry.getValue().toString().substring(0, 100)));
|
|
|
}
|
|
|
}
|
|
|
OkHttpUtil.getInstance(this).url("https://opend.icaiji.com.cn/wxapp/v6/photo").postText(null, oMap).async(new OnOkHttpListener<Object>() {
|
|
@@ -164,15 +259,23 @@ public class MainActivity extends AppCompatActivity {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private String sign(Map<Object, Object> oMap) {
|
|
|
+ private String sign(Map<String, Object> oMap) {
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
- for (Map.Entry<Object, Object> entry : oMap.entrySet()) {
|
|
|
- map.put(entry.getKey().toString(), entry.getValue().toString());
|
|
|
+ for (Map.Entry<String, Object> entry : oMap.entrySet()) {
|
|
|
+ map.put(entry.getKey(), entry.getValue().toString());
|
|
|
}
|
|
|
map.put("secret", "3sx9NNhVGEEEouhoenA5aJ");
|
|
|
return MD5Utils.getSignToken(map);
|
|
|
}
|
|
|
|
|
|
+ private String sign2(Map<String, Object> oMap) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ for (Map.Entry<String, Object> entry : oMap.entrySet()) {
|
|
|
+ map.put(entry.getKey().toString(), entry.getValue().toString());
|
|
|
+ }
|
|
|
+ return MD5Utils.getSignToken(map);
|
|
|
+ }
|
|
|
+
|
|
|
private String fileToBase64(File file) {
|
|
|
String base64 = null;
|
|
|
InputStream in = null;
|
|
@@ -197,13 +300,13 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
private void init() {
|
|
|
String url = "http://test.zhcjrwang.com/api/Test/Index";
|
|
|
- Map<Object, Object> headerMap = new HashMap<>();
|
|
|
+ Map<String, Object> headerMap = new HashMap<>();
|
|
|
headerMap.put("app_key", "XiangKeLai");
|
|
|
String timeStamp = DateUtil.timeStamp();
|
|
|
headerMap.put("timestamp", timeStamp);
|
|
|
headerMap.put("sign", ("XiangKeLai1" + timeStamp).toUpperCase());
|
|
|
Jlog.v(headerMap);
|
|
|
- Map<Object, Object> bodyMap = new HashMap<>();
|
|
|
+ Map<String, Object> bodyMap = new HashMap<>();
|
|
|
bodyMap.put("data", "+fAFfMCGsMZqeS+gyrZm1A==");
|
|
|
Jlog.v(bodyMap);
|
|
|
OkHttpUtil.getInstance(this).url(url, true).postText(headerMap, bodyMap).async(new OnOkHttpListener<Object>() {
|