♬♬ v1.0.0版本的 MD5 值为:04cc17073568ba22bfb83ea139fbe521
以下内容为反编译后的 StripeApiHandler.java 源代码,内容仅作参考
package com.stripe.android.net;
import com.baidu.mapapi.UIMsg;
import com.stripe.android.exception.APIConnectionException;
import com.stripe.android.exception.APIException;
import com.stripe.android.exception.AuthenticationException;
import com.stripe.android.exception.CardException;
import com.stripe.android.exception.InvalidRequestException;
import com.stripe.android.exception.PermissionException;
import com.stripe.android.exception.RateLimitException;
import com.stripe.android.model.Token;
import com.stripe.android.net.ErrorParser;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.Security;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
import obfuse.NPStringFog;
import org.json.JSONException;
import org.json.JSONObject;
public class StripeApiHandler {
public static final String CHARSET = "UTF-8";
private static final String DNS_CACHE_TTL_PROPERTY_NAME = "networkaddress.cache.ttl";
static final String GET = "GET";
public static final String LIVE_API_BASE = "https://api.stripe.com";
static final String POST = "POST";
private static final SSLSocketFactory SSL_SOCKET_FACTORY = new StripeSSLSocketFactory();
public static final String TOKENS = "tokens";
public static final String VERSION = "3.5.0";
@Retention(RetentionPolicy.SOURCE)
@interface RestMethod {
}
public static Token createToken(Map<String, Object> cardParams, RequestOptions options) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
return requestToken(NPStringFog.decode("617E6265"), getApiUrl(), cardParams, options);
}
public static Token retrieveToken(RequestOptions options, String tokenId) throws AuthenticationException, InvalidRequestException, APIConnectionException, APIException {
try {
return requestToken(NPStringFog.decode("767465"), getRetrieveTokenApiUrl(tokenId), null, options);
} catch (CardException cardException) {
throw new APIException(cardException.getMessage(), cardException.getRequestId(), cardException.getStatusCode(), cardException);
}
}
static String createQuery(Map<String, Object> params) throws UnsupportedEncodingException, InvalidRequestException {
StringBuilder queryStringBuffer = new StringBuilder();
List<Parameter> flatParams = flattenParams(params);
for (Parameter param : flatParams) {
if (queryStringBuffer.length() > 0) {
queryStringBuffer.append(NPStringFog.decode("17"));
}
queryStringBuffer.append(urlEncodePair(param.key, param.value));
}
return queryStringBuffer.toString();
}
static Map<String, String> getHeaders(RequestOptions options) {
Map<String, String> headers = new HashMap<>();
String apiVersion = options.getApiVersion();
headers.put(NPStringFog.decode("7052525441451C72595043425445"), "UTF-8");
headers.put(NPStringFog.decode("705252544145"), "application/json");
String decode = NPStringFog.decode("021F041F01");
headers.put(NPStringFog.decode("644254431C7056545F45"), String.format(NPStringFog.decode("6245435841541E4700117B50475073585F55585F56421E1442"), decode));
headers.put(NPStringFog.decode("704445595E43584B5045585E5F"), String.format(NPStringFog.decode("735450435443111442"), options.getPublishableApiKey()));
String[] propertyNames = {NPStringFog.decode("5E421F5F505C54"), "os.version", NPStringFog.decode("5E421F50435259"), "java.version", NPStringFog.decode("5B5047501F47545F555E43"), "java.vm.version", NPStringFog.decode("5B5047501F475C1F47545F555E43")};
Map<String, String> propertyMap = new HashMap<>();
for (String propertyName : propertyNames) {
propertyMap.put(propertyName, System.getProperty(propertyName));
}
propertyMap.put(NPStringFog.decode("53585F55585F56421F47544342585E5F"), decode);
propertyMap.put(NPStringFog.decode("5D505F56"), "Java");
propertyMap.put(NPStringFog.decode("4144535D5842595443"), "Stripe");
JSONObject headerMappingObject = new JSONObject(propertyMap);
headers.put(NPStringFog.decode("691C6245435841541C725D58545F451C644254431C7056545F45"), headerMappingObject.toString());
if (apiVersion != null) {
headers.put(NPStringFog.decode("6245435841541C67544342585E5F"), apiVersion);
}
if (options.getIdempotencyKey() != null) {
headers.put(NPStringFog.decode("7855545C415E45545F52481C7A5448"), options.getIdempotencyKey());
}
return headers;
}
static String getApiUrl() {
return String.format(NPStringFog.decode("14421E47001E1442"), NPStringFog.decode("59454541420B1E1E5041581F4245435841541F525E5C"), NPStringFog.decode("455E5A545F42"));
}
static String getRetrieveTokenApiUrl(String tokenId) {
return String.format(NPStringFog.decode("14421E1442"), getApiUrl(), tokenId);
}
private static String formatURL(String url, String query) {
if (query == null || query.isEmpty()) {
return url;
}
String separator = NPStringFog.decode("0E");
if (url.contains(separator)) {
separator = NPStringFog.decode("17");
}
return String.format(NPStringFog.decode("144214421442"), url, separator, query);
}
private static HttpURLConnection createGetConnection(String url, String query, RequestOptions options) throws IOException {
String getURL = formatURL(url, query);
HttpURLConnection conn = createStripeConnection(getURL, options);
conn.setRequestMethod(NPStringFog.decode("767465"));
return conn;
}
private static HttpURLConnection createPostConnection(String url, String query, RequestOptions options) throws IOException {
HttpURLConnection conn = createStripeConnection(url, options);
conn.setDoOutput(true);
conn.setRequestMethod(NPStringFog.decode("617E6265"));
String decode = NPStringFog.decode("6465771C09");
conn.setRequestProperty(NPStringFog.decode("725E5F45545F451C65484154"), String.format(NPStringFog.decode("5041415D58525045585E5F1E491C4646461C575E435C1C44435D545F525E5554550A525950434254450C1442"), decode));
OutputStream output = null;
try {
output = conn.getOutputStream();
output.write(query.getBytes(decode));
return conn;
} finally {
if (output != null) {
output.close();
}
}
}
private static HttpURLConnection createStripeConnection(String url, RequestOptions options) throws IOException {
URL stripeURL = new URL(url);
HttpURLConnection conn = (HttpURLConnection) stripeURL.openConnection();
conn.setConnectTimeout(UIMsg.m_AppUI.MSG_RADAR_SEARCH_RETURN_RESULT);
conn.setReadTimeout(80000);
conn.setUseCaches(false);
for (Map.Entry<String, String> header : getHeaders(options).entrySet()) {
conn.setRequestProperty(header.getKey(), header.getValue());
}
if (conn instanceof HttpsURLConnection) {
((HttpsURLConnection) conn).setSSLSocketFactory(SSL_SOCKET_FACTORY);
}
return conn;
}
private static Token requestToken(String method, String url, Map<String, Object> params, RequestOptions options) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
String decode = NPStringFog.decode("1C00");
if (options == null) {
return null;
}
String originalDNSCacheTTL = null;
Boolean allowedToSetTTL = true;
try {
originalDNSCacheTTL = Security.getProperty(DNS_CACHE_TTL_PROPERTY_NAME);
Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, NPStringFog.decode("01"));
} catch (SecurityException e) {
allowedToSetTTL = false;
}
String apiKey = options.getPublishableApiKey();
if (apiKey.trim().isEmpty()) {
throw new AuthenticationException(NPStringFog.decode("7F5E11706178115A54481141435E47585554551F111979787F650B1142544511485E444311706178115A5448114442585F5611166245435841541F5041587A5448110C110D7061781C7A74680F161F11685E441152505F1156545F544350455411706178115A5448421157435E5C11455954116245435841541146545311585F455443575052541F116254541159454541420B1E1E4245435841541F525E5C1E50415811575E431155544550585D42115E4311545C50585D11424441415E4345714245435841541F525E5C11585711485E441159504754114044544245585E5F421F"), null, 0);
}
try {
StripeResponse response = getStripeResponse(method, url, params, options);
int rCode = response.getResponseCode();
String rBody = response.getResponseBody();
String requestId = null;
Map<String, List<String>> headers = response.getResponseHeaders();
List<String> requestIdList = headers == null ? null : headers.get(NPStringFog.decode("635440445442451C7855"));
if (requestIdList != null && requestIdList.size() > 0) {
requestId = requestIdList.get(0);
}
if (rCode < 200 || rCode >= 300) {
handleAPIError(rBody, rCode, requestId);
}
Token parseToken = TokenParser.parseToken(rBody);
if (allowedToSetTTL.booleanValue()) {
if (originalDNSCacheTTL == null) {
Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, decode);
} else {
Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, originalDNSCacheTTL);
}
}
return parseToken;
} catch (JSONException e2) {
if (allowedToSetTTL.booleanValue()) {
if (originalDNSCacheTTL == null) {
Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, decode);
} else {
Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, originalDNSCacheTTL);
}
}
return null;
} catch (Throwable th) {
if (allowedToSetTTL.booleanValue()) {
if (originalDNSCacheTTL == null) {
Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, decode);
} else {
Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, originalDNSCacheTTL);
}
}
throw th;
}
}
private static StripeResponse getStripeResponse(String method, String url, Map<String, Object> params, RequestOptions options) throws InvalidRequestException, APIConnectionException, APIException {
try {
String query = createQuery(params);
return makeURLConnectionRequest(method, url, query, options);
} catch (UnsupportedEncodingException e) {
throw new InvalidRequestException(NPStringFog.decode("645F50535D5411455E11545F525E555411415043505C544554434211455E116465771C091F11615D5450425411525E5F4550524511424441415E4345714245435841541F525E5C11575E4311504242584245505F52541F"), null, null, 0, e);
}
}
private static List<Parameter> flattenParams(Map<String, Object> params) throws InvalidRequestException {
return flattenParamsMap(params, null);
}
private static List<Parameter> flattenParamsList(List<Object> params, String keyPrefix) throws InvalidRequestException {
List<Parameter> flatParams = new LinkedList<>();
Iterator<?> it = params.iterator();
String newPrefix = String.format(NPStringFog.decode("14426A6C"), keyPrefix);
if (params.isEmpty()) {
flatParams.add(new Parameter(keyPrefix, NPStringFog.decode("")));
} else {
while (it.hasNext()) {
flatParams.addAll(flattenParamsValue(it.next(), newPrefix));
}
}
return flatParams;
}
private static List<Parameter> flattenParamsMap(Map<String, Object> params, String keyPrefix) throws InvalidRequestException {
List<Parameter> flatParams = new LinkedList<>();
if (params == null) {
return flatParams;
}
for (Map.Entry<String, Object> entry : params.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
String newPrefix = key;
if (keyPrefix != null) {
newPrefix = String.format(NPStringFog.decode("14426A14426C"), keyPrefix, key);
}
flatParams.addAll(flattenParamsValue(value, newPrefix));
}
return flatParams;
}
private static List<Parameter> flattenParamsValue(Object value, String keyPrefix) throws InvalidRequestException {
if (value instanceof Map) {
return flattenParamsMap((Map) value, keyPrefix);
}
if (value instanceof List) {
return flattenParamsList((List) value, keyPrefix);
}
String decode = NPStringFog.decode("");
if (decode.equals(value)) {
throw new InvalidRequestException(NPStringFog.decode("685E441152505F5F5E45114254451116") + keyPrefix + NPStringFog.decode("1611455E11505F11545C41454811424543585F561F11665411585F4554434143544511545C41454811424543585F5642115042115F445D5D11585F1143544044544245421F11685E44115C5048114254451116") + keyPrefix + NPStringFog.decode("1611455E115F445D5D11455E1155545D544554114559541141435E41544345481F"), keyPrefix, null, 0, null);
}
if (value == null) {
List<Parameter> flatParams = new LinkedList<>();
flatParams.add(new Parameter(keyPrefix, decode));
return flatParams;
}
List<Parameter> flatParams2 = new LinkedList<>();
flatParams2.add(new Parameter(keyPrefix, value.toString()));
return flatParams2;
}
private static void handleAPIError(String rBody, int rCode, String requestId) throws InvalidRequestException, AuthenticationException, CardException, APIException {
ErrorParser.StripeError stripeError = ErrorParser.parseError(rBody);
if (rCode != 429) {
switch (rCode) {
case 400:
throw new InvalidRequestException(stripeError.message, stripeError.param, requestId, Integer.valueOf(rCode), null);
case 401:
throw new AuthenticationException(stripeError.message, requestId, Integer.valueOf(rCode));
case 402:
throw new CardException(stripeError.message, requestId, stripeError.code, stripeError.param, stripeError.decline_code, stripeError.charge, Integer.valueOf(rCode), null);
case 403:
throw new PermissionException(stripeError.message, requestId, Integer.valueOf(rCode));
case UIMsg.l_ErrorNo.NETWORK_ERROR_404:
throw new InvalidRequestException(stripeError.message, stripeError.param, requestId, Integer.valueOf(rCode), null);
default:
throw new APIException(stripeError.message, requestId, Integer.valueOf(rCode), null);
}
}
throw new RateLimitException(stripeError.message, stripeError.param, requestId, Integer.valueOf(rCode), null);
}
private static String urlEncodePair(String k, String v) throws UnsupportedEncodingException {
return String.format(NPStringFog.decode("14420C1442"), urlEncode(k), urlEncode(v));
}
private static String urlEncode(String str) throws UnsupportedEncodingException {
if (str == null) {
return null;
}
return URLEncoder.encode(str, NPStringFog.decode("6465771C09"));
}
private static StripeResponse makeURLConnectionRequest(String method, String url, String query, RequestOptions options) throws APIConnectionException {
HttpURLConnection conn;
int rCode;
String rBody;
HttpURLConnection conn2 = null;
char c = 65535;
try {
try {
int hashCode = method.hashCode();
if (hashCode != 70454) {
if (hashCode == 2461856 && method.equals(NPStringFog.decode("617E6265"))) {
c = 1;
if (c != 0) {
conn = createGetConnection(url, query, options);
} else if (c == 1) {
conn = createPostConnection(url, query, options);
} else {
throw new APIConnectionException(String.format(NPStringFog.decode("645F4354525E565F584B54551179656561115C5445595E551114421F116559584211585F5558525045544211501153445611585F11455954116245435841541153585F55585F56421F11615D5450425411525E5F4550524511424441415E4345714245435841541F525E5C11575E4311504242584245505F52541F"), method));
}
rCode = conn2.getResponseCode();
if (rCode < 200 && rCode < 300) {
rBody = getResponseBody(conn2.getInputStream());
} else {
rBody = getResponseBody(conn2.getErrorStream());
}
Map<String, List<String>> headers = conn2.getHeaderFields();
return new StripeResponse(rCode, rBody, headers);
}
if (c != 0) {
}
rCode = conn2.getResponseCode();
if (rCode < 200) {
}
rBody = getResponseBody(conn2.getErrorStream());
Map<String, List<String>> headers2 = conn2.getHeaderFields();
return new StripeResponse(rCode, rBody, headers2);
}
if (method.equals(NPStringFog.decode("767465"))) {
c = 0;
if (c != 0) {
}
rCode = conn2.getResponseCode();
if (rCode < 200) {
}
rBody = getResponseBody(conn2.getErrorStream());
Map<String, List<String>> headers22 = conn2.getHeaderFields();
return new StripeResponse(rCode, rBody, headers22);
}
if (c != 0) {
}
rCode = conn2.getResponseCode();
if (rCode < 200) {
}
rBody = getResponseBody(conn2.getErrorStream());
Map<String, List<String>> headers222 = conn2.getHeaderFields();
return new StripeResponse(rCode, rBody, headers222);
} catch (IOException e) {
throw new APIConnectionException(String.format(NPStringFog.decode("787E744952544145585E5F11554443585F5611706178114354404454424511455E1162454358415411191442180B11144211615D5450425411525954525A11485E444311585F4554435F544511525E5F5F545245585E5F11505F551145434811505650585F1F11785711455958421141435E535D545C1141544342584245421D11485E441142595E445D5511525954525A1162454358415416421142544347585254114245504544421150451159454541420B1E1E454658454554431F525E5C1E4245435841544245504544421D115E43115D5445114442115A5F5E4611504511424441415E4345714245435841541F525E5C1F"), getApiUrl(), e.getMessage()), e);
}
} finally {
if (conn2 != null) {
conn2.disconnect();
}
}
}
private static String getResponseBody(InputStream responseStream) throws IOException {
String rBody = new Scanner(responseStream, NPStringFog.decode("6465771C09")).useDelimiter(NPStringFog.decode("6D70")).next();
responseStream.close();
return rBody;
}
public static final class Parameter {
public final String key;
public final String value;
public Parameter(String key, String value) {
this.key = key;
this.value = value;
}
}
}