php代码
class Pay extends Web { /** * 最多以每秒999个的速度生成13位订单号 * * @return string */ function getOrderId() { //哪年,哪天,哪一秒 $base = date('y') . date('z') . str_pad((date('H') * 60 * 60 + date('i') * 60 + date('s')), 5, 0, STR_PAD_LEFT); $next_sec = time() + 1; $pre_max_id = 999; while(time() < $next_sec) { $order_id = mt_rand(1, $pre_max_id); $store_key = parent::getCacheKey('orderIdCache', $base, $order_id); $setRet = $this->store->setnx($store_key, 1); if ($setRet) { $this->store->expire($store_key, 5); return $base.str_pad($order_id, 3, 0, STR_PAD_LEFT); } else { continue; } } return $this->getOrderId(); } }