萝莉来了 v1.2.1版本的 MD5 值为:6055c21e001561c5b114d0da5b392fcb
以下内容为反编译后的 Iap.java 源代码,内容仅作参考
package cn.iyd.iydpay_apk;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.flurry.org.codehaus.jackson.util.MinimalPrettyPrinter;
import com.infinit.MultimodeBilling.tools.MyApplication;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import mm.purchasesdk.OnPurchaseListener;
import mm.purchasesdk.Purchase;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
public class Iap implements OnPurchaseListener {
private static final String DATABASE_NAME = "iydpay_mmiap";
private static final int DATABASE_VERSION = 1;
static Iap mIap;
IydDataBaseHelper iydHelper;
IydNet iydnet;
Context mContext;
String merchant_id;
String user_id;
Data[] query_data = null;
Data[] notify_data = null;
public class Data {
String notifyStatus;
String orderid;
String payStatus;
long payTime;
String paycode;
String tradeid;
Data() {
}
}
private Iap(Context context, String userid, String merchantid) {
this.mContext = context;
this.user_id = userid;
this.merchant_id = merchantid;
this.iydHelper = new IydDataBaseHelper(context, DATABASE_NAME, null, 1);
this.iydnet = new IydNet(context);
}
public static Iap getInstance(Context context, String userid, String merchantid) {
if (mIap == null) {
mIap = new Iap(context, userid, merchantid);
}
return mIap;
}
public void pay(String paycode, String tradeid) {
this.iydHelper.add(paycode, tradeid);
}
public void billingFinish(boolean isSuccess, String tradeid, String orderid, String paycode) {
this.iydHelper.billingFinish(isSuccess, tradeid, orderid);
}
public String notificationServer(HashMap map) {
System.out.println("notificationServer:" + map);
if (map == null) {
return null;
}
JSONObject obj = new JSONObject();
for (String key : map.keySet()) {
Object value = map.get(key);
try {
obj.put(key, value);
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
try {
String tradeid = obj.getString(OnPurchaseListener.TRADEID);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("method", "billing.makePayment"));
params.add(new BasicNameValuePair("merchant_id", this.merchant_id));
params.add(new BasicNameValuePair("user_id", this.user_id));
params.add(new BasicNameValuePair("v", "2"));
params.add(new BasicNameValuePair("payment_type", Iydpay.PAY_MMIAP));
try {
params.add(new BasicNameValuePair("product_id", obj.getString(OnPurchaseListener.PAYCODE)));
params.add(new BasicNameValuePair("iap_data", obj.toString()));
System.out.println(params);
String result = this.iydnet.httpPostResponse("http://joy-app.punchbox.org/billing/services", params);
System.out.println("notificationServer:<" + result + ">");
if (result == null) {
return null;
}
this.iydHelper.notifyFinish(tradeid);
return result;
} catch (JSONException e2) {
e2.printStackTrace();
return null;
}
} catch (JSONException e1) {
e1.printStackTrace();
return null;
}
}
public void log() {
this.iydHelper.log();
}
public boolean check() {
String[] string_array_query = this.iydHelper.getNeedQuery();
String[] string_array_notify = this.iydHelper.getNeedNotify();
if ((string_array_query != null && string_array_query.length > 0) || (string_array_notify != null && string_array_notify.length > 0)) {
this.query_data = null;
this.notify_data = null;
if (string_array_notify != null && string_array_notify.length > 0) {
System.out.println("string_array_notify:" + string_array_notify.length);
this.notify_data = new Data[string_array_notify.length];
for (int i = 0; i < string_array_notify.length; i++) {
this.notify_data[i] = this.iydHelper.getData(string_array_notify[i]);
System.out.println(String.valueOf(i) + ":" + string_array_notify[i] + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + this.notify_data[i]);
}
}
Thread t = new Thread() {
@Override
public void run() {
if (Iap.this.notify_data != null) {
for (int i2 = 0; i2 < Iap.this.notify_data.length; i2++) {
if (Iap.this.notify_data[i2] != null) {
Purchase.getInstance();
System.out.println("notificationServer:" + i2);
System.out.println("paycode:" + Iap.this.notify_data[i2].paycode);
System.out.println("tradeid:" + Iap.this.notify_data[i2].tradeid);
HashMap<String, String> map = new HashMap<>();
map.put(OnPurchaseListener.TRADEID, Iap.this.notify_data[i2].tradeid);
map.put(OnPurchaseListener.PAYCODE, Iap.this.notify_data[i2].paycode);
map.put(OnPurchaseListener.ORDERID, Iap.this.notify_data[i2].orderid);
Iap.this.notificationServer(map);
}
}
}
}
};
t.start();
return true;
}
return false;
}
public class IydDataBaseHelper extends SQLiteOpenHelper {
private final String DATABASE_CREATE;
public IydDataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
this.DATABASE_CREATE = "CREATE TABLE mmiap ( tradeid varchar(64) primary KEY ,orderid varchar(64),paycode varchar(64),payStatus varchar(28),notifyStatus varchar(28),payTime LONG);";
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE mmiap ( tradeid varchar(64) primary KEY ,orderid varchar(64),paycode varchar(64),payStatus varchar(28),notifyStatus varchar(28),payTime LONG);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS mmiap");
onCreate(db);
}
public void add(String paycode, String tradeid) {
Object[] obj = {tradeid, "", paycode, "", "", Long.valueOf(System.currentTimeMillis())};
SQLiteDatabase sd = getWritableDatabase();
sd.execSQL("INSERT OR REPLACE INTO mmiap(tradeid,orderid,paycode,payStatus,notifyStatus,payTime)VALUES(?,?,?,?,?,?)", obj);
close();
}
public void billingFinish(boolean isSuccess, String tradeid, String orderid) {
String payStatus;
if (isSuccess) {
payStatus = MyApplication.RESULT_SUCCESS;
} else {
payStatus = "fail";
}
Object[] obj = {payStatus, orderid, tradeid};
SQLiteDatabase sd = getWritableDatabase();
sd.execSQL("UPDATE mmiap SET payStatus=?,orderid=? WHERE tradeid=?", obj);
close();
}
public void notifyFinish(String tradeid) {
Object[] obj = {MyApplication.RESULT_SUCCESS, tradeid};
SQLiteDatabase sd = getWritableDatabase();
sd.execSQL("UPDATE mmiap SET notifyStatus=? WHERE tradeid=?", obj);
close();
}
public String[] getNeedQuery() {
System.out.println("getNeedQuery");
String[] s = null;
SQLiteDatabase sd = getWritableDatabase();
Cursor cursor = sd.query("mmiap", null, "payStatus=?", new String[]{""}, null, null, null);
int n = cursor.getCount();
int i = 0;
if (n > 0) {
s = new String[n];
while (cursor.moveToNext()) {
s[i] = cursor.getString(cursor.getColumnIndex("tradeid"));
i++;
}
}
cursor.close();
close();
System.out.println(s);
return s;
}
public String[] getNeedNotify() {
System.out.println("getNeedNotify");
String[] s = null;
SQLiteDatabase sd = getWritableDatabase();
Cursor cursor = sd.query("mmiap", null, "notifyStatus=? and payStatus <> ?", new String[]{"", ""}, null, null, null);
int n = cursor.getCount();
int i = 0;
if (n > 0) {
s = new String[n];
while (cursor.moveToNext()) {
s[i] = cursor.getString(cursor.getColumnIndex("tradeid"));
i++;
}
}
cursor.close();
close();
System.out.println(s);
return s;
}
public Data getData(String trade_id) {
String[] str = {trade_id};
Data data = null;
SQLiteDatabase sd = getWritableDatabase();
Cursor cursor = sd.query("mmiap", null, "tradeid=?", str, null, null, null);
if (cursor.moveToNext()) {
String tradeid = cursor.getString(cursor.getColumnIndex("tradeid"));
String orderid = cursor.getString(cursor.getColumnIndex("orderid"));
String paycode = cursor.getString(cursor.getColumnIndex("paycode"));
String payStatus = cursor.getString(cursor.getColumnIndex("payStatus"));
String notifyStatus = cursor.getString(cursor.getColumnIndex("notifyStatus"));
Long payTime = Long.valueOf(cursor.getLong(cursor.getColumnIndex("payTime")));
System.out.println(String.valueOf(tradeid) + "," + orderid + "," + paycode + "," + payStatus + "," + notifyStatus);
data = new Data();
data.tradeid = tradeid;
data.orderid = orderid;
data.paycode = paycode;
data.payStatus = payStatus;
data.notifyStatus = notifyStatus;
data.payTime = payTime.longValue();
}
cursor.close();
close();
return data;
}
public void log() {
System.out.println("-------------------------------log-------------------------------");
SQLiteDatabase sd = getWritableDatabase();
Cursor cursor = sd.query("mmiap", null, null, null, null, null, null);
int i = 0;
while (cursor.moveToNext()) {
i++;
String tradeid = cursor.getString(cursor.getColumnIndex("tradeid"));
String orderid = cursor.getString(cursor.getColumnIndex("orderid"));
String paycode = cursor.getString(cursor.getColumnIndex("paycode"));
String payStatus = cursor.getString(cursor.getColumnIndex("payStatus"));
String notifyStatus = cursor.getString(cursor.getColumnIndex("notifyStatus"));
System.out.println(String.valueOf(i) + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + tradeid + "," + orderid + "," + paycode + "," + payStatus + "," + notifyStatus);
}
cursor.close();
close();
}
}
@Override
public void onAfterApply() {
}
@Override
public void onAfterDownload() {
}
@Override
public void onBeforeApply() {
}
@Override
public void onBeforeDownload() {
}
@Override
public void onBillingFinish(int arg0, HashMap arg1) {
}
@Override
public void onInitFinish(int arg0) {
}
@Override
public void onQueryFinish(int code, HashMap arg1) {
System.out.println("onQueryFinish: code" + code + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + arg1);
if (code == 102 || code == 104) {
String orderID = (String) arg1.get(OnPurchaseListener.ORDERID);
String paycode = (String) arg1.get(OnPurchaseListener.PAYCODE);
String tradeID = (String) arg1.get(OnPurchaseListener.TRADEID);
billingFinish(true, tradeID, orderID, paycode);
notificationServer(arg1);
return;
}
billingFinish(false, null, null, null);
}
}