请教一个IAP问题:如何同步服务器和客户端的购买信息

2013-03-11 17:57:01 +08:00
 doubleone
手机上有购买会员功能:(1个月、3个月……),属于Consumable。如果一切正常,App store返回成功,再向自己的服务器发送purchasedReceipt,服务器然后向Apple验证purchasedReceipt,得知用户是否合法购买成功。
但假设,客户端在向服务器发送purchasedReceipt时,出现了网络异常,这时比较好的解决方案有哪些?
本地存储信息,待网络正常后再次验证?
5564 次点击
所在节点    iDev
25 条回复
satgi
2013-03-11 18:01:41 +08:00
应该是吧,服务器向Apple验证receipt的时候不也有可能发生异常吗。。。
总得验证了购买结果才算完成嘛
之前也遇到过这问题,不过那个项目没进行下去。。。
shellcodecow
2013-03-11 18:26:48 +08:00
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
只要不finish 下次点击应该还是会走一遍流程,这时候你加判断。如果post receipt to sever失败重试3次,如果3次还是失败,弹出feedback 发送email给客服。
tangqiaoboy
2013-03-11 21:28:57 +08:00
我就是这么搞的。
另外,还需要考虑服务器和苹果验证时超时的情况,有些时候苹果的服务器会超时。另外,攻击者会拿另外的支付成功的凭证来欺骗,记得验证凭证的bundle id
doubleone
2013-03-11 21:46:50 +08:00
@satgi
@shellcodecow
@tangqiaoboy
谢谢

@shellcodecow 等服务器接口好了,试试这个方法。但有个疑问,在finishTransaction之前通知服务器向Apple验证,此时Apple给服务器的结果应该是已购买成功了吧?难道如果不调用finishTransaction,Apple还会重置为未购买?Transaction使用了长连接?
satgi
2013-03-11 22:57:40 +08:00
不会重置为未购买,SKPaymentTransactionStatePurchased就说明购买成功了,但是这时候购买成功只有你知道啊,你还需要完成验证交易,提供下载,解锁啊啥的,调用finishTransaction之后相应的那个payment才会从payment queue当中移除。
ewangke
2013-03-12 00:42:07 +08:00
跑个题,为什么是consumable而不是subscription?
doubleone
2013-03-12 10:21:24 +08:00
@ewangke 比如某个用户已买了一个月会员,在一个月结束前,就可以续费
ewangke
2013-03-12 12:46:34 +08:00
@doubleone subscription不行么?这不是典型的场景
doubleone
2013-03-12 14:49:20 +08:00
@ewangke 我的理解是 这就像游戏中买积分一样 所以选择了consumable
ewangke
2013-03-12 14:50:44 +08:00
@doubleone 你理解得也有道理,但我担心被苹果拒。上线了么
doubleone
2013-03-12 15:15:45 +08:00
@ewangke 之前的版本没有iap 已上线 新版还在开发中
doubleone
2013-03-12 15:20:47 +08:00
@ewangke 你做过类似的 用的是subscription?
ewangke
2013-03-12 16:19:25 +08:00
@doubleone 没做过
不过App Store上这类的都是subscription
doubleone
2013-03-12 16:45:50 +08:00
ewangke
2013-03-12 20:25:14 +08:00
@doubleone 好吧,既然你以国内发行商的标准
doubleone
2013-03-12 22:01:57 +08:00
@ewangke 话说这和是不是国内发行商没什么关系吧?如果有更好的方式,应当学习。我想知道的是你是如何看出是consumable还是subscription?麻烦举个国外的例子
doubleone
2013-03-12 22:04:51 +08:00
ewangke
2013-03-12 23:55:21 +08:00
@doubleone
这个SO的link能说明什么,跟你的情况完全没有关系
NYTimes这类订阅用户,本质就是会员,通过订阅的方式获得每月的付费内容
续费不是可以auto renewable么?
只有开发者才完全清楚后面是什么模型,PPTV未必像你说的那样;非要跟苹果反着来,只有自己吃亏
ewangke
2013-03-13 00:07:13 +08:00
@doubleone

你说的也不是完全不行,但总觉得很别扭。希望你们产品上线后,可以回来回这个贴,跟大家说说结果。
如果使用Consumable, 比如我买了两个1个月的迅雷会员,放在那里不用,又可以随时用掉。
Skype的点数/VPN流量/游戏金币,适合用consumable类型。

附:
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/APIOverview/OverviewoftheStoreKitAPI.html

Consumable products must be purchased each time the user needs that item. For example, one-time services are commonly implemented as consumable products.

分割线

Auto-renewable subscriptions are delivered to all of a user’s devices in the same way as non-consumable products. However, auto-renewable subscriptions differ in other ways. When you create an auto-renewable subscription in iTunes Connect, you choose the duration of the subscription. The App Store automatically renews the subscription each time its term expires. If the user chooses to not allow the subscription to be renewed, the user’s access to the subscription is revoked after the subscription expires. Your application is responsible for validating whether a subscription is currently active and can also receive an updated receipt for the most recent transaction.

Non-renewing subscriptions are a mechanism for creating products with a limited duration. Non-renewing subscriptions differ from auto-renewable subscriptions in a few key ways:

The term of the subscription is not declared when you create the product in iTunes Connect; your application is responsible for providing this information to the user. In most cases, you would include the term of the subscription in the description of your product.

Non-renewing subscriptions may be purchased multiple times (like a consumable product) and are not automatically renewed by the App Store. You are responsible for implementing the renewal process inside your application. Specifically, your application must recognize when the subscription has expired and prompt the user to purchase the product again.

You are required to deliver non-renewing subscriptions to all devices owned by the user. Non-renewing subscriptions are not automatically synchronized to all devices by Store Kit; you must implement this infrastructure yourself. For example, most subscriptions are provided by an external server; your server would need to implement a mechanism to identify users and associate subscription purchases with the user who purchased them.
doubleone
2013-03-29 21:28:48 +08:00
@ewangke it should be non-renewing subscriptions.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/62604

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX