以下是 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