Explorar el Código

新的登录+注册

lizhen_gitee hace 1 año
padre
commit
354ffcb5bf

+ 42 - 42
addons/epay/config.php

@@ -2,54 +2,54 @@
 
 return [
     [
-        'name'    => 'wechat',
-        'title'   => '微信',
-        'type'    => 'array',
+        'name' => 'wechat',
+        'title' => '微信',
+        'type' => 'array',
         'content' => [],
-        'value'   => [
-            'appid'          => '',
-            'app_id'         => '',
-            'app_secret'     => '',
-            'miniapp_id'     => '',
-            'mch_id'         => '',
-            'key'            => '',
-            'mode'           => 'normal',
-            'sub_mch_id'     => '',
-            'sub_appid'      => '',
-            'sub_app_id'     => '',
+        'value' => [
+            'appid' => '',
+            'app_id' => '',
+            'app_secret' => '',
+            'miniapp_id' => 'wx876d08cf9b58ef10',
+            'mch_id' => '1650735102',
+            'key' => 'TEz4JneTy0AR2v0btHHTE0TtXbOMakvN',
+            'mode' => 'normal',
+            'sub_mch_id' => '',
+            'sub_appid' => '',
+            'sub_app_id' => '',
             'sub_miniapp_id' => '',
-            'notify_url'     => '/addons/epay/api/notifyx/type/wechat',
-            'cert_client'    => '/addons/epay/certs/apiclient_cert.pem',
-            'cert_key'       => '/addons/epay/certs/apiclient_key.pem',
-            'log'            => '1',
+            'notify_url' => '/addons/epay/api/notifyx/type/wechat',
+            'cert_client' => '/addons/epay/certs/apiclient_cert.pem',
+            'cert_key' => '/addons/epay/certs/apiclient_key.pem',
+            'log' => '1',
         ],
-        'rule'    => '',
-        'msg'     => '',
-        'tip'     => '微信参数配置',
-        'ok'      => '',
-        'extend'  => '',
+        'rule' => '',
+        'msg' => '',
+        'tip' => '微信参数配置',
+        'ok' => '',
+        'extend' => '',
     ],
     [
-        'name'    => 'alipay',
-        'title'   => '支付宝',
-        'type'    => 'array',
+        'name' => 'alipay',
+        'title' => '支付宝',
+        'type' => 'array',
         'content' => [],
-        'value'   => [
-            'app_id'              => '',
-            'mode'                => 'normal',
-            'notify_url'          => '/addons/epay/api/notifyx/type/alipay',
-            'return_url'          => '/addons/epay/api/returnx/type/alipay',
-            'private_key'         => '',
-            'ali_public_key'      => '',
+        'value' => [
+            'mode' => 'normal',
+            'app_id' => '',
+            'notify_url' => '/addons/epay/api/notifyx/type/alipay',
+            'return_url' => '/addons/epay/api/returnx/type/alipay',
+            'private_key' => '',
+            'ali_public_key' => '',
             'app_cert_public_key' => '',
-            'alipay_root_cert'    => '',
-            'log'                 => '1',
-            'scanpay'             => '0',
+            'alipay_root_cert' => '',
+            'log' => '1',
+            'scanpay' => '0',
         ],
-        'rule'    => 'required',
-        'msg'     => '',
-        'tip'     => '支付宝参数配置',
-        'ok'      => '',
-        'extend'  => '',
-    ]
+        'rule' => 'required',
+        'msg' => '',
+        'tip' => '支付宝参数配置',
+        'ok' => '',
+        'extend' => '',
+    ],
 ];

+ 1 - 0
application/api/controller/Baseconfig.php

@@ -17,6 +17,7 @@ class Baseconfig extends Api
 
         $config = [
             'contactus' => config('site.contactus'),
+//            'loginsite_bgimage' => config('site.loginsite_bgimage'),
         ];
 
         $this->success('success',$config);

+ 52 - 3
application/api/controller/User.php

@@ -402,7 +402,7 @@ class User extends Api
     /**
      * 微信小程序登录
      */
-    public function wxMiniProgramLogin() {
+    public function wxMiniProgramLogin_old() {
         $openid        = $this->request->request('openid');// openid值
         $avatar        = $this->request->request('avatar');
         $nickname      = $this->request->request('nickname');
@@ -421,7 +421,7 @@ class User extends Api
         $openidInfo = Db::name('user_sessionkey')->where(['openid'=>$openid])->find();
         $session_key = $openidInfo['sessionkey'];
 
-       // 微信授权openid登录
+        // 微信授权openid登录
         $userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
         // 用户信息不存在时使用
         $extend = [
@@ -449,7 +449,8 @@ class User extends Api
             }
 
             //学生入库
-            $stu_data['user_id'] = $this->auth->id;
+            $stu_data['user_id']    = $this->auth->id;
+            $stu_data['is_default'] = 1;
             Db::name('user_student')->insertGetId($stu_data);
 
             //从学生库找人,放到注册人名下
@@ -465,6 +466,54 @@ class User extends Api
         }
 
     }
+    /**
+     * 微信小程序登录
+     */
+    public function wxMiniProgramLogin() {
+        $openid        = $this->request->request('openid');// openid值
+
+        if (!$openid) {
+            $this->error(__('Invalid parameters'));
+        }
+
+        // 获取openid和sessionkey
+        $openidInfo = Db::name('user_sessionkey')->where(['openid'=>$openid])->find();
+        $session_key = $openidInfo['sessionkey'];
+
+        // 微信授权openid登录
+        $userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
+
+
+        // 判断用户是否已经存在
+        if($userInfo) { // 登录
+            Db::name('user')->where('id',$userInfo['id'])->update(['logintime'=>time()]);
+            $res = $this->auth->direct($userInfo['id']);
+        } else {
+            // 注册
+
+            // 用户信息不存在时使用
+            $extend = [
+                'mini_openid'    => $openid,
+                'mini_sessionkey'=> $session_key,
+                'unionid'        => $openidInfo['unionid'],
+            ];
+
+            // 默认注册一个会员
+            $result = $this->auth->register('', '', '','', $extend);
+            if (!$result) {
+                $this->error("注册失败!");
+            }
+
+            $res = $this->auth->direct($this->auth->id);
+        }
+        $userInfo = $this->getUserinfo('return');
+        if($res) {
+            $this->success("登录成功!",$userInfo);
+        } else {
+            $this->error("登录失败!");
+        }
+
+    }
 
     /**
      * json 请求

+ 2 - 2
application/common/library/Auth.php

@@ -173,8 +173,8 @@ class Auth
 //            'password' => $password,
 //            'email'    => $email,
 //            'mobile'   => $mobile,
-//            'nickname'  => $this->get_rand_nick_name(),
-//            'avatar'   => '/assets/img/avatar.png',
+            'nickname'  => $this->get_rand_nick_name(),
+            'avatar'    => '/assets/img/avatarlogo.png',
 //            'introcode' => $this->getUinqueNo(8, $introcode),
         ];
         $params = array_merge($data, [

BIN
public/assets/img/avatarlogo.png