Browse Source

获取随机数

shish 2 năm trước cách đây
mục cha
commit
72fbf38f72
1 tập tin đã thay đổi với 12 bổ sung12 xóa
  1. 12 12
      common/components/lakala/Lakala.php

+ 12 - 12
common/components/lakala/Lakala.php

@@ -103,21 +103,10 @@ class Lakala
         return false;
     }
 
-    public function randString()
-    {
-        $length = "12";
-        $characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
-        $randomString = "";
-        for ($i = 0; $i < $length; $i++) {
-            $randomString .= $characters[rand(0, strlen($characters) - 1)];
-        }
-        return $randomString;
-    }
-
     //签名
     public function getAuthorization($body)
     {
-        $nonceStr = $this->randString();
+        $nonceStr = $this->randString(12);
         $timestamp = time();
 
         $message = $this->appid . "\n" . $this->serial_no . "\n" . $timestamp . "\n" . $nonceStr . "\n" . $body . "\n";
@@ -130,6 +119,17 @@ class Lakala
         return $this->schema . " appid=\"" . $this->appid . "\"," . "serial_no=\"" . $this->serial_no . "\"," . "timestamp=\"" . $timestamp . "\"," . "nonce_str=\"" . $nonceStr . "\"," . "signature=\"" . base64_encode($signature) . "\"";
     }
 
+    //获取随机数
+    public function randString($length)
+    {
+        $characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+        $randomString = "";
+        for ($i = 0; $i < $length; $i++) {
+            $randomString .= $characters[rand(0, strlen($characters) - 1)];
+        }
+        return $randomString;
+    }
+
     //请求
     public function post($url, $data, $authorization)
     {