OurPlay v5.5.9版本的 MD5 值为:d4e139798f4c2243a1145c8af5e21046
以下内容为反编译后的 WxPay.java 源代码,内容仅作参考
package com.excelliance.kxqp.payer.wx;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import com.alipay.sdk.util.l;
import com.excelliance.kxqp.gs.util.ab;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.analytics.pro.am;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Random;
import java.util.Stack;
import org.apache.http.client.utils.URLEncodedUtils;
import org.json.JSONObject;
public class WxPay extends BasePay {
private static final String API_ORDER = "https://sdk.ourplay.com.cn/wepay/v1/unifiedorder.php";
public static final String BASE_URL = "https://sdk.ourplay.com.cn/wepay/";
public static final boolean DEBUG_LOG = false;
private static final int HTTP_REQUEST_TIMEOUT = 30000;
private static final String LYL_KEY = "lylptpay";
public static final String TAG = "WxPay";
private static char[] charSetArray = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
static WxPay mPay;
private Context mContext;
String mPayId;
private HttpURLConnection mCfgUrlConn = null;
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int i;
String action = intent.getAction();
if (action == null) {
return;
}
if (!action.equals(context.getPackageName() + ".action.payresult") || WxPay.this.callback == null) {
return;
}
int intExtra = intent.getIntExtra(l.c, -1);
String stringExtra = intent.getStringExtra("prepayId");
if (intExtra == 0) {
i = BasePay.PAY_OK;
} else if (intExtra == -2) {
i = BasePay.PAY_CANCEL;
} else {
i = BasePay.PAY_ERROR;
}
WxPay.this.callback.onPayFinish(i, stringExtra);
}
};
public WxPay(Context context) {
this.mContext = context;
IntentFilter intentFilter = new IntentFilter(context.getPackageName() + ".action.payresult");
if (context instanceof Activity) {
context.getApplicationContext().registerReceiver(this.receiver, intentFilter);
} else {
context.registerReceiver(this.receiver, intentFilter);
}
}
public static WxPay getInstance(Context context) {
if (mPay == null) {
mPay = new WxPay(context);
}
return mPay;
}
@Override
public int pay(float f, int i, String str) {
if (mPay == null) {
return 1;
}
this.mPayId = str;
fetchWxSignResult(i);
return 0;
}
@Override
public void destroy() {
try {
if (this.mContext instanceof Activity) {
this.mContext.getApplicationContext().unregisterReceiver(this.receiver);
} else {
this.mContext.unregisterReceiver(this.receiver);
}
} catch (Exception unused) {
}
this.mContext = null;
this.callback = null;
mPay = null;
}
public void wxPay(String str, String str2, String str3, String str4, String str5, String str6, String str7, String str8) {
IWXAPI createWXAPI = WXAPIFactory.createWXAPI(this.mContext, str);
createWXAPI.registerApp(str);
PayReq payReq = new PayReq();
payReq.appId = str;
payReq.partnerId = str2;
payReq.prepayId = str3;
payReq.nonceStr = str4;
payReq.timeStamp = str5;
payReq.packageValue = str6;
payReq.sign = str7;
if (str8 != null && str8.length() > 0) {
payReq.extData = str8;
}
createWXAPI.sendReq(payReq);
}
private void fetchWxSignResult(final int i) {
Log.d(TAG, "fetchWxSignResult: " + i);
new Thread(new Runnable() {
@Override
public void run() {
try {
boolean prepareCfgConnect = WxPay.this.prepareCfgConnect(WxPay.API_ORDER);
Log.d(WxPay.TAG, "fetchWxSignResult: cb " + prepareCfgConnect);
if (!prepareCfgConnect || WxPay.this.mCfgUrlConn == null) {
return;
}
String outTradeNo = WxPay.this.getOutTradeNo(WxPay.this.mContext, i);
String encrypt = WxPay.encrypt(outTradeNo);
WxPay.this.log("fetchWxSignResult: orderParam = " + outTradeNo + ", encodedParam = " + encrypt);
DataOutputStream dataOutputStream = new DataOutputStream(WxPay.this.mCfgUrlConn.getOutputStream());
dataOutputStream.writeBytes(encrypt);
dataOutputStream.flush();
dataOutputStream.close();
if (WxPay.this.mCfgUrlConn.getResponseCode() == 200) {
String str = "";
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(WxPay.this.mCfgUrlConn.getInputStream()));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
str = str + readLine;
}
bufferedReader.close();
WxPay.this.log("fetchWxSignResult: result = " + str);
if (TextUtils.isEmpty(str)) {
return;
}
String decrypt = WxPay.decrypt(str, "utf-8");
WxPay.this.log("fetchWxSignResult: decode cfg = " + decrypt);
try {
JSONObject jSONObject = new JSONObject(decrypt);
String optString = jSONObject.optString("appid");
String optString2 = jSONObject.optString("partnerid");
String optString3 = jSONObject.optString("prepayid");
String optString4 = jSONObject.optString("package");
String optString5 = jSONObject.optString("noncestr");
String optString6 = jSONObject.optString(com.alipay.sdk.tid.b.f);
String optString7 = jSONObject.optString("sign");
String optString8 = jSONObject.optString("extdata");
WxPay.this.log("fetchWxSignResult: appid = " + optString + ", partnerid = " + optString2 + ", prepayid = " + optString3 + ", pkg = " + optString4 + ", noncestr = " + optString5 + ", timestamp = " + optString6 + ", sign = " + optString7 + ", extdata = " + optString8);
WxPay.this.wxPay(optString, optString2, optString3, optString5, optString6, optString4, optString7, optString8);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e2) {
Log.e(WxPay.TAG, "fetchWxSignResult e:" + e2);
e2.printStackTrace();
}
}
}).start();
}
public boolean prepareCfgConnect(String str) {
try {
this.mCfgUrlConn = null;
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setUseCaches(false);
httpURLConnection.setInstanceFollowRedirects(true);
httpURLConnection.setConnectTimeout(HTTP_REQUEST_TIMEOUT);
httpURLConnection.setReadTimeout(HTTP_REQUEST_TIMEOUT);
httpURLConnection.setRequestProperty("Content-Type", URLEncodedUtils.CONTENT_TYPE);
this.mCfgUrlConn = httpURLConnection;
return true;
} catch (Exception unused) {
return false;
}
}
public String getOutTradeNo(Context context, int i) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(getManifestMeta(context, "VersionCode"));
stringBuffer.append("_");
stringBuffer.append(com.excelliance.kxqp.payer.a.c(getManifestMeta(context, "MainChId")));
stringBuffer.append("_");
stringBuffer.append(com.excelliance.kxqp.payer.a.c(getManifestMeta(context, "SubChId")));
stringBuffer.append("_");
stringBuffer.append(getAndroidId(context));
stringBuffer.append("_");
stringBuffer.append(com.excelliance.kxqp.payer.a.c(context.getSharedPreferences("userInfo", Build.VERSION.SDK_INT < 11 ? 0 : 4).getString("uid", null)));
stringBuffer.append("_");
stringBuffer.append(am.aC);
stringBuffer.append("_");
String rid = getRid(context);
log("rid = " + rid);
stringBuffer.append(com.excelliance.kxqp.payer.a.c(rid));
stringBuffer.append("_");
stringBuffer.append(com.excelliance.kxqp.payer.a.c(String.valueOf(i)));
stringBuffer.append("_");
stringBuffer.append(new Random().nextInt());
String stringBuffer2 = stringBuffer.toString();
return stringBuffer2.length() > 64 ? stringBuffer2.substring(0, 64) : stringBuffer2;
}
public static String convertDecimalTo62Hex(String str) {
try {
Stack stack = new Stack();
StringBuilder sb = new StringBuilder(0);
for (Long valueOf = Long.valueOf(str); valueOf.longValue() != 0; valueOf = Long.valueOf(valueOf.longValue() / 62)) {
stack.add(Character.valueOf(charSetArray[new Long(valueOf.longValue() - ((valueOf.longValue() / 62) * 62)).intValue()]));
}
while (!stack.isEmpty()) {
sb.append(stack.pop());
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return str;
}
}
public static String decrypt(String str, String str2) {
return decrypt(str, LYL_KEY, str2);
}
public static String decrypt(String str, String str2, String str3) {
return ab.a(str, str2, str3);
}
public static String encrypt(String str) {
return encrypt(str, LYL_KEY);
}
public static String encrypt(String str, String str2) {
try {
byte[] bytes = str2.getBytes("utf-8");
byte[] bytes2 = str.getBytes("utf-8");
for (byte b2 : bytes) {
for (int i = 0; i < bytes2.length; i++) {
bytes2[i] = (byte) (bytes2[i] ^ b2);
}
}
return Base64.encodeToString(bytes2, 0);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static String getManifestMeta(Context context, String str) {
try {
ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128);
if (applicationInfo == null) {
return "";
}
if (str.equals("VersionCode")) {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
return packageInfo != null ? String.valueOf(packageInfo.versionCode) : "";
}
if (str.equals("MainChId")) {
return String.valueOf(applicationInfo.metaData.get("MainChId"));
}
return str.equals("SubChId") ? String.valueOf(applicationInfo.metaData.get("SubChId")) : "";
} catch (Exception unused) {
return "";
}
}
public static String getAndroidId(Context context) {
if (context != null) {
return com.excelliance.kxqp.util.a.b.e(context);
}
return null;
}
public static String getImei(Context context) {
try {
return com.excelliance.kxqp.util.a.b.c(context);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public String getRid(Context context) {
int intSpValueWithAesDecript = getIntSpValueWithAesDecript(context.getSharedPreferences("USERINFO", Build.VERSION.SDK_INT < 11 ? 0 : 4), "USER_ID");
return intSpValueWithAesDecript != 0 ? String.valueOf(intSpValueWithAesDecript) : "";
}
public int getIntSpValueWithAesDecript(SharedPreferences sharedPreferences, String str) {
if (sharedPreferences == null || TextUtils.isEmpty(str)) {
return 0;
}
try {
return Integer.valueOf(a.a(sharedPreferences.getString(str, a.a("0")), "keics_e21p3kds8s")).intValue();
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
public void log(Object obj) {
Log.d(TAG, "MSG:" + obj);
}
}