为订阅优惠生成签名 - Xcode - Swift

2024-02-11

我想问是否有人已经实现了 inapp 订阅(自动续订)的新优惠,如果可能的话,在服务器端创建系统以使用 p8 密钥和 php 创建此签名的难度。我在苹果文档中找到了这个,我不确定是否理解它:https://developer.apple.com/documentation/storekit/in-app_purchase/generating_a_signature_for_subscription_offers https://developer.apple.com/documentation/storekit/in-app_purchase/generating_a_signature_for_subscription_offers


以下是 RevenueCat 的演练:iOS 订阅优惠 https://www.revenuecat.com/2019/03/12/subscription-offers

该帖子包含更多详细信息,但签名生成是:

import json
import uuid
import time
import hashlib
import base64

from ecdsa import SigningKey
from ecdsa.util import sigencode_der

bundle_id = 'com.myapp'
key_id = 'XWSXTGQVX2'
product = 'com.myapp.product.a'
offer = 'REFERENCE_CODE' # This is the code set in ASC
application_username = 'user_name' # Should be the same you use when
                                   # making purchases
nonce = uuid.uuid4()
timestamp = int(round(time.time() * 1000))

payload = '\u2063'.join([bundle_id, 
                         key_id, 
                         product, 
                         offer, 
                         application_username, 
                         str(nonce), # Should be lower case
                         str(timestamp)])

# Read the key file
with open('cert.der', 'rb') as myfile:
  der = myfile.read()

signing_key = SigningKey.from_der(der)

signature = signing_key.sign(payload.encode('utf-8'), 
                             hashfunc=hashlib.sha256, 
                             sigencode=sigencode_der)
encoded_signature = base64.b64encode(signature)

print(str(encoded_signature, 'utf-8'), str(nonce), str(timestamp), key_id)

这只是一个概念证明。您将希望它出现在您的服务器上,并且可能有一些逻辑来确定对于给定用户,所请求的报价是否合适。

生成签名、随机数和时间戳后,将它们与key_id返回到您的应用程序,您可以在其中创建SKPaymentDiscount.

免责声明:我在 RevenueCat 工作。我们通过 SDK 支持开箱即用的订阅优惠,无需代码签名:https://www.revenuecat.com/2019/04/25/signing-ios-subscription-offers https://www.revenuecat.com/2019/04/25/signing-ios-subscription-offers

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为订阅优惠生成签名 - Xcode - Swift 的相关文章

随机推荐