Kaynağa Gözat

一键登录,绑定微信openid

lizhen_gitee 1 yıl önce
ebeveyn
işleme
a1a30b137a
2 değiştirilmiş dosya ile 41 ekleme ve 159 silme
  1. 36 154
      application/api/controller/User.php
  2. 5 5
      application/config.php

+ 36 - 154
application/api/controller/User.php

@@ -63,28 +63,6 @@ class User extends Api
         }
     }
 
-    //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次。
-    private function firstopen_send($oneuser){
-        //找出公会的人
-        $map = [
-            'gh_id'  => ['gt',0],
-            'gender'  => 0,
-        ];
-        $ghuser = Db::name('user')->where($map)->orderRaw('rand()')->limit(3)->column('id');
-        //dump($ghuser);
-
-        //随机取出一句话
-        $oneword = Db::name('plantask_accost')->orderRaw('rand()')->limit(3)->column('title');
-        //dump($oneword);
-
-        $tenim = new \app\common\library\Tenim;
-
-        for($i = 0;$i < 3;$i++){
-            $ghuser_one  = isset($ghuser[$i])  ? $ghuser[$i]  : $ghuser[array_rand($ghuser)];
-            $oneword_one = isset($oneword[$i]) ? $oneword[$i] : $oneword[array_rand($oneword)];
-            $tenim->sendMessageToUser($ghuser_one,$oneuser,$oneword_one);
-        }
-    }
 
     /**
      * 手机验证码登录
@@ -191,6 +169,9 @@ class User extends Api
 
         $user = \app\common\model\User::getByOpenid($wechat_openid);
         if ($user) {
+            if ($user->status == -1) {
+                $this->error('账户已注销');
+            }
             if ($user->status != 1) {
                 $this->error(__('Account is locked'));
             }
@@ -263,6 +244,9 @@ class User extends Api
 
                 $user = \app\common\model\User::getByMobile($mobile);
                 if ($user) {
+                    if ($user->status == -1) {
+                        $this->error('账户已注销');
+                    }
                     if ($user->status != 1) {
                         $this->error(__('Account is locked'));
                     }
@@ -378,13 +362,13 @@ class User extends Api
 
         //默认头像
         //现在没头像,也没穿头像,但是却传了性别
-        if($this->auth->avatar == config('site.domain_cdnurl').'/avatar.png' && isset($data['gender']) && $data['avatar'] == config('site.domain_cdnurl').'/avatar.png'){
+        /*if($this->auth->avatar == config('site.domain_cdnurl').'/avatar.png' && isset($data['gender']) && $data['avatar'] == config('site.domain_cdnurl').'/avatar.png'){
             if($data['gender'] == 1){
                 $data['avatar'] = 'https://meet-1251365327.cos.ap-beijing.myqcloud.com/uploads/20220314/f9277fba97fd76d9ecfc63b506a3674a.png';
             }else{
                 $data['avatar'] = 'https://meet-1251365327.cos.ap-beijing.myqcloud.com/uploads/20220314/5030460c05c86774f60123ffea7b78a1.png';
             }
-        }
+        }*/
         //默认头像
 
         Db::startTrans();
@@ -454,9 +438,7 @@ class User extends Api
         $this->success();
     }
 
-    public function set_status_switch(){
 
-    }
 
     /*
      * 修改用户的坐标
@@ -599,41 +581,38 @@ class User extends Api
     public function bindopenid()
     {
         Db::startTrans();
-        try {
-            $code =  $this->request->param('code','');
-            if(!$code){
-                throw new Exception(__('Invalid parameters'));
-            }
-            //微信
-            $wechat = new Wechat();
-            $openid = $wechat->getOpenid($code);
 
-            if(!$openid){
-                throw new Exception('openid获取失败');
-            }
+        $code =  $this->request->param('code','');
+        if(!$code){
+            $this->error(__('Invalid parameters'));
+        }
+        //微信
+        $wechat = new Wechat();
+        $openid = $wechat->getOpenid($code);
 
-            $user = model('User')->find($this->auth->id);
-            if(!empty($user['wechat_openid'])/* && $openid != $user['openid']*/){
-                throw new Exception('已经绑定了微信号');
-            }
-            $otherUserWhere['wechat_openid'] = $openid;
-            $otherUserWhere['id'] = ['neq',$this->auth->id];
-            $otherUser = model('User')->where($otherUserWhere)->find();
-            if (!empty($otherUser)) {
-                throw new Exception('该微信已被其他用户绑定过');
-            }
+        if(!$openid){
+            $this->error('openid获取失败');
+        }
 
-            $user->wechat_openid = $openid;
-            $userRes = $user->save();
-            if (!$userRes) {
-                throw new Exception('绑定微信失败');
-            }
-            Db::commit();
-            $this->success('success',$this->userInfo('return'));
-        } catch (Exception $e) {
-            Db::rollback();
-            $this->error($e->getMessage());
+        $user = model('User')->find($this->auth->id);
+        if(!empty($user['wechat_openid'])/* && $openid != $user['openid']*/){
+            $this->error('已经绑定了微信号');
         }
+        $otherUserWhere['wechat_openid'] = $openid;
+        $otherUserWhere['id'] = ['neq',$this->auth->id];
+        $otherUser = model('User')->where($otherUserWhere)->find();
+        if (!empty($otherUser)) {
+            $this->error('该微信已被其他用户绑定过');
+        }
+
+        $user->wechat_openid = $openid;
+        $userRes = $user->save();
+        if (!$userRes) {
+            $this->error('绑定微信失败');
+        }
+        Db::commit();
+        $this->success('success',$this->userInfo('return'));
+
     }
 
 
@@ -781,102 +760,6 @@ class User extends Api
         $this->success('注销成功');
     }
 
-
-    //APP 转化数据统计方案(即:APP 上报对接方案): 广告主上报激活数据,亿米平台搭建服务系统关联点击&下载数据和广告主提供的所有激活数据,将激活数据归因到对应广告。
-    public function yimi_advert(){
-        //http://trail.e.mi.com/global/log?appId={appid}&info={data}&conv_type={convType}&customer_id={customerId}
-        $api_url      = 'http://trail.e.mi.com/global/log?';
-        $api_url_test = 'http://trail.e.mi.com/global/test?';
-
-        //应用id 1453045
-        //秘钥A(encrypt_key):ZxdIaVHvFqSQYzWD
-        //秘钥B(sign_key):uaeWeunykLRnkyLw
-        $sign_key = 'uaeWeunykLRnkyLw'; //真的
-        $encrypt_key = 'ZxdIaVHvFqSQYzWD';//真的
-
-        $appid = '1453045';
-        $conv_type = 'APP_REGISTER';
-        $customer_id = '292232';
-
-        //推荐模式
-        /*$imei = md5('imei');
-        $data = [
-            'imei' => '91b9185dba1772851dd02b276a6c969e',
-            'oaid' => '5fb96f268628810c',
-            'conv_time' => '1504687208890',
-            'client_ip' => '127.0.0.1',
-            'ua' => 'Dalvik/2.1.0 (Linux; U; Android 11; M2012K11AC Build/RKQ1.200826.002)',
-        ];*/
-
-        //采用模式4
-        /*
-        $ua = input('ua','','trim');
-        if(empty($ua)){
-            return true;
-        }
-        $data = [
-            'conv_time' => time().substr(microtime(),2,3),
-            'client_ip' => request()->ip(),
-            'ua' => $ua,
-        ];
-        */
-
-        //采用模式3
-        $oaid = input('oaid','','trim');
-        if(empty($oaid)){
-            return true;
-        }
-        $data = [
-            'oaid' => $oaid,
-            'conv_time' => time().substr(microtime(),2,3),
-            'client_ip' => request()->ip(),
-        ];
-
-        $data_query = http_build_query($data);
-        //dump($data_query);
-
-        $property = $sign_key.'&'.urlencode($data_query);
-        //dump($property);
-
-        $signature = md5($property);
-        //dump($signature);
-
-        $base_data = $data_query .'&sign='.urlencode($signature);
-        //echo $base_data;
-
-        $info = urlencode(base64_encode($this->xor_enc($base_data, $encrypt_key)));
-        //dump($info);
-
-        $request_url = $api_url.'appId='.$appid.'&info='.$info.'&customer_id='.$customer_id.'&conv_type='.$conv_type;
-        //echo $request_url;
-
-        $result = curl_get($request_url);
-        //dump($result);
-        //日志
-        $log = [
-            'param' => $base_data,
-            'url'   => $request_url,
-            'result'=> $result,
-            'createtime' => time(),
-        ];
-        Db::name('yimi_advert')->insertGetId($log);
-
-        return true;
-    }
-
-    //亿米 异或加密,解密
-    public function xor_enc($str,$key)
-    {
-        $crytxt = '';
-        $keylen = strlen($key);
-        for($i=0;$i<strlen($str);$i++)
-        {
-            $k = $i%$keylen;
-            $crytxt .= $str[$i] ^ $key[$k];
-        }
-        return $crytxt;
-    }
-
     //公众号获取openid
     public function getUserOpenid_gzh(){
         $configValue = Service::getConfig('wechat');
@@ -887,7 +770,6 @@ class User extends Api
     }
     /**
      * 微信内H5-JSAPI支付
-     *
      */
     public function jssdkBuildConfig() {
         $url = $this->request->request("url");

+ 5 - 5
application/config.php

@@ -342,11 +342,11 @@ return [
     // 运营商一键登录
     'onLogin'        => [
         //
-        'secretid'     => '9241225ab5e880d9b746c043962486bf',
+        'secretid'     => '285634ecce83ba06ed0fefb40f54032b',
         //
-        'secretkey'      => '5c6f6483eb0002dd3a1d866d17f409b1',
+        'secretkey'      => 'ae6a74b00cc6433cbfe6507cd799b98e',
         //
-        'businessid'      => '31c634cee6364d47a007fe87a46342ea',
+        'businessid'      => '443e5907c6d9477a8896b4460ec485b6',
     ],
 
 
@@ -357,8 +357,8 @@ return [
 
     //开放平台的,不是小程序的
     'wxMiniProgram' => [
-        'appid'  => '',
-        'secret' => '',
+        'appid'  => 'wx4148b31582a36cbc',
+        'secret' => '5c56f3d50113caf5d105279305a2ca44',
     ],
 
     //阿里银行卡三要素