android平台下, 谷歌应用收费提供了最新的google-billing接口,该接口用来发送请求应用收费和管理应用收费事物。下面简单介绍应用收费的实现过程。
实现android应用的支付功能需要做到以下几点:
1.查看google应用支付功能提供的最新开发文档,了解应用内支付功能的机制,具体参考http://developer.android.com/guide/google/play/billing/index.html
2.升级android sdk开发环境,安装google-billing的api,添加IMarketBillingService,将aild文件添加到项目中(参看附加图片,aidl路径。须确认最新公布google billing的aidl文件已经为V2版本)。
用于实现五类的计费请求:
1)检查账单的支付请求(request);
2)请求进行购买的请求(purchast);
3)获取购买信息的请求(receiver);
4)确认通知的请求(confirm);
5)恢复交易的请求(restore)。
3.更新AndroidManifest.xml文件。添加权限设置以及调用服务的设置。
<uses-permission android:name="com.android.vending.BILLING" />
<service android:name=".billing.BillingService" />
<application
<receiver android:name=".billing.BillingReceiver">
<intent-filter>
<action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
<action android:name="com.android.vending.billing.RESPONSE_CODE" />
<action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
4.创建服务用于绑定到IMarketBillingService,android应用程序可以通过该service进行发送用户的购买请求和接收来自google play store的计费响应账单。
BillingService mService = IMarketBillingService.Stub.asInterface(service);
5.创建BillingReceiver用于接受来自IPC发送的广播信息。
public class BillingReceiver extends BroadcastReceiver {
private static final String TAG = "BillingReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i(TAG, "Received action: " + action);
if (Const.ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
String signedData = intent.getStringExtra(Const.INAPP_SIGNED_DATA);
String signature = intent.getStringExtra(Const.INAPP_SIGNATURE);
purchaseStateChanged(context, signedData, signature);
} else if (Const.ACTION_NOTIFY.equals(action)) {
String notifyId = intent.getStringExtra(Const.NOTIFICATION_ID);
notify(context, notifyId);
} else if (Const.ACTION_RESPONSE_CODE.equals(action)) {
long requestId = intent.getLongExtra(Const.INAPP_REQUEST_ID, -1);
int responseCodeIndex = intent.getIntExtra(Const.INAPP_RESPONSE_CODE, Const.ResponseCode.RESULT_ERROR.ordinal());
checkResponseCode(context, requestId, responseCodeIndex);
} else {
Log.e(TAG, "unexpected action: " + action);
}
}
private void purchaseStateChanged(Context context, String signedData, String signature) {
Log.i(TAG, "purchaseStateChanged got signedData: " + signedData);
Log.i(TAG, "purchaseStateChanged got signature: " + signature);
BillingHelper.verifyPurchase(signedData, signature);
}
private void notify(Context context, String notifyId) {
Log.i(TAG, "notify got id: " + notifyId);
String[] notifyIds = {notifyId};
BillingHelper.getPurchaseInformation(notifyIds);
}
private void checkResponseCode(Context context, long requestId, int responseCodeIndex) {
Log.i(TAG, "checkResponseCode got requestId: " + requestId);
Log.i(TAG, "checkResponseCode got responseCode: " + Const.ResponseCode.valueOf(responseCodeIndex));
}
}
6.创建一个安全处理的组件BillingSecurity,用于包含应用的支付功能以及账户的安全问题,将google play 上的发布应用的public key 作为验证的密钥,进行交易的安全验证。
7.修改应用代码,实现各接口,用于支持应用的收费功能。
注:
1)以上仅是简单介绍in-app-billing的实现过程,在操作之前,需要了解完成的支付机制,明确各接口需要的参数以及应用内产品设置。根据需求,开发者需要明确,应用是属于购买还是订阅功能,在google play上传时应用,可以参考: http://developer.android.com/guide/google/play/billing/billing_admin.html
2)在应用功能完成上架之前,必须对支付功能进行测试。用于测试的方式有两种:
一种利用静态响应对应用的内够功能进行测试;
另一种是使用开发者的商品ID对应用的内够功能进行测试。
具体可以参考:http://developer.android.com/guide/google/play/billing/billing_testing.html。
3)测试中会遇到一系列的问题,国内用户会有诸多障碍,测试发布流程:
(1)将应用作为测试apk上传到google play;
(2)设置应用商品的购买属性,产品IP等;
(3)在实体android 设备上安装应用;
(4)将google play store上某一账户,设置为设备的主账户;
(5)确保设备上的play store或apps 是最新版本。
- 大小: 5.5 KB
分享到:
相关推荐
Android In-App Billing v3 Library This is a simple, straight-forward implementation of the Android v3 In-app billing API. It supports: In-App Product Purchases (both non-consumable and consumable) ...
Google Play 应用内支付(In-app Billing V2 + V3)官方示例打包下载
自己转换的Android开发指南中的In-app Billing章节, 制作成了6寸的PDF,专门为Kindle3等6寸电纸书设计。
Google Play 应用内购
Godot-Myket-In-App-Billing 适用于Godot Game Engine的软应用内结算插件
react-native-billing, 在Android上,将本地桥反应到InApp计费 用于 Android 的InApp计费 本机计费 为 InApp Billing提供一个易于使用的界面,它通过包装anjlab计费库的 InApp来完成。const InAppBilling = require...
在应用程序内购买 在应用内购买Android应用程序 在应用内购买类型: 当前订阅类型的演示 为Google Play设置IAP
Android高级应用源码-android应用内购买 google app veding billing.zip
安卓计费Android 测试应用程序专注于 Google Play In-app Billing。 第一个版本或多或少基于。
Cut the hassle when implementing in-app purchases on Android. Reactive Billing is a lightweight reactive wrapper around In App Billing API v3 for Android. Features Reactive: Exposes the In App ...
这是Android v3应用内结算API的简单,直接的实现。 它支持:应用内产品购买(非消耗性和消耗性)和订阅。 维护者通缉 该项目正在寻找维护者。 目前,只有外部贡献者的请求请求正在接受,接受和欢迎。 Anjlab团队...
一个基于Google的可示例代码来处理In-App-Billing V3( )的Android库。 该项目的目标是构建一个可靠且经过测试的库,可以轻松地将其作为包含在您的(基于Maven的)项目中。 Google的示例代码已经过重构并可以测试...
Godot-Myket应用内结算示例 Myot在Godot中的App Billing示例项目中 提供一个示例项目,说明如何使用向使用制作的游戏添加应用内账单功能。
googleplay支付demo in-app-billing-v02 in-app-billing-v03
Android In-App Billing v3 Library:开发者通过Android v3 API轻松处理应用程序支付问题
google-billing-4.0.0.jar
资源来自pypi官网。 资源全名:django-aws-billing-0.1.3.tar.gz
Google Play结算示例应用程序。 要构建每个样本,请参阅项目目录中的自述文件说明。 在您的Android应用中购买商品。 -在Android应用程序中购买订阅并在服务器上管理订阅。 在您的Android应用程序中购买订阅并在...
资源来自pypi官网。 资源全名:google-cloud-billing-0.1.0.tar.gz