需要为每个请求创建和发送唯一ID

时间:2014-08-22 09:30:18

标签: php sql ccavenue

我正在我的网站上集成支付网关(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。

8 个答案:

答案 0 :(得分: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);

答案 1 :(得分:1)

每次使用唯一身份证时,微缩时间都是唯一的:

<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>   

答案 2 :(得分:0)

  1. 将订单保存到DB(DB顺序必须有PK)
  2. 获取PK(使用或不使用AJAX)并将其插入选项值
  3. 这是最好的做法

答案 3 :(得分:0)

您可以使用自动创建密钥创建一个表,并将该ID传递给支付网关。

或者在其他情况下,您可以在PHP中生成唯一ID

检查以下链接以生成唯一ID

Generating a unique ID in PHP

和此ID您可以保持会话以处理来自支付网关的响应,如果您在付款后需要该ID。

答案 4 :(得分: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>   

答案 5 :(得分:0)

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

答案 6 :(得分:0)

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

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

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

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

答案 7 :(得分:0)

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

因此,如果有人在 2014年7月10日下订单,则该特定订单的ORDER_ID为&#34; 20 &#34;那么唯一的order_id将是&#34; 2014071020 &#34;。无论情况如何,它都将是独一无二的。

如果您的表格中没有任何 primary_key 字段,那么您可以使用PHP的 time() 功能生成一个独特的身份。

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

问候。

相关问题