Merge remote-tracking branch 'OutDoor/secondaryExploit' into secondaryExploit

This commit is contained in:
wangdongsheng 2021-08-24 18:27:37 +08:00
commit d63b66eedf
14 changed files with 1075 additions and 60 deletions

View File

@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
//ndkVersion '23.0.7123448'
ndkVersion '23.0.7123448'
defaultConfig {
applicationId "com.navinfo.outdoor"

View File

@ -0,0 +1,87 @@
package com.navinfo.outdoor.activity;
import android.os.StrictMode;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
/**
* 获取token
*/
public class AuthService {
/**
* 获取权限token
* @return 返回示例
* {
* "access_token": "24.460da4889caad24cccdb1fea17221975.2592000.1491995545.282335-1234567",
* "expires_in": 2592000
* }
*/
public static String getAuth() {
// 官网获取的 API Key 更新为你注册的
String clientId = "iafhTwf6LnOMoYTiZQDlrKTu";
// 官网获取的 Secret Key 更新为你注册的
String clientSecret = "0d3yoIsrsrAspUMoyNkWeeqDTvxvg9QB";
return getAuth(clientId, clientSecret);
}
/**
* 获取API访问token
* 该token有一定的有效期需要自行管理当失效时需重新获取.
* @param ak - 百度云官网获取的 API Key
* @param sk - 百度云官网获取的 Securet Key
* @return assess_token 示例
* "24.460da4889caad24cccdb1fea17221975.2592000.1491995545.282335-1234567"
*/
public static String getAuth(String ak, String sk) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
// 获取token地址
String authHost = "https://aip.baidubce.com/oauth/2.0/token?";
String getAccessTokenUrl = authHost
// 1. grant_type为固定参数
+ "grant_type=client_credentials"
// 2. 官网获取的 API Key
+ "&client_id=" + ak
// 3. 官网获取的 Secret Key
+ "&client_secret=" + sk;
try {
URL realUrl = new URL(getAccessTokenUrl);
// 打开和URL之间的连接
HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
connection.setRequestMethod("POST");
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.err.println(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String result = "";
String line;
while ((line = in.readLine()) != null) {
result += line;
}
/**
* 返回结果示例
*/
System.err.println("result:" + result);
JSONObject jsonObject = new JSONObject(result);
String access_token = jsonObject.getString("access_token");
return access_token;
} catch (Exception e) {
System.err.printf("获取token失败");
e.printStackTrace(System.err);
}
return null;
}
}

View File

@ -0,0 +1,51 @@
package com.navinfo.outdoor.activity;
import com.navinfo.outdoor.api.Constant;
import com.navinfo.outdoor.base.Base64Util;
import com.navinfo.outdoor.http.HttpUtil;
import com.navinfo.outdoor.util.FileUtil;
import java.net.URLEncoder;
/**
* 银行卡识别
*/
public class BankCard {
/**
* 重要提示代码中所需工具类
* FileUtil,Base64Util,HttpUtil,GsonUtils请从
* https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
* https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
* https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
* https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
* 下载
*/
public static String bankCard() {
// 请求url
String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/bankcard";
try {
// 本地文件路径
String filePath = Constant.FILE_PATH;
byte[] imgData = FileUtil.readFileByBytes(filePath);
String imgStr = Base64Util.encode(imgData);
String imgParam = URLEncoder.encode(imgStr, "UTF-8");
String param = "image=" + imgParam;
// 注意这里仅为了简化编码每一次请求都去获取access_token线上环境access_token有过期时间 客户端可自行缓存过期后重新获取
String accessToken =AuthService.getAuth("iafhTwf6LnOMoYTiZQDlrKTu","0d3yoIsrsrAspUMoyNkWeeqDTvxvg9QB");
String result = HttpUtil.post(url, accessToken, param);
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
BankCard.bankCard();
}
}

View File

@ -0,0 +1,49 @@
package com.navinfo.outdoor.activity;
import com.navinfo.outdoor.api.Constant;
import com.navinfo.outdoor.base.Base64Util;
import com.navinfo.outdoor.http.HttpUtil;
import com.navinfo.outdoor.util.FileUtil;
import java.net.URLEncoder;
/**
* 身份证识别
*/
public class IdCard {
/**
* 重要提示代码中所需工具类
* FileUtil,Base64Util,HttpUtil,GsonUtils请从
* https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
* https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
* https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
* https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
* 下载
*/
public static String idcard() {
// 请求url
String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard";
try {
// 本地文件路径
String filePath = Constant.FILE_PATH;
byte[] imgData = FileUtil.readFileByBytes(filePath);
String imgStr = Base64Util.encode(imgData);
String imgParam = URLEncoder.encode(imgStr, "UTF-8");
String param = "id_card_side=" + "front" + "&image=" + imgParam;
// 注意这里仅为了简化编码每一次请求都去获取access_token线上环境access_token有过期时间 客户端可自行缓存过期后重新获取
String accessToken = AuthService.getAuth("iafhTwf6LnOMoYTiZQDlrKTu","0d3yoIsrsrAspUMoyNkWeeqDTvxvg9QB");
String result = HttpUtil.post(url, accessToken, param);
System.out.println(result);
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
IdCard.idcard();
}
}

View File

@ -47,6 +47,7 @@ import com.otaliastudios.cameraview.CameraException;
import com.otaliastudios.cameraview.CameraListener;
import com.otaliastudios.cameraview.CameraLogger;
import com.otaliastudios.cameraview.CameraOptions;
import com.otaliastudios.cameraview.CameraView;
import com.otaliastudios.cameraview.FileCallback;
import com.otaliastudios.cameraview.PictureResult;
@ -59,6 +60,7 @@ import com.otaliastudios.cameraview.frame.FrameProcessor;
import com.otaliastudios.cameraview.size.AspectRatio;
import com.otaliastudios.cameraview.size.Size;
import com.otaliastudios.cameraview.size.SizeSelector;
import com.otaliastudios.cameraview.size.SizeSelectorParser;
import com.otaliastudios.cameraview.size.SizeSelectors;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
@ -212,8 +214,7 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
* app:cameraVideoSizeMaxWidth="2000"
* app:cameraVideoSizeMaxArea="2000000"
*/
camera.setVideoBitRate(2100000);
camera.setVideoBitRate(2000000);
//获取地图
tencentMap = ivMap.getMap();
@ -251,6 +252,18 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
}
//相机预览监听
camera.addCameraListener(new CameraListener() {
@Override
public void onCameraOpened(@NonNull @NotNull CameraOptions options) {
super.onCameraOpened(options);
// List<Size> sizeList = (List<Size>) options.getSupportedVideoSizes();
//
// Size size = null;
// SizeSelector maxWidthSizeSelector = SizeSelectors.maxWidth(size.getWidth());
// SizeSelector maxHeightSizeSelector = SizeSelectors.maxHeight(size.getHeight());
// camera.setVideoSize(SizeSelectors.and(maxHeightSizeSelector, maxWidthSizeSelector));
camera.setVideoBitRate(2000000);
}
@Override
public void onPictureTaken(@NonNull @NotNull PictureResult result) {
super.onPictureTaken(result);

View File

@ -97,6 +97,7 @@ public class Constant {
public static String QQ = null;
public static String WECHAT = null;
public static String MOBILE = null;//手机号
public static String FILE_PATH = null;//银行卡图片途径
//message word

View File

@ -0,0 +1,65 @@
package com.navinfo.outdoor.base;
/**
* Base64 工具类
*/
public class Base64Util {
private static final char last2byte = (char) Integer.parseInt("00000011", 2);
private static final char last4byte = (char) Integer.parseInt("00001111", 2);
private static final char last6byte = (char) Integer.parseInt("00111111", 2);
private static final char lead6byte = (char) Integer.parseInt("11111100", 2);
private static final char lead4byte = (char) Integer.parseInt("11110000", 2);
private static final char lead2byte = (char) Integer.parseInt("11000000", 2);
private static final char[] encodeTable = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
public Base64Util() {
}
public static String encode(byte[] from) {
StringBuilder to = new StringBuilder((int) ((double) from.length * 1.34D) + 3);
int num = 0;
char currentByte = 0;
int i;
for (i = 0; i < from.length; ++i) {
for (num %= 8; num < 8; num += 6) {
switch (num) {
case 0:
currentByte = (char) (from[i] & lead6byte);
currentByte = (char) (currentByte >>> 2);
case 1:
case 3:
case 5:
default:
break;
case 2:
currentByte = (char) (from[i] & last6byte);
break;
case 4:
currentByte = (char) (from[i] & last4byte);
currentByte = (char) (currentByte << 2);
if (i + 1 < from.length) {
currentByte = (char) (currentByte | (from[i + 1] & lead2byte) >>> 6);
}
break;
case 6:
currentByte = (char) (from[i] & last2byte);
currentByte = (char) (currentByte << 4);
if (i + 1 < from.length) {
currentByte = (char) (currentByte | (from[i + 1] & lead4byte) >>> 4);
}
}
to.append(encodeTable[currentByte]);
}
}
if (to.length() % 4 != 0) {
for (i = 4 - to.length() % 4; i > 0; --i) {
to.append("=");
}
}
return to.toString();
}
}

View File

@ -0,0 +1,62 @@
package com.navinfo.outdoor.bean;
public class BankCardBean {
private Long log_id;
private ResultBean result;
public Long getLog_id() {
return log_id;
}
public void setLog_id(Long log_id) {
this.log_id = log_id;
}
public ResultBean getResult() {
return result;
}
public void setResult(ResultBean result) {
this.result = result;
}
public static class ResultBean {
private String bank_card_number;
private String valid_date;
private Integer bank_card_type;
private String bank_name;
public String getBank_card_number() {
return bank_card_number;
}
public void setBank_card_number(String bank_card_number) {
this.bank_card_number = bank_card_number;
}
public String getValid_date() {
return valid_date;
}
public void setValid_date(String valid_date) {
this.valid_date = valid_date;
}
public Integer getBank_card_type() {
return bank_card_type;
}
public void setBank_card_type(Integer bank_card_type) {
this.bank_card_type = bank_card_type;
}
public String getBank_name() {
return bank_name;
}
public void setBank_name(String bank_name) {
this.bank_name = bank_name;
}
}
}

View File

@ -0,0 +1,525 @@
package com.navinfo.outdoor.bean;
public class IdCardNumberBean {
private Long log_id;
private Integer direction;
private String image_status;
private String photo;
private PhotoLocationBean photo_location;
private WordsResultBean words_result;
private Integer words_result_num;
public Long getLog_id() {
return log_id;
}
public void setLog_id(Long log_id) {
this.log_id = log_id;
}
public Integer getDirection() {
return direction;
}
public void setDirection(Integer direction) {
this.direction = direction;
}
public String getImage_status() {
return image_status;
}
public void setImage_status(String image_status) {
this.image_status = image_status;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public PhotoLocationBean getPhoto_location() {
return photo_location;
}
public void setPhoto_location(PhotoLocationBean photo_location) {
this.photo_location = photo_location;
}
public WordsResultBean getWords_result() {
return words_result;
}
public void setWords_result(WordsResultBean words_result) {
this.words_result = words_result;
}
public Integer getWords_result_num() {
return words_result_num;
}
public void setWords_result_num(Integer words_result_num) {
this.words_result_num = words_result_num;
}
public static class PhotoLocationBean {
private Integer width;
private Integer top;
private Integer left;
private Integer height;
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getTop() {
return top;
}
public void setTop(Integer top) {
this.top = top;
}
public Integer getLeft() {
return left;
}
public void setLeft(Integer left) {
this.left = left;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
public static class WordsResultBean {
private 住址Bean 住址;
private 公民身份号码Bean 公民身份号码;
private 出生Bean 出生;
private 姓名Bean 姓名;
private 性别Bean 性别;
private 民族Bean 民族;
public 住址Bean get住址() {
return 住址;
}
public void set住址(住址Bean 住址) {
this.住址 = 住址;
}
public 公民身份号码Bean get公民身份号码() {
return 公民身份号码;
}
public void set公民身份号码(公民身份号码Bean 公民身份号码) {
this.公民身份号码 = 公民身份号码;
}
public 出生Bean get出生() {
return 出生;
}
public void set出生(出生Bean 出生) {
this.出生 = 出生;
}
public 姓名Bean get姓名() {
return 姓名;
}
public void set姓名(姓名Bean 姓名) {
this.姓名 = 姓名;
}
public 性别Bean get性别() {
return 性别;
}
public void set性别(性别Bean 性别) {
this.性别 = 性别;
}
public 民族Bean get民族() {
return 民族;
}
public void set民族(民族Bean 民族) {
this.民族 = 民族;
}
public static class 住址Bean {
private LocationBean location;
private String words;
public LocationBean getLocation() {
return location;
}
public void setLocation(LocationBean location) {
this.location = location;
}
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
public static class LocationBean {
private Integer left;
private Integer top;
private Integer width;
private Integer height;
public Integer getLeft() {
return left;
}
public void setLeft(Integer left) {
this.left = left;
}
public Integer getTop() {
return top;
}
public void setTop(Integer top) {
this.top = top;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
}
public static class 公民身份号码Bean {
private LocationBean location;
private String words;
public LocationBean getLocation() {
return location;
}
public void setLocation(LocationBean location) {
this.location = location;
}
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
public static class LocationBean {
private Integer left;
private Integer top;
private Integer width;
private Integer height;
public Integer getLeft() {
return left;
}
public void setLeft(Integer left) {
this.left = left;
}
public Integer getTop() {
return top;
}
public void setTop(Integer top) {
this.top = top;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
}
public static class 出生Bean {
private LocationBean location;
private String words;
public LocationBean getLocation() {
return location;
}
public void setLocation(LocationBean location) {
this.location = location;
}
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
public static class LocationBean {
private Integer left;
private Integer top;
private Integer width;
private Integer height;
public Integer getLeft() {
return left;
}
public void setLeft(Integer left) {
this.left = left;
}
public Integer getTop() {
return top;
}
public void setTop(Integer top) {
this.top = top;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
}
public static class 姓名Bean {
private LocationBean location;
private String words;
public LocationBean getLocation() {
return location;
}
public void setLocation(LocationBean location) {
this.location = location;
}
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
public static class LocationBean {
private Integer left;
private Integer top;
private Integer width;
private Integer height;
public Integer getLeft() {
return left;
}
public void setLeft(Integer left) {
this.left = left;
}
public Integer getTop() {
return top;
}
public void setTop(Integer top) {
this.top = top;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
}
public static class 性别Bean {
private LocationBean location;
private String words;
public LocationBean getLocation() {
return location;
}
public void setLocation(LocationBean location) {
this.location = location;
}
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
public static class LocationBean {
private Integer left;
private Integer top;
private Integer width;
private Integer height;
public Integer getLeft() {
return left;
}
public void setLeft(Integer left) {
this.left = left;
}
public Integer getTop() {
return top;
}
public void setTop(Integer top) {
this.top = top;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
}
public static class 民族Bean {
private LocationBean location;
private String words;
public LocationBean getLocation() {
return location;
}
public void setLocation(LocationBean location) {
this.location = location;
}
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
public static class LocationBean {
private Integer left;
private Integer top;
private Integer width;
private Integer height;
public Integer getLeft() {
return left;
}
public void setLeft(Integer left) {
this.left = left;
}
public Integer getTop() {
return top;
}
public void setTop(Integer top) {
this.top = top;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
}
}
}

View File

@ -34,9 +34,11 @@ import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.activity.BankCard;
import com.navinfo.outdoor.adapter.BankAdapter;
import com.navinfo.outdoor.api.Constant;
import com.navinfo.outdoor.base.BaseFragment;
import com.navinfo.outdoor.bean.BankCardBean;
import com.navinfo.outdoor.bean.BankPathBean;
import com.navinfo.outdoor.bean.BankPhoneBean;
import com.navinfo.outdoor.http.Callback;
@ -180,6 +182,7 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe
gatheringList.add(new File(gatheringCameraTag));
String etBankAccount = etBankNum.getText().toString().trim();
if (etBankAccount == null || etBankAccount.equals("")) {
if (!etBankAccount.matches("^\\\\d{19}$\"")) {
Toast.makeText(getActivity(), "银行卡号不能为空", Toast.LENGTH_SHORT).show();
return;
@ -239,7 +242,17 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe
Toast.makeText(getActivity(), "请先拍照", Toast.LENGTH_SHORT).show();
return;
}
gatheringCamera.setTag(file.getAbsolutePath());
String absolutePath = file.getAbsolutePath();
Constant.FILE_PATH = absolutePath;
gatheringCamera.setTag(absolutePath);
//银行卡识别
BankCardBean bankCardBean = new Gson().fromJson(BankCard.bankCard(), BankCardBean.class);
if (bankCardBean==null){
Toast.makeText(getContext(), "请手动添加银行卡号", Toast.LENGTH_SHORT).show();
}else {
String bank_card_number = bankCardBean.getResult().getBank_card_number();
etBankNum.setText(bank_card_number);
}
}
}

View File

@ -1,9 +1,6 @@
package com.navinfo.outdoor.fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
@ -19,23 +16,21 @@ import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.google.gson.Gson;
import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.util.DialogSettings;
import com.kongzue.dialog.v3.MessageDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.activity.IdCard;
import com.navinfo.outdoor.api.Constant;
import com.navinfo.outdoor.base.BaseFragment;
import com.navinfo.outdoor.bean.IdCardNumberBean;
import com.navinfo.outdoor.bean.NameAuthenticationBean;
import com.navinfo.outdoor.http.Callback;
import com.navinfo.outdoor.http.DialogCallback;
import com.navinfo.outdoor.http.HttpInterface;
import com.navinfo.outdoor.http.OkGoBuilder;
import com.navinfo.outdoor.util.Geohash;
import com.navinfo.outdoor.util.PhotoPathUtil;
import com.navinfo.outdoor.util.PhotoUtils;
import java.io.File;
@ -69,6 +64,7 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic
private TextView tvTitle;
private LinearLayout linearLayout;
private View userAttestView;
private ImageView useCamera;
public static UserAttestationFragment newInstance(Bundle bundle) {
@ -116,7 +112,8 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic
tvTitle = findViewById(R.id.tv_title);
userAttestView = findViewById(R.id.user_attestation_view);
linearLayout = findViewById(R.id.ll_pic);//身份证照片
useCamera = findViewById(R.id.user_attestation_camera);
useCamera.setOnClickListener(this::onClick);
if (Constant.AUDITSTATUS==-1){//审核中
if (Constant.NAME!=null&&Constant.ID_NUM!=null){
tvTitle.setText("1.审核中");
@ -193,6 +190,12 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic
}
nameAuthentication();
break;
case R.id.user_attestation_camera:
Intent userCameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
file = PhotoUtils.showPhotoFile("d", null);
userCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(userCameraIntent, 124);
break;
}
}
@ -316,19 +319,6 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic
file = null;
ivHera1.setVisibility(View.GONE);
tvCard1.setVisibility(View.GONE);
// int height = bitmap.getHeight();
// int width = bitmap.getWidth();
// if (height > width) {
// DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
// MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照,要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
// @Override
// public boolean onClick(BaseDialog baseDialog, View v) {
// Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
// startActivityForResult(intentPanorama, 100);
// return false;
// }
// });
// }
} else if (requestCode == 122 && resultCode == RESULT_OK) {
if (file == null || !file.exists()) {
Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
@ -341,19 +331,6 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic
file = null;
ivHera2.setVisibility(View.GONE);
tvCard2.setVisibility(View.GONE);
// int height = bitmap.getHeight();
// int width = bitmap.getWidth();
// if (height > width) {
// DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
// MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照,要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
// @Override
// public boolean onClick(BaseDialog baseDialog, View v) {
// Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
// startActivityForResult(intentPanorama, 200);
// return false;
// }
// });
// }
} else if (requestCode == 123 && resultCode == RESULT_OK) {
if (file == null || !file.exists()) {
Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
@ -366,21 +343,23 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic
file = null;
ivHera3.setVisibility(View.GONE);
tvCard3.setVisibility(View.GONE);
// int height = bitmap.getHeight();
// int width = bitmap.getWidth();
// if (height > width) {
// DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
// MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照,要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
// @Override
// public boolean onClick(BaseDialog baseDialog, View v) {
// Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
// startActivityForResult(intentPanorama, 300);
// return false;
// }
// });
// } else {
//
// }
}else if (requestCode == 124 && resultCode == RESULT_OK){
if (file == null && !file.exists()) {
Toast.makeText(getActivity(), "请先拍照", Toast.LENGTH_SHORT).show();
return;
}
String absolutePath = file.getAbsolutePath();
Constant.FILE_PATH = absolutePath;
useCamera.setTag(absolutePath);
//身份证识别
IdCardNumberBean idCardNumberBean = new Gson().fromJson(IdCard.idcard(), IdCardNumberBean.class);
if (idCardNumberBean ==null){
Toast.makeText(getActivity(), "请手动添加身份证号", Toast.LENGTH_SHORT).show();
}else {
String words = idCardNumberBean.getWords_result().get公民身份号码().getWords();
etNamePhone.setText(words);
}
}
}
}

View File

@ -0,0 +1,77 @@
package com.navinfo.outdoor.http;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
/**
* http 工具类
*/
public class HttpUtil {
public static String post(String requestUrl, String accessToken, String params)
throws Exception {
String contentType = "application/x-www-form-urlencoded";
return HttpUtil.post(requestUrl, accessToken, contentType, params);
}
public static String post(String requestUrl, String accessToken, String contentType, String params)
throws Exception {
String encoding = "UTF-8";
if (requestUrl.contains("nlp")) {
encoding = "GBK";
}
return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding);
}
public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding)
throws Exception {
String url = requestUrl + "?access_token=" + accessToken;
return HttpUtil.postGeneralUrl(url, contentType, params, encoding);
}
public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding)
throws Exception {
URL url = new URL(generalUrl);
// 打开和URL之间的连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
// 设置通用的请求属性
connection.setRequestProperty("Content-Type", contentType);
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
// 得到请求的输出流对象
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.write(params.getBytes(encoding));
out.flush();
out.close();
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> headers = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : headers.keySet()) {
System.err.println(key + "--->" + headers.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
BufferedReader in = null;
in = new BufferedReader(
new InputStreamReader(connection.getInputStream(), encoding));
String result = "";
String getLine;
while ((getLine = in.readLine()) != null) {
result += getLine;
}
in.close();
System.err.println("result:" + result);
return result;
}
}

View File

@ -0,0 +1,72 @@
package com.navinfo.outdoor.util;
import java.io.*;
/**
* 文件读取工具类
*/
public class FileUtil {
/**
* 读取文件内容作为字符串返回
*/
public static String readFileAsString(String filePath) throws IOException {
File file = new File(filePath);
if (!file.exists()) {
throw new FileNotFoundException(filePath);
}
if (file.length() > 1024 * 1024 * 1024) {
throw new IOException("File is too large");
}
StringBuilder sb = new StringBuilder((int) (file.length()));
// 创建字节输入流
FileInputStream fis = new FileInputStream(filePath);
// 创建一个长度为10240的Buffer
byte[] bbuf = new byte[10240];
// 用于保存实际读取的字节数
int hasRead = 0;
while ( (hasRead = fis.read(bbuf)) > 0 ) {
sb.append(new String(bbuf, 0, hasRead));
}
fis.close();
return sb.toString();
}
/**
* 根据文件路径读取byte[] 数组
*/
public static byte[] readFileByBytes(String filePath) throws IOException {
File file = new File(filePath);
if (!file.exists()) {
throw new FileNotFoundException(filePath);
} else {
ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length());
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
short bufSize = 1024;
byte[] buffer = new byte[bufSize];
int len1;
while (-1 != (len1 = in.read(buffer, 0, bufSize))) {
bos.write(buffer, 0, len1);
}
byte[] var7 = bos.toByteArray();
return var7;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException var14) {
var14.printStackTrace();
}
bos.close();
}
}
}
}

View File

@ -113,28 +113,49 @@
android:layout_height="1dp"
android:background="#2196F3" />
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_card"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="身份证号:"
android:textColor="#333"
android:textSize="18sp" />
android:textSize="18sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
/>
<EditText
android:id="@+id/et_namePhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:hint="请输入身份证号"
android:textSize="16sp" />
</LinearLayout>
android:textColorHint="@color/colorRed"
android:layout_marginLeft="100dp"
android:layout_marginRight="50dp"
android:hint="点击拍照自动识别"
android:textSize="16sp"
app:layout_constraintLeft_toRightOf="@+id/tv_card"
app:layout_constraintTop_toTopOf="@+id/tv_card"
/>
<ImageView
android:id="@+id/user_attestation_camera"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginBottom="10dp"
android:src="@drawable/ic_baseline_camera"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/et_namePhone"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:layout_width="match_parent"