请教一个IAP问题:如何同步服务器和客户端的购买信息 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
doubleone
V2EX    iDev

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

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

    @shellcodecow 等服务器接口好了,试试这个方法。但有个疑问,在finishTransaction之前通知服务器向Apple验证,此时Apple给服务器的结果应该是已购买成功了吧?难道如果不调用finishTransaction,Apple还会重置为未购买?Transaction使用了长连接?
    satgi
        5
    satgi  
       2013-03-11 22:57:40 +08:00
    不会重置为未购买,SKPaymentTransactionStatePurchased就说明购买成功了,但是这时候购买成功只有你知道啊,你还需要完成验证交易,提供下载,解锁啊啥的,调用finishTransaction之后相应的那个payment才会从payment queue当中移除。
    ewangke
        6
    ewangke  
       2013-03-12 00:42:07 +08:00
    跑个题,为什么是consumable而不是subscription?
    doubleone
        7
    doubleone  
    OP
       2013-03-12 10:21:24 +08:00
    @ewangke 比如某个用户已买了一个月会员,在一个月结束前,就可以续费
    ewangke
        8
    ewangke  
       2013-03-12 12:46:34 +08:00
    @doubleone subscription不行么?这不是典型的场景
    doubleone
        9
    doubleone  
    OP
       2013-03-12 14:49:20 +08:00
    @ewangke 我的理解是 这就像游戏中买积分一样 所以选择了consumable
    ewangke
        10
    ewangke  
       2013-03-12 14:50:44 +08:00
    @doubleone 你理解得也有道理,但我担心被苹果拒。上线了么
    doubleone
        11
    doubleone  
    OP
       2013-03-12 15:15:45 +08:00
    @ewangke 之前的版本没有iap 已上线 新版还在开发中
    doubleone
        12
    doubleone  
    OP
       2013-03-12 15:20:47 +08:00
    @ewangke 你做过类似的 用的是subscription?
    ewangke
        13
    ewangke  
       2013-03-12 16:19:25 +08:00
    @doubleone 没做过
    不过App Store上这类的都是subscription
    doubleone
        14
    doubleone  
    OP
       2013-03-12 16:45:50 +08:00
    ewangke
        15
    ewangke  
       2013-03-12 20:25:14 +08:00
    @doubleone 好吧,既然你以国内发行商的标准
    doubleone
        16
    doubleone  
    OP
       2013-03-12 22:01:57 +08:00
    @ewangke 话说这和是不是国内发行商没什么关系吧?如果有更好的方式,应当学习。我想知道的是你是如何看出是consumable还是subscription?麻烦举个国外的例子
    ewangke
        18
    ewangke  
       2013-03-12 23:55:21 +08:00
    @doubleone
    这个SO的link能说明什么,跟你的情况完全没有关系
    NYTimes这类订阅用户,本质就是会员,通过订阅的方式获得每月的付费内容
    续费不是可以auto renewable么?
    只有开发者才完全清楚后面是什么模型,PPTV未必像你说的那样;非要跟苹果反着来,只有自己吃亏
    ewangke
        19
    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
        20
    doubleone  
    OP
       2013-03-29 21:28:48 +08:00
    @ewangke it should be non-renewing subscriptions.
    ewangke
        21
    ewangke  
       2013-03-30 00:02:59 +08:00
    @doubleone 请教一下,non-renewing和auto-renewing一般如何按场景区分使用
    doubleone
        22
    doubleone  
    OP
       2013-04-01 21:12:59 +08:00   1
    @ewangke 我的理解是non-renewing需要由自己去管理订阅 比如会员 其中会有苹果无法控制的东西 像是特权之类的
    而auto-renewing苹果已经提供了管理方案 适合杂志之类的传统订阅服务
    chisj
        23
    chisj  
       2013-04-02 16:25:59 +08:00
    我的做法:purchasedReceipt每次发送前,都做本地保存。
    发送成功后,移除purchasedReceipt。
    发送失败,提示用户网络异常或者服务器异常,并提供联系方式。

    在每次becameActive时候,判断是否有purchasedReceipt,有的话,发送到后台,成功才移除,出错就在每次Active都继续发送。

    不知道这样是否会有什么问题?
    doubleone
        24
    doubleone  
    OP
       2013-04-02 21:59:05 +08:00 via iPad
    @chisj 基本一样 保存在keychain里 不成功时告知用户会之后自动验证
    chisj
        25
    chisj  
       2013-04-03 09:31:55 +08:00
    @doubleone 多谢,我的版本还没发出去呢。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1567 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 38ms UTC 16:30 PVG 00:30 LAX 09:30 JFK 12:30
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86