15954078560 3 年之前
父節點
當前提交
68472a1912
共有 3 個文件被更改,包括 81 次插入22 次删除
  1. 19 2
      application/api/controller/User.php
  2. 17 9
      application/common/controller/Api.php
  3. 45 11
      application/common/model/UserLike.php

+ 19 - 2
application/api/controller/User.php

@@ -909,8 +909,25 @@ class User extends Api
             ->order("a.createtime",'desc')
             ->limit($pageStart,$pageNum)
             ->select();
-        if($res) foreach($res as $k => $v) {
-            $res[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
+        if($res) {
+            $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL.
+                wordwrap(config('public_key'), 64, PHP_EOL, true) .
+                PHP_EOL."-----END PUBLIC KEY-----";
+            foreach($res as $k => &$v) {
+                if ($v['wechat']) {
+                    $wechat = "";
+                    openssl_public_encrypt($v['wechat'], $wechat, $public_key);
+                    $v['wechat'] = base64_encode($wechat);
+                } else {
+                    $v['wechat'] = '';
+                }
+                $mobile = "";
+//                openssl_private_encrypt($data['mobile'], $mobile, $private_key); // 使用私钥加密数据
+                openssl_public_encrypt($v['mobile'], $mobile, $public_key);
+                $v['mobile'] = base64_encode($mobile);
+
+                $res[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
+            }
         }
         $this->success("获取成功!",$res);
     }

+ 17 - 9
application/common/controller/Api.php

@@ -166,7 +166,7 @@ class Api
      */
     protected function success($msg = '', $data = null, $code = 1, $type = null, array $header = [])
     {
-        if ($data && in_array(request()->action(), ['getLikeList', 'getFansList', 'getFate', 'getUserInfo'])) {
+        if ($data && in_array(request()->action(), ['getUserInfo'])) {
             //手机号/微信号  私钥加密
 //            $private_key = "-----BEGIN RSA PRIVATE KEY-----" .PHP_EOL.
 //                wordwrap(config('private_key'), 64, PHP_EOL, true) .
@@ -180,17 +180,25 @@ class Api
                 openssl_public_encrypt($data['mobile'], $mobile, $public_key);
                 $data['mobile'] = base64_encode($mobile);
             }
-            if (isset($data['wechat']) && $data['wechat']) {
-                $wechat = "";
+            if (isset($data['wechat'])) {
+                if ($data['wechat']) {
+                    $wechat = "";
 //                openssl_private_encrypt($data['wechat'], $wechat, $private_key); // 使用私钥加密数据
-                openssl_public_encrypt($data['wechat'], $wechat, $public_key);
-                $data['wechat'] = base64_encode($wechat);
+                    openssl_public_encrypt($data['wechat'], $wechat, $public_key);
+                    $data['wechat'] = base64_encode($wechat);
+                } else {
+                    $data['wechat'] = '';
+                }
             }
-            if (isset($data['wechat_auth']) && $data['wechat_auth']) {
-                $wechat_auth = "";
+            if (isset($data['wechat_auth'])) {
+                if ($data['wechat_auth']) {
+                    $wechat_auth = "";
 //                openssl_private_encrypt($data['wechat_auth'], $wechat_auth, $private_key); // 使用私钥加密数据
-                openssl_public_encrypt($data['wechat_auth'], $wechat_auth, $public_key);
-                $data['wechat_auth'] = base64_encode($wechat_auth);
+                    openssl_public_encrypt($data['wechat_auth'], $wechat_auth, $public_key);
+                    $data['wechat_auth'] = base64_encode($wechat_auth);
+                } else {
+                    $data['wechat_auth'] = '';
+                }
             }
         }
         $this->result($msg, $data, $code, $type, $header);

+ 45 - 11
application/common/model/UserLike.php

@@ -28,11 +28,28 @@ class UserLike extends Model
             ->where($where)
             ->limit($pageStart,$pageNum)
             ->select();
-        if($list) foreach($list as $k => $v) {
-            if($v['hobby_ids']) {
-                $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
-            } else {
-                $list[$k]['hobby_ids'] = [];
+        if($list) {
+            $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL.
+                wordwrap(config('public_key'), 64, PHP_EOL, true) .
+                PHP_EOL."-----END PUBLIC KEY-----";
+            foreach($list as $k => &$v) {
+                if ($v['wechat']) {
+                    $wechat = "";
+                    openssl_public_encrypt($v['wechat'], $wechat, $public_key);
+                    $v['wechat'] = base64_encode($wechat);
+                } else {
+                    $v['wechat'] = '';
+                }
+                $mobile = "";
+//                openssl_private_encrypt($data['mobile'], $mobile, $private_key); // 使用私钥加密数据
+                openssl_public_encrypt($v['mobile'], $mobile, $public_key);
+                $v['mobile'] = base64_encode($mobile);
+
+                if($v['hobby_ids']) {
+                    $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
+                } else {
+                    $list[$k]['hobby_ids'] = [];
+                }
             }
         }
         return $list;
@@ -45,16 +62,33 @@ class UserLike extends Model
         $where = [];
         $where["a.user_id"] = $user_id;
         $list = $this->alias("a")
-            ->field("a.id,a.fans_id as user_id,u.nickname,u.avatar,u.age,u.constellation,hobby_ids,profession,u.copy_mobile,u.mobile")
+            ->field("a.id,a.fans_id as user_id,u.nickname,u.avatar,u.age,u.constellation,u.wechat,hobby_ids,profession,u.copy_mobile,u.mobile")
             ->join("hx_user u","u.id = a.fans_id","left")
             ->where($where)
             ->limit($pageStart,$pageNum)
             ->select();
-        if($list) foreach($list as $k => $v) {
-            if($v['hobby_ids']) {
-                $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
-            } else {
-                $list[$k]['hobby_ids'] = [];
+        if($list) {
+            $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL.
+                wordwrap(config('public_key'), 64, PHP_EOL, true) .
+                PHP_EOL."-----END PUBLIC KEY-----";
+            foreach($list as $k => &$v) {
+                if ($v['wechat']) {
+                    $wechat = "";
+                    openssl_public_encrypt($v['wechat'], $wechat, $public_key);
+                    $v['wechat'] = base64_encode($wechat);
+                } else {
+                    $v['wechat'] = '';
+                }
+                $mobile = "";
+//                openssl_private_encrypt($data['mobile'], $mobile, $private_key); // 使用私钥加密数据
+                openssl_public_encrypt($v['mobile'], $mobile, $public_key);
+                $v['mobile'] = base64_encode($mobile);
+
+                if($v['hobby_ids']) {
+                    $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
+                } else {
+                    $list[$k]['hobby_ids'] = [];
+                }
             }
         }
         return $list;