如何使用 PHP 检测是否从 Google Checkout 购买了商品?

发布于 2024-11-14 21:37:28 字数 707 浏览 3 评论 0原文

我正在制作一个网络应用程序,该应用程序将以免费和付费形式提供。我想让它检测用户是否已使用 Google Checkout 支付付费版本的费用,并启用付费功能(如果有)。

我将如何在 PHP 中执行此操作?

更新 我的数据库中已经有一个用户表,并且用户需要登录才能使用该应用程序。我还将创建一个名为 purchases 的表,其中包含以下内容:

  • userid 内部使用的帐户 ID
  • chitchat (应用程序的名称) NULL或 Google 订单 id

然后,当我需要检测用户是否购买了它时,我会使用

$userid=esc($_SESSION["id"]); // esc is a function that returns the SQL escaped string
if($query=mysqli_query($link,"SELECT * FROM purchases WHERE userid='$userid'")&&mysqli_num_rows($query)>0){
    // The user has bought the paid version
}

但是,如果我的服务器被黑客攻击,我将如何向 Google 确认订单 id?

I am making a Web app that will be available in free and paid forms. I want to make it detect whether the user has paid for paid version using Google Checkout, and enable paid features if they have.

How would I do this in PHP?

Update I already have a user table in my database, and the user is required to log in to use the app. I will also create a table called purchases which will have the following:

  • userid An internally used account id
  • chitchat (the name of the app) NULL or a Google order id

Then when I need to detect if the user has bought it I would use

$userid=esc($_SESSION["id"]); // esc is a function that returns the SQL escaped string
if($query=mysqli_query($link,"SELECT * FROM purchases WHERE userid='$userid'")&&mysqli_num_rows($query)>0){
    // The user has bought the paid version
}

But then, in case my server is hacked, how would I confirm the order id with Google?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-11-21 21:37:28

鉴于您分享的有关网络应用程序的信息非常少,因此很难给出准确的答案,但这里有一些提示:

  1. 创建用户数据库并要求人们注册。
  2. 当有人购买时,请在数据库中记下该信息。在 Google 结帐过程中,Google 会通知您交易已成功。
  3. 当用户登录时,检查他们是否进行了购买并授予他们访问“仅限付费”区域的权限。

Given the fact that you've shared very little information about your web app, it's difficult to answer with a precise answer but here are some pointers:

  1. Create a database of users and require that people sign up.
  2. When someone makes a purchase, note that in the database. During the Google checkout process, Google will let you know that a transaction was successful.
  3. When a user signs in, check whether or not they've made a purchase and grant them permission to "paid-only" areas.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文