google play 此应用使用的结算功能版本已不能受支持。
来源:互联网 发布:bluehost域名绑定主机 编辑:程序博客网 时间:2024/06/06 04:39
谷歌提供的支付版本需要强制更新,需要开发者更新sdk支付版本。
google paly v3代码解析
今天跟大家一起看下Google的in-app Billing V3支付。
- mHelper.launchPurchaseFlow(MainActivity.this,“android.test.purchased”,RC_REQUEST,mPurchaseFinishedListener);
四:测试用的app一定要跟上传到Google的测试版的包名、版本code、name、签名一致,否则无法进行支付测试。
1.下载in-app-billing-v03,下载地址:http://pan.baidu.com/share/link?shareid=1387554851&uk=473193131将下载后的压缩包解压:
将src目录下两个包及包中的java文件引入工程,例如:
2.添加权限:
- <uses-permissionandroid:nameuses-permissionandroid:name="com.android.vending.BILLING"/>
- String base64EncodedPublicKey ="";此处填写Google控制台添加新应用程序后的appid
- mHelper =new IabHelper(this, base64EncodedPublicKey);
- // enable debuglogging (for a production application, you should set this tofalse).
- mHelper.enableDebugLogging(false);
- // Start setup. This is asynchronous andthe specified listener
- // will be called oncesetup completes.
- Log.d(TAG,"Starting setup.");
- mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener(){
- publicvoid onIabSetupFinished(IabResult result){
- Log.d(TAG,"Setupfinished.");
- if (!result.isSuccess()) {
- // Ohnoes, there was a problem.
- complain("Problemsetting up in-app billing: " + result);
- return;
- }
- iap_is_ok = true;
- //Hooray, IAB is fully set up. Now, let's get an inventory of stuffwe own.
- Log.d(TAG, "Setup successful. Queryinginventory.");
- }
- });
- if(iap_is_ok){
- mHelper.launchPurchaseFlow(MainActivity.this,skus[1],RC_REQUEST, mPurchaseFinishedListener);
- }else {
- showMessage("提示", "GooglePlay初始化失败,当前无法进行支付,请确定您所在地区支持Google Play支付或重启游戏再试!");
- }
- mHelper.queryInventoryAsync(mGotInventoryListener);
- billingservice =mHelper.getService();
- Bundle querySkus = newBundle();
- querySkus.putStringArrayList("ITEM_ID_LIST", skus);
- try {
- Bundle skuDetails = billingservice.getSkuDetails(3,MainActivity.this.getPackageName(),"inapp", querySkus);
- ArrayList<String> responseList =skuDetails.getStringArrayList("DETAILS_LIST");
- if (null!=responseList) {
- for (String thisResponse :responseList) {
- try {
- SkuDetails d = newSkuDetails(thisResponse);
- for (int i = 0; i <sku_list.size(); i++) {
- if(sku_list.get(i).equals(d.getSku())) {
- price_list.set(i, d.getPrice());
- }
- }
- iapHandler.sendEmptyMessage(0);
- }catch (JSONException e) {
- // TODO Auto-generated catchblock
- e.printStackTrace();
- }
- }
- }
- }catch (RemoteException e) {
- // TODO Auto-generated catchblock
- e.printStackTrace();
- }
- // Callback for when a purchase is finished
- IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener =newIabHelper.OnIabPurchaseFinishedListener() {
- publicvoidonIabPurchaseFinished(IabResult result, Purchase purchase) {
- Log.d(TAG,"Purchase finished: " + result+", purchase: " +purchase);
- if (result.isFailure()) {
- // Oh noes!
- complain("Error purchasing: " + result);
- return;
- }
- Log.d(TAG,"Purchase successful.");
- if(purchase.getSku().equals("coins_100")||purchase.getSku().equals("android.test.purchased")){
- mHelper.consumeAsync(purchase, mConsumeFinishedListener);
- }elseif (purchase.getSku().equals("double_income")) {
- //受管理的商品,开启双倍经验
- showMessage("支付成功","成功购买双倍经验");
- }
- }
- };
- // Called when consumption is complete
- IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =newIabHelper.OnConsumeFinishedListener() {
- publicvoid onConsumeFinished(Purchasepurchase, IabResult result) {
- Log.d(TAG,"Consumption finished. Purchase: "+purchase + ", result: " +result);
- // We know this is the "gas"sku because it's the only onewe consume,
- // so we don't check whichsku was consumed. If you havemore than one
- //sku, you probably shouldcheck...
- if (result.isSuccess()) {
- //successfully consumed, so we apply the effects of the item inour
- //game world's logic, which in our case means filling the gas tank abit
- if(purchase.getSku().equals("coins_100")||purchase.getSku().equals("android.test.purchased")){
- showMessage("支付成功","成功购买100猫币");
- }
- }
- else {
- complain("Error while consuming: " + result);
- }
- }
- };
- // Listener that's called when we finish querying the items weown
- IabHelper.QueryInventoryFinishedListener mGotInventoryListener =newIabHelper.QueryInventoryFinishedListener() {
- publicvoidonQueryInventoryFinished(IabResult result, Inventory inventory){
- Log.d(TAG,"Query inventory finished.");
- if (result.isFailure()) {
- complain("Failed to query inventory: " +result);
- return;
- }
- Log.d(TAG,"Query inventory was successful.");
- if(inventory.hasPurchase("double_income")) {
- //查询到有受管理的商品支付成功需要将道具给用户
- showMessage("成功Restore双倍金币", "查询到有双倍金币需要恢复");
- }elseif(inventory.hasPurchase("cions_100")){
- //查询到不受管理的商品支付成功需要将道具消耗掉
- showMessage("成功Restore100金币","查询到有100金币需要恢复");
- }
- }
- };
- @Override
- protectedvoid onActivityResult(int requestCode,int resultCode, Intent data) {
- // TODO Auto-generated methodstub
- Log.d(TAG, "onActivityResult("+ requestCode + "," +resultCode +"," + data);
- // Pass on theactivity result to the helper for handling
- if(!mHelper.handleActivityResult(requestCode, resultCode, data)){
- // not handled, so handle it ourselves(here's where you'd
- // perform any handling of activityresults not related to in-app
- // billing...
- super.onActivityResult(requestCode,resultCode, data);
- }
- else {
- Log.d(TAG,"onActivityResult handled by IABUtil.");
- }
- }
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
public class MainActivityextends Activity {
static IabHelper mHelper;
private staticboolean iap_is_ok =false;//初始化成功标识
static finalintRC_REQUEST = 10001;
private static StringSKU_GAS ="";
private static Map<String, Purchase>mapPurchase =new HashMap<String, Purchase>();
private static MainActivity mainActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainActivity = this;
String base64EncodedPublicKey ="";//此处请填写你应用的appkey
mHelper =new IabHelper(this, base64EncodedPublicKey);
// enable debug logging (for a production application, you should set this to false).
mHelper.enableDebugLogging(false);
//Start setup. This is asynchronous and the specified listener
// will be called once setup completes.
//初始化谷歌支付sdk
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
publicvoid onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
return;
}
iap_is_ok =true;
Toast.makeText(MainActivity.this, "初始化成功", Toast.LENGTH_LONG).show();
}
});
}
// 查询库存(inventory)完成接口---查询未发货的订单
static IabHelper.QueryInventoryFinishedListenermGotInventoryListener=new IabHelper.QueryInventoryFinishedListener() {
publicvoid onQueryInventoryFinished(IabResult result, Inventory inventory) {
if(result.isFailure()) {
return;
}
Log.d(TAG, "查询成功!");
// 因为SKU_GAS是可重复购买的产品,查询我们的已购买的产品,
// 如果当中有SKU_GAS,我们应该立即消耗它,以方便下次可以重复购买。
List<Purchase> listPu = inventory.getAllPurchases();//查询所有未通知google市场的收到的订单
if(listPu.size() >= 0){
for(Purchase item:listPu){
mapPurchase.put(item.getSku(), item);
//通知服务器我已经付款
Service.purchase( item.getOriginalJson(), item.getSignature());
}
}
Purchase gasPurchase = inventory.getPurchase(SKU_GAS);//查找当前商品是否已经通知发货
if(gasPurchase!=null){
showMessage("提示", "正在为您发货请稍后,请稍后...");
}else{
if(iap_is_ok){
try {
mHelper.launchPurchaseFlow(mainActivity,SKU_GAS,RC_REQUEST, mPurchaseFinishedListener,“您的商品订单id”);//到时候会一起放在google商品信息回传给你
} catch (Exception e) {
Common.error(e.getMessage());
}
}else{
showMessage("提示","Google Play初始化失败,当前无法进行支付,请确定您所在地区支持Google Play支付或重启游戏再试!");
}
}
}
};
//通知谷歌这个商品我已经发货了
public static void continuePurchase(String productId){
mHelper.consumeAsync(mapPurchase.get(productId),mConsumeFinishedListener);
}
// google play支付结果监听
static IabHelper.OnIabPurchaseFinishedListenermPurchaseFinishedListener =new IabHelper.OnIabPurchaseFinishedListener() {
publicvoid onIabPurchaseFinished(IabResult result, Purchase purchase) {
//Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
if (result.isFailure()) {
Toast.makeText(mainActivity,"支付失败", Toast.LENGTH_LONG).show();
return;
}
Toast.makeText(mainActivity,"支付成功", Toast.LENGTH_LONG).show();
//添加未通知的商品信息
mapPurchase.put(purchase.getSku(), purchase);
}
};
// 监听--通知谷歌我已经发货了
static IabHelper.OnConsumeFinishedListenermConsumeFinishedListener =new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) {
//Log.d(TAG, "通知谷歌成功---"+purchase);
}else{
//Log.d(TAG, "通知谷歌失败.");
}
}
};
static Handler myHandler =new Handler() {
public void handleMessage(Message msg) {
switch (msg.what){
case 1:
mHelper.queryInventoryAsync(mGotInventoryListener);
break;
}
super.handleMessage(msg);
}
};
//付款-支付
public staticvoid googlePlay(String productId){
SKU_GAS = productId;
myHandler.sendEmptyMessage(1);
}
private staticvoid showMessage(String title,String message){
new AlertDialog.Builder(mainActivity).setTitle(title).setMessage(message).setPositiveButton("确定",null).show();
}
//支付回调---通知服务器我已经付款
@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data) {
if (mHelper ==null)return;
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}else {
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");//获取订单详细信息
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");//获取谷歌市场的订单校验码
if (requestCode ==RC_REQUEST) {
if(purchaseData!=null){
//google play 回调--通知服务已经支付成功
Service.purchase(purchaseData, dataSignature);
//Log.d(TAG, "支付回调用成功");
}
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
DDleSDK.destroy();
if (mHelper !=null)mHelper.dispose();
mHelper = null;
}
}
- google play 此应用使用的结算功能版本已不能受支持。
- 此版本的应用未配置为通过google play结算
- 此版本的应用程序未配置为通过Google Play结算。有关详情,请访问帮助中心
- google play支付提示“此版本的应用程序未配置为通过Google Play结算。有关详情,请访问帮助中心。”
- "必须搭配使用google play服务才能运行"或“您必须先更新Google Play服务才能运行此应用”-如何安装或更新google play services
- 安卓手机:你的手机没有安装google play服务,因此无法运行此应用
- Android调用已安装市场平台(如Google Play商店,豌豆荚,百度手机助手,应用宝等)评论功能
- GOOGLE PLAY转移已发布的应用到另一开发者账号
- Google Play爆重大漏洞 用户已购买应用消失
- 【Android】使用Google Play应用商店
- Google Play和基于功能的过滤
- Google Play和基于功能的过滤
- 解决google服务框架、google play、google地图、google搜索等基本的应用无使用最简单的方法
- 下载google play 里面的应用
- 下载google play的安卓应用
- Google Play和基于功能的过滤---硬件功能参考
- "google play 已停止运行","com.google.process.gapps已停止运行"问题的解决办法
- 使用google play services lib时 提示需要更新版本
- iOS开发网络数据缓存介绍
- android反编译
- socket编程之addrinfo结构体与getaddrinfo函数
- ftp
- Android(UI篇) 获取ListView的滑动距离
- google play 此应用使用的结算功能版本已不能受支持。
- 主子报表数据源来自异构数据库的解决方法(Jasper report为例)
- 软件项目管理流程总结
- UIView的四个边角单独设置为圆角弧度
- 迅雷评分效果
- Python代码优化:优化原则
- 黑马程序员——Java基础---String类和基本数据类型包装类
- C语言volatile用法
- PADS,ADOBE,CAD工具栏重置(复位)