gpt4 book ai didi

ios - 无法使用订阅优惠购买

转载 作者:IT老高 更新时间:2023-10-28 23:21:52 28 4
gpt4 key购买 nike

我正在尝试使 In-App Purchase 订阅优惠起作用。所以我从我们的服务器获得了编码的签名、随机数、时间戳和 key 标识符。我创建了一个 SKPaymentDiscount 对象并将其设置为 SKMutablePayment 对象的 paymentDiscount

在第一次弹出时,它按预期显示修改后的价格 -> 输入密码并继续 -> 第二次弹出:确认订阅:好的 -> 第三次弹出:显示以下错误 无法购买 联系开发者获取更多信息。

我尝试为产品传递不适用的报价标识符。然后它抛出正确的错误说:这不能应用于这个。

PromoOfferAPI.prepareOffer(usernameHash: "name", productIdentifier: "bundleid.product", offerIdentifier: "TEST10") { (result) in
switch result {

case let .success(discount):
// The original product being purchased.
let payment = SKMutablePayment(product: option.product)
// You must set applicationUsername to be the same as the one used to generate the signature.
payment.applicationUsername = "name"
// Add the offer to the payment.
payment.paymentDiscount = discount
// Add the payment to the queue for purchase.
SKPaymentQueue.default().add(payment)
break
case let .customFail(message):
print(message)
break
case let .failure(error):
print(error.localizedDescription)
break
}
}

无论我尝试多少次,它总是给我同样的错误。 无法购买 联系开发者获取更多信息。可以采取什么措施来解决这个问题。任何帮助深表感谢。

提前致谢!

编辑 1:它永远不会进入 updatedTransactions 函数。它只记录 Finishing transaction for payment "bundleid.product"状态:失败。

编辑 2:得到错误: code - 12 (invalidSignature)。无法连接到 iTunes Store

生成编码签名的 Node.JS 代码。

const UUID = require("uuid-v4");
const microtime = require('microtime');
const express = require('express');
const router = express.Router();
const EC = require("elliptic").ec;
const ec = new EC("secp256k1");
const crypto = require('crypto');

const privateKey = `-----BEGIN PRIVATE KEY-----
key goes here
-----END PRIVATE KEY-----`;
//const key = ec.keyFromPrivate(privateKey,'hex');


router.post('/',(req, res)=>{
const bundle_id = "bundle.id";
const key_id = "keyed";
const nonce = String(UUID()).toLowerCase();// Should be lower case
const timestamp = microtime.now();

const product = req.body.product;
const offer = req.body.offer;
const application_username = req.body.application_username;

const payload = bundle_id + '\u2063' + key_id + '\u2063' + product + '\u2063' + offer + '\u2063' + application_username + '\u2063' + String(nonce) + '\u2063' + String(timestamp)
let shaMsg = crypto.createHash("sha256").update(payload).digest();
let signature = ec.sign(shaMsg, privateKey, {canonical: true});
let derSign = signature.toDER();
let buff = new Buffer(derSign);
let base64EncodedSignature = buff.toString('base64');
let response = {
"signeture": base64EncodedSignature,
"nonce": nonce,
"timestamp": timestamp,
"keyIdentifier": key_id
}
res.type('json').send(response);
});

module.exports = router;

最佳答案

我在测试他们提供的新 WWDC2019 示例 Node.js 服务器文件时遇到了同样的问题。按照自述文件后,我能够成功生成签名。

然而,令我惊讶的是,一个无效的签名看起来就像一个有效的,我花了一段时间才意识到我的签名是无效的。

我的错误如下:我使用 Alamofire 向我的服务器发出 GET 请求,如下所示:

AF.request("myserver:3000/offer", parameters: parameters).responseJSON { response in

var signature: String?
var keyID: String?
var timestamp: NSNumber?
var nonce: UUID?

switch response.result {
case let .success(value):
let json = JSON(value)

// Get required parameters for creating offer
signature = json["signature"].stringValue
keyID = json["keyID"].stringValue
timestamp = json["timestamp"].numberValue
nonce = UUID(uuidString: json["nonce"].stringValue)

case let .failure(error):
print(error)
return
}

// Create offer
let discountOffer = SKPaymentDiscount(identifier: offerIdentifier, keyIdentifier: keyID!, nonce: nonce!, signature: signature!, timestamp: timestamp!)

// Pass offer in completion block
completion(discountOffer) // this completion is a part of the method where this snippet is running
}
}

关于 WWDC2019 Video on Subscription Offers 中提供的文件,在 index.js 文件中,他们正在加载我在请求中传递的参数,如下所示:

const appBundleID = req.body.appBundleID;
const productIdentifier = req.body.productIdentifier;
const subscriptionOfferID = req.body.offerID;
const applicationUsername = req.body.applicationUsername;

但是,我的 alamofire 请求并没有传递正文中的参数,而是作为查询参数传递。因此,服务器正在生成一个带有 null appBundleID 以及其他 null 字段的签名!所以我把上面提到的 index.js 部分改成如下:

const appBundleID = req.query.appBundleID;
const productIdentifier = req.query.productIdentifier;
const subscriptionOfferID = req.query.offerID;
const applicationUsername = req.query.applicationUsername;

我希望这对忽略这一点的人有所帮助。请原谅我不安全的 swift,但我希望你明白这一点!

关于ios - 无法使用订阅优惠购买,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56148983/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com