Browse Source

积分兑换

541469799@qq.com 1 year ago
parent
commit
775f0f9b8b
3 changed files with 49 additions and 3 deletions
  1. 22 1
      app/index/common.php
  2. 0 1
      app/index/controller/Checkout.php
  3. 27 1
      app/index/controller/User.php

+ 22 - 1
app/index/common.php

@@ -8,7 +8,7 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 // 应用公共函数库文件
 
@@ -27,3 +27,24 @@ function getPlatform()
     }
     return $value;
 }
+
+// 加密函数
+function encrypt($data, $key = 'vp-256-bit-secret-key')
+{
+    $method = 'AES-256-CBC';
+    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
+    $encrypted = openssl_encrypt($data, $method, $key, 0, $iv);
+    // 将iv和加密数据拼接在一起,然后进行base64编码
+    return base64_encode($iv . $encrypted);
+}
+
+// 解密函数
+function decrypt($data, $key = 'vp-256-bit-secret-key')
+{
+    $method = 'AES-256-CBC';
+    // 解码加密字符串,并分离iv
+    $decoded = base64_decode($data);
+    $iv = substr($decoded, 0, openssl_cipher_iv_length($method));
+    $decrypted = openssl_decrypt(substr($decoded, openssl_cipher_iv_length($method)), $method, $key, 0, $iv);
+    return $decrypted;
+}

+ 0 - 1
app/index/controller/Checkout.php

@@ -67,7 +67,6 @@ class Checkout extends Controller
     public function submit(string $mode = 'buyNow'): Json
     {
         $userId = Session::get('user_id');
-        \think\facade\Log::info('submit:'.$userId);
         if (empty($userId)) {
             return $this->renderJson(config('status.not_logged'), 'Log in please!');
         }

+ 27 - 1
app/index/controller/User.php

@@ -15,7 +15,10 @@ use think\response\Redirect;
  */
 class User extends Controller
 {
-
+    /**
+     * 个人中心
+     * @return \think\response\View
+     */
     public function personal()
     {
         $userId = Session::get('user_id');
@@ -27,4 +30,27 @@ class User extends Controller
         return view('personal', ['goods' => []]);
     }
 
+    /**
+     * 分享商品
+     * @return \think\response\Json
+     */
+    public function shareUser()
+    {
+        $userId = Session::get('user_id');
+        if (empty($userId)) {
+            return $this->renderJson(config('status.not_logged'), 'Log in please!');
+        }
+
+        $goodsId = $this->request->param('goodsId');
+        if (empty($goodsId)){
+            return $this->renderError('Invalid goods');
+        }
+        $encryptUserId = encrypt($userId);
+
+        $url = url('/index/index/productDetail?goodsId=' . $goodsId . '&key=' . $encryptUserId);
+        //todo 发邮件
+
+        return $this->renderSuccess([]);
+    }
+
 }