2

我正在我的网站上集成支付网关(CCavenue),并要求在每个请求中发送一个唯一的订单 ID。

这是示例代码

<form method="post" name="" action="">

<tr>

<td><input type="hidden" name="order_id" value=""/></td> //This must be a unique Id created on your website
</tr>

<tr>
<td><input type="hidden" name="amount" value=""/></td>
</tr>


<td><INPUT TYPE="submit" value="Paynow"></td>
</form>   

谁能让我知道如何使用数据库或任何其他方式来实现这一点。我的虚拟主机支持 php。

4

8 回答 8

2

您可以使用 jquery 创建自动代码

$(document).ready(function()
                    {
                        var code = "";
                        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

                        for( var i=0; i < 6; i++ )
                            code += possible.charAt(Math.floor(Math.random() * possible.length));
                       $("#order_id").val(code);
                    });

使用 PHP::

<input type="hidden" name="order_id" value="<?php echo md5(uniqid(rand()));?>"/>

上面的例子会给出一个长字符串

因此,如果您需要六位数字,您可以按照以下示例进行操作。您可以根据需要更改示例

$six_digit_random_number = mt_rand(100000, 999999);

既然都没有。100000 到 999999 之间是六位数。

也可以通过以下方式进行

string uniqid ([ string $prefix [, bool $more_entropy ]] )

根据当前时间(以微秒为单位)获取带前缀的唯一标识符。

USAGE: $id = uniqid(rand(), true);
于 2014-08-22T09:34:05.053 回答
1

对于唯一的 id,每次都放微时间是唯一的:

<form method="post" name="" action="">

  <tr>
    <td><input type="hidden" name="order_id" value="<?php echo microtime(true)*10000; ?>"/></td> //This must be a unique Id created on your website
  </tr>

  <tr>
    <td><input type="hidden" name="amount" value=""/></td>
  </tr>

  <td><INPUT TYPE="submit" value="Paynow"></td>
</form>   
于 2014-08-22T09:38:26.867 回答
0

You can create a table with an auto in crementing key and that Id you can pass to payment gateway.

or in other case you can generate a unique Id in PHP

check the below link for generating unique Id

Generating a unique ID in PHP

and this Id you can keep in session for handling the response from payment gateway incase you need that ID after payment.

于 2014-08-22T09:40:34.080 回答
0
  1. 将订单存入数据库(在数据库订单中必须有PK)
  2. 获取 PK(是否使用 AJAX)并将其插入选项值中

这是最佳实践

于 2014-08-22T09:37:20.383 回答
0
<?php
$order_id = "ID" . (string)rand(100000, 999999);  // you can change 'ID' to anything
?>

<form method="post" name="" action="">

<tr>

<td><input type="hidden" name="order_id" value=<?php echo $order_id; ?>/></td> 
</tr>

<tr>
<td><input type="hidden" name="amount" value=""/></td>
</tr>


<td><INPUT TYPE="submit" value="Paynow"></td>
</form>   
于 2014-08-22T09:44:47.363 回答
0

使用您的原始订单号(自动递增 id)和字段 order_id LIKE order_no 是 87644 采取 ​​id CCA87644 [此指示是订单号 87644 由 CCavenue 付款]

<input type="hidden" name="order_id" value=""/>

此 ID 将是唯一的,这将有助于您将来进行订单跟踪。其他一些其他的帖子有如何创建一个唯一的ID。

唯一 ID 应按从低到高的顺序排列。这将有助于支付管理和支付管理

于 2014-08-22T11:00:03.057 回答
0

PHP 具有uniquid函数,它可以完全满足您的需求。

于 2014-08-22T10:16:55.997 回答
0

我总是使用下订单的日期和ORDER_ID的组合,这是ORDER表的primary_key字段。

因此,如果有人在2014 年 7 月 10日下订单,并且该特定订单的 ORDER_ID 是“ 20 ”,那么唯一的 order_id 将是“ 2014071020 ”。无论情况如何,它总是独一无二的。

Incase,如果您的表中没有任何primary_key字段,那么您可以使用PHP 的time()函数生成一个唯一的 id。

如果您需要任何与此相关的编程帮助,请告诉我。

问候。

于 2014-09-08T08:54:27.173 回答