in-app billing支付可以从服务端app图形验证码验证吗

Android支付接入之Google In-app-Billing
因为公司需要接入Google的应用内支付(即Google的in-app Billing V3),接入过程中查阅了很多的文章,也遇到很多的问题。故此想和大家分享及交流一下心得,好了废话不多说了下面我们开始接入google的应用内支付。
第一步:准备工作
首先想要使用google的支付,首先必须要有一部安装了google play服务的测试机,在这里提供了三个方法:
1)如果有小米的测试机最好因为小米的完整的保留了google play服务.
2)如果没有可以看下此处附上的连接: 安装Google play的服务.
3)如果以上两种方式你都失败了,不要沮丧下面这种方法可能会更好,点击链接: 下载海马玩模拟器,它可以一步解决问题。
Google play服务安装完成后如下图所示:
其次你还需要一个VPN账号(美国的最好),推荐一下我使用的VPN(如下图)可以随心所欲的选择地点。
最后需要下载开发包,打开 SDK Manager下载Android SDK的extras部分(如下图),其中有我们支付所用到的包,开发用到的说明文档,例子等等。
下载完成后在SDK目录下可以找到这个文件夹android-sdk-windows\extras\google\play_billing
其中samples是google支付接入的demo,可以根据例子进行google支付的接入。同时在SDK目录下可以找到这个文件夹android-sdk-windows\docs\google\play\billing这个是google支付的官方说明文档可以对支付工程及原理有一个了解。
说明文档里讲的很详细,建议把文档完整的看一遍,相信如果你看懂了这几个文档,google支付也就很容易搞定了
第二步:代码接入
准备工作做完了,接下来就是代码接入过程了,首先你需要将之前下载的IInAppBillingService.aidl文件添加到你的工程中,添加方法就是在你的工程里新建一个com.android.vending.billing文件夹,将IInAppBillingService.aidl这个 文件拷贝到其中刷新工程即可(具体的可以参考下载的demo)。
其次把之前下载的google支付库中的demo simple例子中的代码粘贴到你的工程文件中(如下图),可以新建一个包放到里面。
在这里说明一下,如果你是和我一样的初学者,可以打着拿来主义的旗号直接使用,但要注意修改一下类名和变量名,毕竟这个代码是公开的大家都可以看到;如果你是大神觉得这个代码写的太low了,也可以自己修改成你想要的那个范。
1.添加权限
接入之前需要在AndroidManifest.xml 文件中添加支付的权限:
2.初始化IabHelper:
// Create the helper, passing it our context and the public key to verify signatures with
Log.d(TAG, &Creating IAB helper.&);
mHelper = new IabHelper(this, base64EncodedPublicKey);
// enable debug logging (for a production application, you should set this to false).
mHelper.enableDebugLogging(true);
// Start setup. This is asynchronous and the specified listener
// will be called once setup completes.
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.
complain(&Problem setting up in-app billing: & + result);
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null)
// IAB is fully set up. Now, let's get an inventory of stuff we own.
Log.d(TAG, &Setup successful. Querying inventory.&);
mHelper.queryInventoryAsync(mGotInventoryListener);
3.调用支付接口:
是用来购买商品的方法:
mHelper.launchPurchaseFlow(this, SKU_GAS, RC_REQUEST,
mPurchaseFinishedListener, payload);
购买方法的回调:
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, &Purchase finished: & + result + &, purchase: & + purchase);
// if we were disposed of in the meantime, quit.
if (mHelper == null)
if (result.isFailure()) {
complain(&Error purchasing: & + result);
setWaitScreen(false);
if (!verifyDeveloperPayload(purchase)) {
complain(&Error purchasing. Authenticity verification failed.&);
setWaitScreen(false);
Log.d(TAG, &Purchase successful.&);
if (purchase.getSku().equals(SKU_GAS)) {
// bought 1/4 tank of gas. So consume it.
Log.d(TAG, &Purchase is gas. Starting gas consumption.&);
mHelper.consumeAsync(purchase, mConsumeFinishedListener);
else if (purchase.getSku().equals(SKU_PREMIUM)) {
// bought the premium upgrade!
Log.d(TAG, &Purchase is premium upgrade. Congratulating user.&);
alert(&Thank you for upgrading to premium!&);
mIsPremium =
updateUi();
setWaitScreen(false);
else if (purchase.getSku().equals(SKU_INFINITE_GAS)) {
// bought the infinite gas subscription
Log.d(TAG, &Infinite gas subscription purchased.&);
alert(&Thank you for subscribing to infinite gas!&);
mSubscribedToInfiniteGas =
mTank = TANK_MAX;
updateUi();
setWaitScreen(false);
// Called when consumption is complete
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
Log.d(TAG, &Consumption finished. Purchase: & + purchase + &, result: & + result);
// if we were disposed of in the meantime, quit.
if (mHelper == null)
// We know this is the &gas& sku because it's the only one we consume,
// so we don't check which sku was consumed. If you have more than one
// sku, you probably should check...
if (result.isSuccess()) {
// successfully consumed, so we apply the effects of the item in our
// game world's logic, which in our case means filling the gas tank a bit
Log.d(TAG, &Consumption successful. Provisioning.&);
mTank = mTank == TANK_MAX ? TANK_MAX : mTank + 1;
saveData();
alert(&You filled 1/4 tank. Your tank is now & + String.valueOf(mTank) + &/4 full!&);
complain(&Error while consuming: & + result);
updateUi();
setWaitScreen(false);
Log.d(TAG, &End consumption flow.&);
4.调用查询接口:
是用来查询你当前购买的的商品
mHelper.queryInventoryAsync(mGotInventoryListener);
查询方法的回调:
// Listener that's called when we finish querying the items and subscriptions we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, &Query inventory finished.&);
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null)
// Is it a failure?
if (result.isFailure()) {
complain(&Failed to query inventory: & + result);
Log.d(TAG, &Query inventory was successful.&);
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
// Do we have the premium upgrade?
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
Log.d(TAG, &User is & + (mIsPremium ? &PREMIUM& : &NOT PREMIUM&));
// Do we have the infinite gas plan?
Purchase infiniteGasPurchase = inventory.getPurchase(SKU_INFINITE_GAS);
mSubscribedToInfiniteGas = (infiniteGasPurchase != null &&
verifyDeveloperPayload(infiniteGasPurchase));
Log.d(TAG, &User & + (mSubscribedToInfiniteGas ? &HAS& : &DOES NOT HAVE&)
+ & infinite gas subscription.&);
if (mSubscribedToInfiniteGas) mTank = TANK_MAX;
// Check for gas delivery -- if we own gas, we should fill up the tank immediately
Purchase gasPurchase = inventory.getPurchase(SKU_GAS);
if (gasPurchase != null && verifyDeveloperPayload(gasPurchase)) {
Log.d(TAG, &We have gas. Consuming it.&);
mHelper.consumeAsync(inventory.getPurchase(SKU_GAS), mConsumeFinishedListener);
updateUi();
setWaitScreen(false);
Log.d(TAG, &Initial inve enabling main UI.&);
5.消耗商品
因为我们的内购商品是可以重复购买的,但是每次购买之后需要消耗商品,注意这个消耗的意思不是要使用已经购买的商品,而是消除google对改购买商品施加的一个标记,以表示本次购买已成功,之后才可以进行下一次的购买以避免发生重复购买而产生的多次扣款而商品数目不一致的问题。
mHelper.consumeAsync(purchase, mConsumeFinishedListener);
消耗商品的回调:
// Called when consumption is complete
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
Log.d(TAG, &Consumption finished. Purchase: & + purchase + &, result: & + result);
// if we were disposed of in the meantime, quit.
if (mHelper == null)
// We know this is the &gas& sku because it's the only one we consume,
// so we don't check which sku was consumed. If you have more than one
// sku, you probably should check...
if (result.isSuccess()) {
// successfully consumed, so we apply the effects of the item in our
// game world's logic, which in our case means filling the gas tank a bit
Log.d(TAG, &Consumption successful. Provisioning.&);
mTank = mTank == TANK_MAX ? TANK_MAX : mTank + 1;
saveData();
alert(&You filled 1/4 tank. Your tank is now & + String.valueOf(mTank) + &/4 full!&);
complain(&Error while consuming: & + result);
updateUi();
setWaitScreen(false);
Log.d(TAG, &End consumption flow.&);
6.返回数据方法:
在购买时不要忘记添加下面这个方法,它是用来出来返回的数据。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, &onActivityResult(& + requestCode + &,& + resultCode + &,& + data);
if (mHelper == null)
// Pass on the activity 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 activity results not related to in-app
// billing...
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, &onActivityResult handled by IABUtil.&);
7.退出后销毁IabHelper:
在退出时需要销毁IabHelper:
// We're being destroyed. It's important to dispose of the helper here!
public void onDestroy() {
super.onDestroy();
// very important:
Log.d(TAG, &Destroying helper.&);
if (mHelper != null) {
mHelper.dispose();
第三步:打包上传
首先你需要有一个google开发者账号,登录到google开发者后台添加一个应用,同时添加商品的相关部分。
其次google的支付可不是写完代码编译下就可以支付的,所以完成代码的部分后就需要将工程打包上传到google开发者后台,打包的过程相信不需要我多说什么了吧,不会的可以看下这个连接:,上传到Bate版或者ALPHA版,如果是公司开发那应该会有妹子或者汉子帮你完成这个步骤,如果是自己的话那就。。。呵呵。
google的审核过程还是很快的大约半个小时就出炉了,这个时候还需要添加测试账号在这个文档中详细介绍了如何添加测试账号,当然添加测试账号并不意味着你就可以测试了,在审核结束时在google开发者后台的apk界面有一个测试连接,打开后输入测试的账号成为测试人员,这个时候就可以进行google支付的测试了
第四步:测试中的问题
首先测试账号需要有一个绑定的信用卡而且是VISA信用卡账户,点击支付按钮,如果你已经成为测试人员,但是google提示&需要验证身份,需要登录Google账号&这个问题的话很可能是你的商品id有问题,你可以检查下商品id是否正确后重新测试。
关于如何添加商品id google支付的说明文档中会有详细的说明。
如果测试中遇到&无法购买你想要买的商品&这个提示,那可能是你还未成为测试人员或者你用开发者账号进行测试的原因。
1.当前应用程序不支持购买此商品:确定你手机上装的程序包名和签名和后台上传的一致。p.s.上传后台后APK需要等一段时间才能生效。
2.购买的商品不存在 :确保你代码里的商品名字和后台的一致,如果一致,则可能需要等一两个小时再测试,Google后台的问题。
3.loading了很长时间,最后给你提示未知错误:这个不管它,Google后台的问题,等会再测。
最后国内开发者确保是在vpn下进行测试,有什么疑惑的地方可以和我私聊!!!!
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'in app billing
应用程序内部付费机制
内部付费机制参考
测试应用程序付费服务
内部付费机制概述
不支持应用计费
不支持应用程序内计费
更多收起网络短语
Why should the industry be excited by your new global in-app billing options?
为什么说你们的全球应用内置计费系统会让手机游戏产业受益?
Learn how the service works and what a typical in-app billing implementation looks like.
了解应用内支付服务是如何工作的和站内支付的特点。
Tim emphasized that DCB (Direct Carrier Billing) was a major growth factor typically doubling app or in-app sales as soon as they are enabled.
Tim强调DCB(Direct Carrier Billing,运营商代收费)是一项重要的增长因素,经常一开通就能够让应用销售和应用内销售翻番。
More than 50 percent of the apps are using in app billing.
He zeros in on payment and in-app billing.
Google has opened the doors to In-app purchases, carrier billing and now, in-app subscriptions.
$firstVoiceSent
- 来自原声例句
请问您想要如何调整此模块?
感谢您的反馈,我们会尽快进行适当修改!
请问您想要如何调整此模块?
感谢您的反馈,我们会尽快进行适当修改!3057人阅读
&&&&&&& 上个月google play内支付这个功能,这功能我是花了很长时间才完成的。从官方下载回来Demo是一个充汽油的例子,,我自己整理下了,说说我的看法,可能不一定都对,但希望能给你们提供帮助。
&&&&&&& 开发前的准备,如果没,就向你们公司申请吧:
&&&&&&& 1、root过的手机一部
&&&&&& 2、翻墙工具()
&&&&&& 3、Google帐号一个&(需绑定等信用卡)&用做测试帐号
&&&&&& 4、开通一个平台帐号(能把发布上去)
&&&&& 开发中的问题:
&&& & 首先说下base64EncodedPublicKey的作用的吧,这个是每个app发布到google play后台时,google会生成的一个非常长key ,这个key是用在google交易中的安全验证,建议
把它放在服务端,通过请求服务端时获取;
&&&& 接下来是productid,它是你在后台设置的一个产品id,当你发布你的app上去并设置好产品id时,你就可以通过这个id来获取该商品的相关信息,如:价格、产品名、详细说明等,这个也是连接google play内支付的第一个步骤;
&&&&& 当你获取到以上信息时,就证明你的后台设置正确了,并且可以进入google的支付界面了,用户在上面的操作,会通过onActivityResult返回数据,你只需要判断requestCode 和resultCode 是否正常,(返回相关参数,请参看api吧,正常是requestCode&==&1001,resultCode&==&RESULT_OK)以上操作完成后,还需一个“消耗”(consumePurchase)的步骤,官网也提到过,因为这些交易不一定都是只交易一次而已,像游戏币这些的话,是一种虚拟的货币,是可多次购买的,所有消耗这一步其实就是为了告诉google,这件商品是可被买家多次购买的,“消耗”这一步骤可调用多次,Demo上在各个环节上也调用过的。
&&&&& 注意事项:
&&& 1、 在上传app时,为了前期开发方便 ,可随意上传,但必须要加上权限&uses-permission android:name=&com.android.vending.BILLING& /&
&&&& 2、如果app没正式发布,那么测试时,需要在后台添加测试人员,该测试人员就是以上讲的第三点,而且需要正式打包出来测试(keystore一定要保持好)
&&& 代码简单说明:
&&& mHelper :是一个帮助类,可在demo上查看
&&& SKU_GAS:商品的名字(后台定义的)
&&&& mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
&& &&& &&& &&& &public void onIabSetupFinished(IabResult result) {
&&&&&&&&&&&&&&&&&&&&&&&& //& 这是连接的第一步,通常是初始化和检查设备是否符合购买要求& TODO...
&&&&&&&&&&&&&&&&&&&&&&& mHelper.queryInventoryAsync(mGotInventoryListener, list);&
&&&&&&&&&&&&&&& }
&&& //查询商品
&&& IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
&& &&& & &&& public void onQueryInventoryFinished(final IabResult result,
&& &&& &&& && & & & & & final Inventory inventory) {
&&&&&&&&&&&&& & & & & & //& 这是查询其商品的相关信息,如价格,商品说明等。& TODO...
&&&&&&&&&&&&&&&&&&&&&&& mHelper.launchPurchaseFlow(activity, SKU_GAS, RC_REQUEST,
&& &&& &&& &&& &&& &&& &&& &mPurchaseFinishedListener, payload);&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&& //购买商品
&&& IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
&& && & & & & public void onIabPurchaseFinished(final IabResult result,
&& &&& &&& &&& & & & & & final Purchase purchase) {
& & & & & & & & & & & & //& 是否购买成功。& TODO...
&&&&&&&&&&&&&&&&&&&&&&& mHelper.consumeAsync(purchase, mConsumeFinishedListener);&&&&&&
&&&&&&&&&&&&&&& }
&&& //通知google消耗商品
&&& IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
&& &&& &public void onConsumeFinished(final Purchase purchase,
&& &&& &&& &&& &final IabResult result) {
& & & & & & & & & & & & //& 查询该商品是否以消耗成功,为下一次购买做准备。& TODO...
&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&& demo地址:& http://download.csdn.net/detail/a6369
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:28515次
排名:千里之外
原创:24篇
转载:15篇
评论:17条
(1)(1)(2)(1)(1)(2)(3)(1)(2)(7)(2)(3)(2)(2)(2)(4)(4)谷歌发布v3版Android In-App Billing结账接口
据外媒报道,谷歌于近日对Android版的In-App Billing(IAB)进行了升级工作,并于今日发布了v3版接口。据悉,软件中的IAB系统设计更加简单,这也就意味着开发人员可以用更少的代码对系统进行整合修改。谷歌还指出,v3版IAB的构架也得到了改善,交易过程中损失将变得更少,本地缓存的API调用速度将变得更快。
全新的本地缓存功能可以让开发人员在本地查看信息,从而可以加快软件的反应速度。另外,这个全新的框架还具备了同步以及即时报告购买结果的功能。
不过,目前,这个v3版Android IAB软件只允许以in-app形式进行购买。任何Android 2.2以及以上版本的Google Play都可以使用这个软件。[广告]活动入口:
[责任编辑:teikaei ]
-5-4-3-2-1012345
当前平均分: 打分后显示
-5-4-3-2-1012345
当前平均分: 打分后显示
Advertisment ad adsense googlesAndroid中文API
中文(中国)
Русский
In-app Billing
In-app Billing is a Google Play service that lets you sell digital content from inside
your applications. You can use the service to sell a wide range of content, including downloadable
content such as media files or photos, virtual content such as game levels or potions, premium services
and features, and more. You can use In-app Billing to sell products as
Standard in-app products (one-time billing), or
Subscriptions, (recurring, automated billing)
When you use the in-app billing service to sell an item,
whether it's an in-app product or a subscription, Google Play
handles all checkout details so your application never has to directly process
any financial transactions. Google Play uses the same checkout backend service as
is used for application purchases, so your users experience a consistent and
familiar purchase flow (see figure 1). Also, the transaction fee for in-app
purchases is the same as the transaction fee for application purchases
Any application that you publish through Google Play can implement In-app Billing. No special
account or registration is required other than an Android Market publisher account and a Google
Wallet Merchant account. Also, because the service uses no dedicated framework APIs, you can add
in-app billing to any application that uses a minimum API level of 4 or higher.
To help you integrate in-app billing into your application, the Android SDK
provides a sample application that demonstrates how to sell standard in-app
products and subscriptions from inside an app. The sample contains examples of
billing-related classes you can use to implement in-app billing in your
application. It also contains examples of the database, user interface, and
business logic you might use to implement in-app billing.
Important: Although the sample application is a working example
of how you can implement in-app billing, we strongly recommend that you modify and
obfuscate the sample code before you use it in a production application. For more information, see
Figure 1. Applications initiate in-app billing requests through their own UI
(first screen). Google Play responds to the request by providing the checkout user interface
(middle screen). When checkout is complete, the application resumes.
To learn more about Google Play's in-app billing service and start integrating it into your
applications, read the following documents:
Learn how the service works and what a typical in-app billing implementation looks
Use this step-by-step guide to start incorporating in-app billing into your
application. The instructions apply to both one-time and subscription purchases.
Learn how subscriptions work and how to implement support for them in your app.
Review these best practices to help ensure that your in-app billing implementation is
secure and well designed.
Understand how the in-app billing test tools work and learn how to test your in-app billing
implementation.
Learn how to set up your product list, register test accounts, and handle refunds.
Get detailed information about Google Play response codes and the in-app billing
interface.

我要回帖

更多关于 app支付宝 服务端开发 的文章

 

随机推荐