xuxiuxi
2017-07-18 d906c07255528df929b6ab276ac07e290cfc895a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package cn.com.basic.face.service;
 
import android.widget.Toast;
 
import cn.com.basic.face.base.BaseApplication;
import cn.com.basic.face.fragment.VisitorRegisterFragment;
import cn.com.basic.face.util.AppApi;
 
import org.xutils.http.RequestParams;
import org.xutils.x;
 
import java.io.File;
import java.io.FileWriter;
import java.util.List;
 
import cn.com.basic.face.discern.common.BaseCommonCallBack;
import cn.com.basic.face.util.IdCard;
 
public class RegisterMng {
 
    public static RegisterMng instance = new RegisterMng();
 
    public static RegisterMng getInstance() {
        return instance;
    }
 
    public void add(RequestParams params, String idCardHeadPhoto) {
        if (!BaseApplication.deviceAvailable) {
            return;
        }
        try {
            File path = BaseApplication.getInstance().getFilesDir();
            File rawSurveillancePhotoFile = new File(path, "rawSurveillancePhoto");
            if (!rawSurveillancePhotoFile.exists()) {
                rawSurveillancePhotoFile.createNewFile();
            }
            File f0 = new File(path, "f0");
            if (!f0.exists()) {
                f0.createNewFile();
            }
            File surveillancePhotoFile = new File(path, "surveillancePhoto");
            if (!surveillancePhotoFile.exists()) {
                surveillancePhotoFile.createNewFile();
            }
            File uploadCustomPhotoFile = new File(path, "uploadCustomPhoto");
            if (!uploadCustomPhotoFile.exists()) {
                uploadCustomPhotoFile.createNewFile();
            }
            File idCardPhotoFile = new File(path, "idCardPhoto");
            if (!idCardPhotoFile.exists()) {
                idCardPhotoFile.createNewFile();
            }
 
            FileWriter fw0 = new FileWriter(f0);
            fw0.write("test1");
            fw0.close();
            params.setUri(AppApi.BASE_URL +AppApi.REGISTER_ADD);
            params.addBodyParameter("f0", f0);
            params.addBodyParameter("rawSurveillancePhoto", rawSurveillancePhotoFile);
            params.addBodyParameter("surveillancePhoto", surveillancePhotoFile);
            params.addBodyParameter("uploadCustomPhoto", uploadCustomPhotoFile);
            params.addBodyParameter("idCardPhoto", idCardPhotoFile);
            if (idCardHeadPhoto != null && !"".equals(idCardHeadPhoto)) {
                File f5 = new File(idCardHeadPhoto);
                if (!f5.exists()) {
                    f5.createNewFile();
                }
                params.addBodyParameter("idCardHeadPhoto", f5);
            }
            x.http().post(params, new BaseCommonCallBack() {
                @Override
                public void success() {
                    Toast.makeText(BaseApplication.getInstance(),"添加成功", Toast.LENGTH_SHORT).show();
                    VisitorRegisterFragment.getInstance().resetForm();
                }
            });
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
 
    public void compareSurveillancePhotoAndIdCardPhoto(RequestParams params, final IdCard idCard) {
        if (!BaseApplication.deviceAvailable) {
            return;
        }
        try {
            File path = BaseApplication.getInstance().getFilesDir();
            File f0 = new File(path, "f0");
            if (!f0.exists()) {
                f0.createNewFile();
            }
            File surveillancePhotoFile = new File(path, "surveillancePhoto");
            if (!surveillancePhotoFile.exists()) {
                surveillancePhotoFile.createNewFile();
            }
            File idCardHeadPhotoFile = new File(path, "idCardHeadPhoto");
            if (!idCardHeadPhotoFile.exists()) {
                idCardHeadPhotoFile.createNewFile();
            }
            FileWriter fw0 = new FileWriter(f0);
            fw0.write("test1");
            fw0.close();
 
            params.setUri(AppApi.BASE_URL +AppApi.REGISTER_ID_CARD_AUTH);
            params.addBodyParameter("f0", f0);
            params.addBodyParameter("surveillancePhoto", surveillancePhotoFile);
            params.addBodyParameter("idCardPhoto", idCardHeadPhotoFile);
            x.http().post(params, new BaseCommonCallBack() {
                @Override
                public void success() {
                    if (!VisitorRegisterFragment.getInstance().isVisible()) {
                        return;
                    }
                    List<Double> percents = resultBean.getListBeanOfType(Double.class);
                    if (percents != null && percents.size() > 0) {
                        double percent = percents.get(0);
                        if (percent >= 70) {
                            Toast.makeText(BaseApplication.getInstance(),"认证通过", Toast.LENGTH_SHORT).show();
                            VisitorRegisterFragment.getInstance().fillFormWithIdCard(idCard);
                            return;
                        }
                        System.out.println("percent="+percent);
                    }
                    Toast.makeText(BaseApplication.getInstance(),"认证失败", Toast.LENGTH_SHORT).show();
                }
            });
 
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(BaseApplication.getInstance(),"认证失败", Toast.LENGTH_SHORT).show();
        }
 
    }
 
 
    public void addAttender(RequestParams params, String idCardHeadPhoto) {
        if (!BaseApplication.deviceAvailable) {
            return;
        }
        try {
            File path = BaseApplication.getInstance().getFilesDir();
            File rawSurveillancePhotoFile = new File(path, "rawSurveillancePhoto_attender");
            if (!rawSurveillancePhotoFile.exists()) {
                rawSurveillancePhotoFile.createNewFile();
            }
            File f0 = new File(path, "f0");
            if (!f0.exists()) {
                f0.createNewFile();
            }
            File surveillancePhotoFile = new File(path, "surveillancePhoto_attender");
            if (!surveillancePhotoFile.exists()) {
                surveillancePhotoFile.createNewFile();
            }
            File uploadCustomPhotoFile = new File(path, "uploadCustomPhoto_attender");
            if (!uploadCustomPhotoFile.exists()) {
                uploadCustomPhotoFile.createNewFile();
            }
            File idCardPhotoFile = new File(path, "idCardPhoto_attender");
            if (!idCardPhotoFile.exists()) {
                idCardPhotoFile.createNewFile();
            }
 
            FileWriter fw0 = new FileWriter(f0);
            fw0.write("test1");
            fw0.close();
            params.setUri(AppApi.BASE_URL +AppApi.ATTENDER_REGISTER_ADD);
            params.addBodyParameter("f0", f0);
            params.addBodyParameter("rawSurveillancePhoto", rawSurveillancePhotoFile);
            params.addBodyParameter("surveillancePhoto", surveillancePhotoFile);
            params.addBodyParameter("uploadCustomPhoto", uploadCustomPhotoFile);
            params.addBodyParameter("idCardPhoto", idCardPhotoFile);
            if (idCardHeadPhoto != null && !"".equals(idCardHeadPhoto)) {
                File f5 = new File(idCardHeadPhoto);
                if (!f5.exists()) {
                    f5.createNewFile();
                }
                params.addBodyParameter("idCardHeadPhoto_attender", f5);
            }
            x.http().post(params, new BaseCommonCallBack() {
                @Override
                public void success() {
                    Toast.makeText(BaseApplication.getInstance(),"添加成功", Toast.LENGTH_SHORT).show();
                    VisitorRegisterFragment.getInstance().resetForm();
                }
            });
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
 
}