xieruidong 2 years ago
parent
commit
a3aa209d87

+ 8 - 0
application/common/library/Auth.php

@@ -5,6 +5,7 @@ namespace app\common\library;
 use app\admin\model\UserRule;
 use app\common\model\User;
 use fast\Random;
+use think\Cache;
 use think\Config;
 use think\Db;
 use think\Exception;
@@ -174,6 +175,13 @@ class Auth
                 return false;
             }
         }
+        if(empty($extend['unionid']) && !empty($extend['openid'])){
+            $unionid=Cache::get("union_id_{$extend['openid']}");
+            if($unionid){
+                $extend['unionid']=$unionid;
+                Cache::rm("union_id_{$extend['openid']}");
+            }
+        }
             $ip = request()->ip();
             $time = time();
             $data = [

+ 4 - 8
application/common/service/WxOpenService.php

@@ -57,16 +57,12 @@ class WxOpenService{
                 }
             }
             elseif($e==1){
-                Cache::set("wx_open_openid_{$key}", $arr['openid'], 600);
+                //Cache::set("wx_open_openid_{$key}", $arr['openid'], 600);
+                if(!empty($arr['unionid'])) {
+                    Cache::set("union_id_{$arr['openid']}", $arr['unionid'], 600);
+                }
             }
             return [true,$arr['openid'],$arr];
         }
     }
-    public static function getCachedOpenId($key){
-        $openid=Cache::get($cacheKey="wx_open_openid_{$key}",'');
-        if($openid){
-            Cache::rm($cacheKey);
-        }
-        return $openid;
-    }
 }