Updated on 2026-08-14
This commit is contained in:
parent
ff6efa8f37
commit
6cf2cd2afb
13 changed files with 239 additions and 111 deletions
29
app/src/main/java/com/tangem/data/network/Server.java
Normal file
29
app/src/main/java/com/tangem/data/network/Server.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Server {
|
||||
|
||||
public static Map<String, String> getHeader() {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Content-Type", "application/json");
|
||||
return headers;
|
||||
}
|
||||
|
||||
public static class API {
|
||||
private static final String URL_TANGEM = ServerURL.API_TANGEM;
|
||||
|
||||
public static class Method {
|
||||
/**
|
||||
* https://tangem-webapp.appspot.com/
|
||||
*/
|
||||
public static final String INFO_VERIFY = URL_TANGEM + "info/version";
|
||||
|
||||
public static final String CARD_VERIFY = URL_TANGEM + "card/verify";
|
||||
public static final String CARD_VALIDATE = URL_TANGEM + "card/validate";
|
||||
public static final String CARD_ACTIVATE = URL_TANGEM + "card/activate";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
app/src/main/java/com/tangem/data/network/ServerURL.java
Normal file
11
app/src/main/java/com/tangem/data/network/ServerURL.java
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
public class ServerURL {
|
||||
public static final String API_TANGEM = "https://tangem-webapp.appspot.com/";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
54
app/src/main/java/com/tangem/data/network/VolleyHelper.kt
Normal file
54
app/src/main/java/com/tangem/data/network/VolleyHelper.kt
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package com.tangem.data.network
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v7.app.AlertDialog
|
||||
import com.android.volley.AuthFailureError
|
||||
import com.android.volley.DefaultRetryPolicy
|
||||
import com.android.volley.Request
|
||||
import com.android.volley.toolbox.StringRequest
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonParser
|
||||
import com.tangem.AppController
|
||||
import com.tangem.wallet.R
|
||||
|
||||
class VolleyHelper {
|
||||
|
||||
fun doRequest(context: Context, url: String, params: Map<String, String>) {
|
||||
val stringRequest = object : StringRequest(Request.Method.POST, url,
|
||||
{ response ->
|
||||
val data = GsonBuilder().setPrettyPrinting().create().toJson(JsonParser().parse(response))
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle("sxsx")
|
||||
.setMessage(data)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNeutralButton(R.string.send) { _, _ ->
|
||||
val intent = Intent(Intent.ACTION_SEND)
|
||||
intent.type = "text/html"
|
||||
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("digest2003@mail.ru"))
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, url)
|
||||
intent.putExtra(Intent.EXTRA_TEXT, data)
|
||||
context.startActivity(Intent.createChooser(intent, "Send gson"))
|
||||
}
|
||||
val alert = builder.create()
|
||||
alert.show()
|
||||
},
|
||||
{ error -> val networkResponse = error.networkResponse }) {
|
||||
|
||||
|
||||
@Throws(AuthFailureError::class)
|
||||
override fun getHeaders(): Map<String, String> {
|
||||
return Server.getHeader()
|
||||
}
|
||||
|
||||
@Throws(AuthFailureError::class)
|
||||
override fun getParams(): Map<String, String> {
|
||||
return params
|
||||
}
|
||||
}
|
||||
|
||||
stringRequest.retryPolicy = DefaultRetryPolicy(60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
|
||||
AppController.getInstance().addToRequestQueue(stringRequest)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -22,20 +22,19 @@ import java.util.Locale;
|
|||
|
||||
public class VerificationServerProtocol {
|
||||
|
||||
public static class Request
|
||||
{
|
||||
public Request(CustomCommand command, Class answerClass)
|
||||
{
|
||||
this.command=command;
|
||||
this.answerClass=answerClass;
|
||||
public static class Request {
|
||||
public Request(CustomCommand command, Class answerClass) {
|
||||
this.command = command;
|
||||
this.answerClass = answerClass;
|
||||
}
|
||||
|
||||
public String error;
|
||||
public CustomCommand command;
|
||||
public CustomAnswer answer;
|
||||
public Type answerClass;
|
||||
|
||||
public void doPost(String hostURL) throws IOException {
|
||||
URL url = new URL(hostURL+"/"+command.getURL());
|
||||
URL url = new URL(hostURL + "/" + command.getURL());
|
||||
URLConnection con = url.openConnection();
|
||||
HttpURLConnection http = (HttpURLConnection) con;
|
||||
try {
|
||||
|
|
@ -60,8 +59,7 @@ public class VerificationServerProtocol {
|
|||
answer = getGson().fromJson(br, answerClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
http.disconnect();
|
||||
}
|
||||
}
|
||||
|
|
@ -70,8 +68,7 @@ public class VerificationServerProtocol {
|
|||
static abstract class CustomCommand {
|
||||
public abstract String getURL();
|
||||
|
||||
public byte[] toBytes()
|
||||
{
|
||||
public byte[] toBytes() {
|
||||
return getGson().toJson(this).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
|
|
@ -121,15 +118,14 @@ public class VerificationServerProtocol {
|
|||
public ResultItem[] results;
|
||||
}
|
||||
|
||||
public static Request prepare(TangemCard card)
|
||||
{
|
||||
Command c=new Command();
|
||||
c.requests=new RequestItem[1];
|
||||
c.requests[0]=new RequestItem();
|
||||
c.requests[0].CID=Util.bytesToHex(card.getCID());
|
||||
c.requests[0].publicKey=Util.bytesToHex(card.getCardPublicKey());
|
||||
public static Request prepare(TangemCard card) {
|
||||
Command c = new Command();
|
||||
c.requests = new RequestItem[1];
|
||||
c.requests[0] = new RequestItem();
|
||||
c.requests[0].CID = Util.bytesToHex(card.getCID());
|
||||
c.requests[0].publicKey = Util.bytesToHex(card.getCardPublicKey());
|
||||
|
||||
return new Request(c,Answer.class);
|
||||
return new Request(c, Answer.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -154,6 +150,7 @@ public class VerificationServerProtocol {
|
|||
public ResultItem(RequestItem request) {
|
||||
CID = request.CID;
|
||||
}
|
||||
|
||||
public String error;
|
||||
public String CID;
|
||||
public Integer previousCounter;
|
||||
|
|
@ -164,14 +161,13 @@ public class VerificationServerProtocol {
|
|||
public ResultItem[] results;
|
||||
}
|
||||
|
||||
public Request prepare(TangemCard card, int ValidationCounter, byte[] ValidationSignature)
|
||||
{
|
||||
Command c=new Command();
|
||||
c.requests=new RequestItem[1];
|
||||
c.requests[0].CID= Util.bytesToHex(card.getCID());
|
||||
c.requests[0].counter=ValidationCounter;
|
||||
c.requests[0].signature=Util.bytesToHex(ValidationSignature);
|
||||
return new Request(new Command(),Answer.class);
|
||||
public Request prepare(TangemCard card, int ValidationCounter, byte[] ValidationSignature) {
|
||||
Command c = new Command();
|
||||
c.requests = new RequestItem[1];
|
||||
c.requests[0].CID = Util.bytesToHex(card.getCID());
|
||||
c.requests[0].counter = ValidationCounter;
|
||||
c.requests[0].signature = Util.bytesToHex(ValidationSignature);
|
||||
return new Request(new Command(), Answer.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,35 +8,34 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class VerificationServerTask extends AsyncTask<VerificationServerProtocol.Request, Void, List<VerificationServerProtocol.Request>> {
|
||||
public static final String hostURL ="https://tangem-webapp.appspot.com";
|
||||
public static final String hostURL = "https://tangem-webapp.appspot.com";
|
||||
|
||||
public VerificationServerTask() {
|
||||
|
||||
}
|
||||
|
||||
protected List<VerificationServerProtocol.Request> doInBackground(VerificationServerProtocol.Request... requests) {
|
||||
List<VerificationServerProtocol.Request> result = new ArrayList<>();
|
||||
for (int i = 0; i < requests.length; i++) {
|
||||
result.add(requests[i]);
|
||||
}
|
||||
|
||||
for (VerificationServerProtocol.Request request : result) {
|
||||
try {
|
||||
request.doPost(hostURL);
|
||||
} catch (Exception e) {
|
||||
request.error = e.getMessage();
|
||||
if( request.error==null || request.error.isEmpty() )
|
||||
{
|
||||
request.error = e.getClass().getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getValidationNodeDescription() {
|
||||
return hostURL;
|
||||
}
|
||||
public VerificationServerTask() {
|
||||
|
||||
}
|
||||
|
||||
protected List<VerificationServerProtocol.Request> doInBackground(VerificationServerProtocol.Request... requests) {
|
||||
List<VerificationServerProtocol.Request> result = new ArrayList<>();
|
||||
for (int i = 0; i < requests.length; i++) {
|
||||
result.add(requests[i]);
|
||||
}
|
||||
|
||||
for (VerificationServerProtocol.Request request : result) {
|
||||
try {
|
||||
request.doPost(hostURL);
|
||||
} catch (Exception e) {
|
||||
request.error = e.getMessage();
|
||||
if (request.error == null || request.error.isEmpty()) {
|
||||
request.error = e.getClass().getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getValidationNodeDescription() {
|
||||
return hostURL;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue