Sfoglia il codice sorgente

更新用户微信头像昵称时,验证是否传入了

sunxiaobiao 1 anno fa
parent
commit
d425d41219

+ 11 - 7
app/common/repositories/user/UserRepository.php

@@ -3199,7 +3199,7 @@ class UserRepository extends BaseRepository
3199 3199
     /*微信登录验证
3200 3200
      $openid 微信openid
3201 3201
     */
3202
-    public  function  wechatCheck($openid, $nickname = '', $headimgurl = ''){
3202
+    public  function  wechatCheck($openid, $nickname = null, $headimgurl = null){
3203 3203
         $user = Db::name("user")->where(['wechat_user_id'=>$openid])->find();
3204 3204
         //判断是否是第一次登录
3205 3205
         if($user){
@@ -3223,15 +3223,19 @@ class UserRepository extends BaseRepository
3223 3223
                         'type' => 1
3224 3224
                     ]);
3225 3225
                 }
3226
+                $data2 = [];
3227
+                if (!is_null($nickname) || !is_null($headimgurl)) {
3228
+                    $data2 = [
3229
+                        "type" => 1,
3230
+                        "uid" => $user['uid'],
3231
+                        "nickname" => $nickname ?: '',
3232
+                        "avater" => $headimgurl ?: '',
3233
+                    ];
3234
+                }
3226 3235
                 $this->updateUser(
3227 3236
                     $user['uid'],
3228 3237
                     ['wechat_user_id' => $openid],
3229
-                    [
3230
-                        "type" => 1,
3231
-                        "uid" => $user['uid'],
3232
-                        "nickname" => $nickname,
3233
-                        "avater" => $headimgurl,
3234
-                    ]
3238
+                    $data2
3235 3239
                 );
3236 3240
 
3237 3241
                 return ['code' => 200, 'msg' => '登陆成功', 'user' => $user];

+ 5 - 1
app/controller/api/Auth.php

@@ -1629,7 +1629,11 @@ class Auth extends BaseController
1629 1629
 
1630 1630
     /*微信授权登录*/
1631 1631
     public function wechatCheck(){
1632
-        $data =  $this->request->params(['openid', 'nickname', 'avatar']);
1632
+        $data =  $this->request->params(['openid']);
1633
+        // , 'nickname', 'avatar'
1634
+        $data['nickname'] = $this->request->param('nickname', null);
1635
+        $data['avatar'] = $this->request->param('avatar', null);
1636
+
1633 1637
         if(!$data['openid'] || $data['openid'] == '' || $data['openid'] =='undefined'){
1634 1638
             return app('json')->fail("openid参数缺失");
1635 1639
         }