从 swift 调用时如何将参数传递给 https 函数?

How to pass a parameter into an https function when it's called from swift?

我一直在使用 typescript 在我的应用程序中实现 stripe,并且我有以下功能:

exports.deleteStripeCustomer = functions.https.onCall((data, context) => { 
  const deleted = await stripe.customers.del(
    "I need to add the customers ID here"
  );
});

在我需要添加 customerID 的字符串中,我想从我的 swift 代码中添加客户 ID,我已经在侦听该 ID 并在函数被调用时将其添加到函数中.

在 swift 中,这将是这样完成的:

func sayHello(name: string) {
    print("hello \(name)")
}

然后当调用该函数时,id 从其他地方传入,如下所示:

sayHello(name: usersName)

知道这是如何用打字稿完成的吗?

在此先致谢,如有任何帮助,我们将不胜感激!

在 TypeScript 函数中,您只需从 data 参数中获取即可。

exports.deleteStripeCustomer = functions.https.onCall((data, context) => {
    const userId = data.userId
});

并且在 Swift 调用中,您将像这样传递它:

let payload = [
    "userId": "u456"
]

SomeAPI.httpsCallable("deleteStripeCustomer").call(payload) { (_, error) in
    if let error = error {
        print(error)
    }
}

我从未使用过 Stripe,我不知道他们的客户端 API 是如何配置的(或服务器端),但我认为它就像其他 TypeScript-Swift 我过去曾使用过的交互操作,这就是它在那里完成的方式。如果你 link 我查看他们关于这个 API 的文档,我可以提供进一步的帮助,但一般来说,既然你问的一般,这就是它的完成方式。