۱۳۹۴/۰۵/۰۴, ۱۱:۳۹ ق.ظ
سلام دوستان عزیز من تو پرداخت درون برنامه ای تحت سرور با رفرش کردن توکن id مشکل دارم
خواهشن راهنمایی کنید چیکار باید کنم
اینم سورس جاوا
بنظرتون کجای سورس اشتباست
خواهشن راهنمایی کنید چیکار باید کنم
اینم سورس جاوا
بنظرتون کجای سورس اشتباست
کد پیاچپی:
public class Pool extends Activity {
private ProgressDialog progressDialog;
public static String order;
private Dialog dialog;
public static int g = 0;
SharedPreferences preferences = null;
private String PACKAGENAME = "";
final String KEY = "PERIMIUM";
// Debug tag, for logging
static final String TAG = "savedPremium";
// SKUs for our products: the premium upgrade (non-consumable)
static final String SKU_PREMIUM = "how";
// Does the user have the premium upgrade?
boolean mIsPremium1 = false;
// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 10001;
// The helper object
IabHelper mHelper;
private SharedPreferences shared;
private SharedPreferences.Editor editor;
private Typeface typeface;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pool);
button = (Button) findViewById(R.id.btnpool);
typeface = Typeface.createFromAsset(getAssets(), "fonts/titr.ttf");
button.setTypeface(typeface);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
onSavedUpgradeAppButtonClicked(arg0);
// verifytoken();
}
});
shared = getSharedPreferences("Pref", MODE_PRIVATE);
editor = shared.edit();
g = shared.getInt("mon", 0);
/************************************************** ************************************************** *******/
preferences = getSharedPreferences(PACKAGENAME, Context.MODE_PRIVATE);
PACKAGENAME = getClass().getName();
Log.e("TAG", PACKAGENAME);
mIsPremium1 = preferences.getBoolean(KEY, false);
if (mIsPremium1 == true) {
updateUi();
return;
}
String base64EncodedPublicKey = "MIHNMA0GCSqGSCpgXp3J1b4KKwYgzNx3EyqOpRccZXk4p JtwO nXVavJxiooZHNRul5v0eT2NvCPmPoNeqgRIX1MilemLyqfksJt m8hxFTQYfcFriFXl8+Sq2RPtL2z+RIG1wECAwEAAQ==";
mHelper = new IabHelper(this, base64EncodedPublicKey);
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
}
});
/************************************************** ************************************************** *******/
}
/************************************************** ************************************************** *******/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
+ data);
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
public void onSavedUpgradeAppButtonClicked(View arg0) {
Log.d(TAG,
"Upgrade button clicked; launching purchase flow for upgrade.");
// setWaitScreen(true);
String payload = "gdhassdflsldaslfkahsjahsjakaasa";
mHelper.launchPurchaseFlow(this, SKU_PREMIUM, RC_REQUEST,
mPurchaseFinishedListener, payload);
}
boolean verifyDeveloperPayload(Purchase p) {
//String payload =p.getDeveloperPayload();
order=p.getOrderId();
return true;
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: "
+ purchase);
Inventory inv = null;
try {
inv = mHelper.queryInventory(true, null);
if (inv.hasPurchase(SKU_PREMIUM)) {
// alert("تبريک شما به کاربر ويژه ارتقا يافتيد");
if (purchase.getSku().equals(SKU_PREMIUM)) {
// Log.d(TAG,
// "Purchase is premium upgrade. Congratulating user.");
// // alert("تبريک شما به کاربر ويژه ارتقا يافتيد");
// editor.putInt("mon", 1);
// editor.apply();
//
// mIsPremium1 = true;
// updateUi();
// setWaitScreen(false);
order=purchase.getOrderId();
verifytoken();
}
// حالا برنامه را فعال کنيد
} else {
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
// setWaitScreen(false);
return;
}
if (!verifyDeveloperPayload(purchase)) {
complain("Error purchasing. Authenticity verification failed.");
// setWaitScreen(false);
return;
}
Log.d(TAG, "خريد نادرست است");
}
} catch (IabException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
// Update button with updateUi
public void updateUi() {
if (mIsPremium1) {
AlertDialog.Builder builder=new AlertDialog.Builder(Pool.this);
builder.setTitle("کاربر ويژه");
builder.setMessage("تبريک ميگم"+"\n"+"دوست عزيز شما به کاربر ويژه ارتقا يافتيد");
builder.setPositiveButton("خب", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
startActivity(new Intent(Pool.this,StartActivity.class));
}
});
builder.show();
SharedPreferences.Editor newtask = preferences.edit();
newtask.putBoolean(KEY, true);
newtask.commit();
}
}
void complain(String message) {
Log.e(TAG, "**** testbilling Error: " + message);
alert("Error: " + message);
}
void alert(String message) {
AlertDialog.Builder bld = new AlertDialog.Builder(this);
bld.setMessage(message);
bld.setNeutralButton("OK", null);
Log.d(TAG, "Showing alert dialog: " + message);
bld.create().show();
}
/************************************************** ************************************************** *******/
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "Destroying helper.");
if (mHelper != null)
mHelper.dispose();
mHelper = null;
}
public void verifytoken() {
progressDialog=new ProgressDialog(Pool.this);
progressDialog = ProgressDialog.show(this, "خريد", "لطفا چند لحظه صبر کنيد تا بررسي خريد صورت بگيرد...");
new RequestTask().execute("http://www.BBccountry.ir/token/token.php?package=com.dev.howold&product=howold&to kenid="+order);
}
class RequestTask extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
responseString = out.toString();
out.close();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
//TODO Handle problems..
} catch (IOException e) {
//TODO Handle problems..
}
return responseString;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
progressDialog.dismiss();
if (result.length() > 5){
Log.d(TAG, "Purchase is premium upgrade. Congratulating user." + result + result.length());
Toast.makeText(getApplicationContext(), "پرداخت انجام شد", Toast.LENGTH_SHORT).show();
mIsPremium1 = true;
updateUi();
// setWaitScreen(false);
} else {
Log.d(TAG, "natigeh" + result);
// setWaitScreen(false);
Toast.makeText(getApplicationContext(), "پرداخت انجام نشد", Toast.LENGTH_SHORT).show();
}
}
}
}