آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

مشکل در پرداخت درون برنامه لطفا کمک کنیدحل شد + سورس کد

دانیال  10 سال پیش  10 سال پیش
+1 0

سورس کد در پایین قرار گرفت

 برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال 
دانیال  10 سال پیش
0 0

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import java.util.ArrayList;

import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.entity.BufferedHttpEntity; 
import org.apache.http.impl.client.DefaultHttpClient; 


import android.app.ActionBar.LayoutParams;
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.ProgressDialog; 
import android.content.Context;
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.content.SharedPreferences.Editor; 
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle; 
import android.preference.PreferenceManager; 
import android.util.Log; 
import android.view.View; 
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener; 
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button; 
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView; 
import android.widget.Toast; 
import android.app.*;
import android.content.*;
import android.content.pm.*;
import android.net.*;
import android.os.*;
import android.preference.*;
import android.util.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import com.utils.*;
import android.telephony.*;
import java.util.*;

public class pro extends Activity{



	int update = 0;
	public ProgressDialog dialog ;
	Button btn1; 
	Button btn2;
	SharedPreferences sp;



	///دخیره پریمیوم
	public static final String KEY_PREMIUM_VERSION = "VERSIONapp";
	private String              payload; // رشته ی منحصر به فردی که ما اون رو تولید میکنیم و به هنگام خرید به بازار ارسال میکنیم

//Debug tag, for logging 
	static final String TAG = "SmsBaaz"; 
//SKUs for our products: the premium upgrade (non-consumable) 
	static final String SKU_PREMIUM = "adad.app"; 
//Does the user have the premium upgrade? 
	boolean mIsPremium = false; 
//(arbitrary) request code for the purchase flow 
	static final int RC_REQUEST = 10001; 
//The helper object 
	IabHelper mHelper; 



	@Override
	protected void onCreate(Bundle savedInstanceState) { 
		// TODO Auto-generated method stub 
		super.onCreate(savedInstanceState); 

		setContentView(R.layout.buy_premium_activity); 


		
		
		




		TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
		payload = telephonyManager.getDeviceId();



		// show loading dialog with ProgressDialog
        dialog = new ProgressDialog(this);
        dialog.setCancelable(false);
        dialog.setInverseBackgroundForced(false);





		// btn1=(Button) findViewById(R.id.onlinebtn);
		//btn1.setOnClickListener(new OnClickListener() { 

		//@Override
		//	public void onClick(View v) { 
		// TODO Auto-generated method stub 


		//	} 
		//	}); 

		btn2=(Button) findViewById(R.id.button_buy);

		btn2.setText(payload);
		sp = PreferenceManager.getDefaultSharedPreferences(this  );







		dialog.setMessage("بررسی سبد خرید");
		dialog.show();
		String base64EncodedPublicKey = "MIHNMA0GCSqGSIb3DQEBAQUAA4G7ADCBtwKBrwC1y1br2Toqwq3Dm7HYrqYihFeoEUpjTM/msWEXK8+PzWYDjm3VEYImNWCVyDLQP6sq8pkbZMU0vAYjMq7PiI8xvrENHsFmrpmOxig2WvBfRoGTAkWCFJd7Fj7Z3uMJ1s8WZoGAHKL85tVqCU5Zt8Dup6oYh5cOOieRd3nXAfcjjBT1+Qv4kVxnsQTSb/MSm7EJlyAIDEnACxFeHiqV9BtnZZCWLitkQkbHtF7SR1UCAwEAAQ=="; 
		// You can find it in your Bazaar console, in the Dealers section.  
		// It is recommended to add more security than just pasting it in your source code; 
		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()) { 
						//				Toast.makeText(getApplicationContext(),"وارد اکانت حساب کاربری خود در بازار شوید."+"\n"+"یا اتصال به اینترنت را بررسی کنید.",Toast.LENGTH_LONG).show();

						// Oh noes, there was a problem. 
						Log.d(TAG, "Problem setting up In-app Billing: " + result); 
					} 
					// Hooray, IAB is fully set up! 
					mHelper.queryInventoryAsync(mGotInventoryListener)  ; 

				} 


			}); 



	}













//با آغاز اکتیویتی کد زیر اجرا میشود که برای جستجو premium بودن میباشد. 
//اگر کاربر premium باشد دیالوگ loading مخفی میشه dialog.hide() متد UpdateUi() اجرا میشه و محتوای این متد را در باتن قرار میده. 
//اگر کاربر premium نباشه هم منتظر لمس کردن کاربر بر روی دکمه میشه که متد onOnlineUpgradeAppButtonClicked را فراخوانی کند. 
	IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { 
		public void onQueryInventoryFinished(IabResult result, Inventory inventory) { 
			Log.d(TAG, "Query inventory finished."); 
			if (result.isFailure()) { 
				Log.d(TAG, "Failed to query inventory: " + result); 
				dialog.hide();
				//	Toast.makeText(getApplicationContext(),"خطا در ارتباط با سرور."+"\n"+"وارد اکانت حساب کاربری خود در بازار شوید."+"\n"+"یا اتصال به اینترنت را بررسی کنید.",Toast.LENGTH_LONG).show();
				return; 
			} 
			else { 



				Log.d(TAG, "Query inventory was successful."); 
				// does the user have the premium upgrade? 
				mIsPremium = inventory.hasPurchase(SKU_PREMIUM); 

				// update UI accordingly 

				Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM")); 
			} 
			dialog.hide();
			updateUi();
			Log.d(TAG, "Initial inventory query finished; enabling main UI."); 

		} 

	}; 



	@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.");
        }
    }
	
////جلوگیری از هک شدن پرداخت درون برنامه
	IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
            if (!result.isFailure()) {
				
                if (purchase.getOrderId().equals(purchase.getToken())) {
                    if (purchase.getSku().equals(SKU_PREMIUM)
						&& purchase.getDeveloperPayload().equals(payload)) {
						//Purchase successfull.
						
						{
                    }
                } else {
					//Purchase is not valid!
					Toast.makeText(getApplicationContext(), "خرید موفق آمیز بود", Toast.LENGTH_LONG).show();

					SharedPreferences shared = getSharedPreferences("Prefs", MODE_PRIVATE);
					SharedPreferences.Editor editor = shared.edit();
					editor.putBoolean("MIHNMA0GCSqGSIb3DQEBAQUAA4G7ADCBtwKBrwC1y1br2Toqwq3Dm7HYrqYihFeoEUpjTM/msWEXK8+PzWYDjm3VEYImNWCVyDLQP6sq8pkbZMU0vAYjMq7PiI8xvrENHsFmrpmOxig2WvBfRoGTAkWCFJd7Fj7Z3uMJ1s8WZoGAHKL85tVqCU5Zt8Dup6oYh5cOOieRd3nXAfcjjBT1+Qv4kVxnsQTSb/MSm7EJlyAIDEnACxFeHiqV9BtnZZCWLitkQkbHtF7SR1UCAwEAAQ==", true);
					editor.apply();
					Intent intentz = new Intent(
						pro.this,
						main.class);
					intentz.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
									 | Intent.FLAG_ACTIVITY_NEW_TASK);

					finish();
					startActivity(intentz);
					
					}
					}else{
						Toast.makeText(getApplicationContext(), "لطفا برنامه را هک نکنید", Toast.LENGTH_LONG).show();
					
					
                }
            }
            if (mHelper != null)
                mHelper.flagEndAsync();

        }
    };
	@Override
	public void onDestroy() { 
		super.onDestroy(); 

		Log.d(TAG, "Destroying helper."); 
		if (mHelper != null) mHelper.dispose(); 
		mHelper = null; 
	} 



// اگر کاربر پریمیوم باشد دستورات آپدیت را انجام میدهد در غیر اینصورت به صفحه خرید هدایت می شود. 
	public void updateUi() { 

		if (mIsPremium) { 

            update = 224;



			//    Toast.makeText(getApplicationContext(),"شما کاربر ویژه هستید",Toast.LENGTH_LONG).show();


		} 

		else
		{       

			Toast.makeText(getApplicationContext(),"نرم افزار خریداری نشده است",Toast.LENGTH_LONG).show();

		} 
	} 






	void complain(String message) { 
		Log.e(TAG, "**** testbilling Error: " + message); 
	} 





	private boolean isNetworkConnected() { 
		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo ni = cm.getActiveNetworkInfo();
		if (ni == null) {
			////چک نت
			Toast.makeText(getApplicationContext(), "لطفا ابتدا به اینترنت متصل شوید", Toast.LENGTH_LONG).show();
			return false;
		} else
			return true;
    }

	public static boolean isPackageInstalled(String packagename,Context context) {
		PackageManager pm = context.getPackageManager();
		try {
			pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
			return true;}
		catch (NameNotFoundException e) {
			return false;}
	}

	public void onOnlineUpgradeAppButtonClicked(View arg0) {



		if(!isPackageInstalled("com.farsitel.bazaar", pro.this)){
			Toast.makeText(getApplicationContext(), "لطفا ابتدا بازار را نصب کنید", Toast.LENGTH_LONG).show();

		}
		else{
			if(isNetworkConnected()){


				Log.d(TAG, "Upgrade button clicked; launching purchase flow for upgrade."); 

				/* TODO: for security, generate your payload here for verification. See the comments on 
				 * verifyDeveloperPayload() for more info. Since this is a SAMPLE, we just use 
				 * an empty string, but on a production app you should carefully generate this. */
				//String payload = "inbarnametavasotehamedjjsakhteshodeast";

				mHelper.launchPurchaseFlow(pro.this, SKU_PREMIUM, RC_REQUEST,
										   mPurchaseFinishedListener, payload);



			}
		}


	} 





	private static long back_pressed = 0L;
	@Override
	public void onBackPressed()
	{
		finish(); 
		
	}}
 
 
 
 
 
  

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .