生成订阅报价的签名-Xcode-Swift

mfi*_*ore 3 xcode in-app-purchase ios swift in-app-subscription

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

enc*_*ife 5

这是RevenueCat的演练:iOS订阅优惠

该帖子包含更多细节,但签名生成为:

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)
Run Code Online (Sandbox Code Playgroud)

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

生成签名后,随机数和时间戳将它们与key_id背面一起发送到您的应用中,您可以在其中创建SKPaymentDiscount

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