生成订阅报价的签名-Xcode-Swift [英] Generating a Signature for Subscription Offers - Xcode - Swift
问题描述
我想问问是否有人已经为inapp-subscription(自动续订)实施了新的报价,如果可能的话,创建服务器端系统以使用php的p8密钥创建此签名的难度.我在Apple文档中找到了这个,我不确定是否理解: https://developer.apple.com/documentation/storekit/in-app_purchase/generation_a_signature_for_subscription_offers
I wanted to ask if someone has already implemented the new Offers for the inapp-subscription (auto renewal), the difficulty in creating server-side the system to create this signature using the p8 key with php if possible. I found this on the Apple documentation, I'm not sure understanding it: https://developer.apple.com/documentation/storekit/in-app_purchase/generating_a_signature_for_subscription_offers
推荐答案
Here's a walkthrough from RevenueCat: iOS Subscription Offers
帖子包含更多细节,但签名生成为:
The post contains much more detail, but the signature generation is:
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)
这仅仅是概念的证明.您可能希望在服务器上使用它,并且可能具有一些逻辑,对于给定的用户,确定所请求的报价是否合适.
This is just a proof of concept. You will want this on your server and perhaps have some logic to determine, for a given user, if the requested offer is appropriate.
生成签名后,随机数和时间戳将它们连同key_id
一起发送回您的应用中,您可以在其中创建SKPaymentDiscount
.
Once you’ve generated the signature, nonce and timestamp send these along with the key_id
back to your app where you can create an SKPaymentDiscount
.
免责声明:我在RevenueCat工作.我们使用我们的SDK开箱即用地支持订阅优惠,无需代码签名: 查看全文