lizhen_gitee 11 ماه پیش
والد
کامیت
e6aa390df5

+ 2 - 1
application/api/controller/Sms.php

@@ -27,6 +27,7 @@ class Sms extends Api
         $mobile = $this->request->post("mobile");
         $event = $this->request->post("event");
         $event = $event ? $event : 'register';
+        $event = 'default';
 
         if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
             $this->error(__('手机号不正确'));
@@ -53,7 +54,7 @@ class Sms extends Api
             }
         }
         if (!Hook::get('sms_send')) {
-            $this->error(__('请在后台插件管理安装短信验证插件'));
+            //$this->error(__('请在后台插件管理安装短信验证插件'));
         }
         $ret = Smslib::send($mobile, null, $event);
         if ($ret) {

+ 298 - 107
application/api/controller/User.php

@@ -8,13 +8,15 @@ use app\common\library\Sms;
 use fast\Random;
 use think\Config;
 use think\Validate;
-
+use app\common\library\Keyworld;
+use think\Db;
+use app\common\library\Wechat;
 /**
  * 会员接口
  */
 class User extends Api
 {
-    protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
+    protected $noNeedLogin = ['login', 'mobilelogin', 'wechatlogin', 'bindmobile','register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
     protected $noNeedRight = '*';
 
     public function _initialize()
@@ -35,28 +37,7 @@ class User extends Api
         $this->success('', ['welcome' => $this->auth->nickname]);
     }
 
-    /**
-     * 会员登录
-     *
-     * @ApiMethod (POST)
-     * @param string $account  账号
-     * @param string $password 密码
-     */
-    public function login()
-    {
-        $account = $this->request->post('account');
-        $password = $this->request->post('password');
-        if (!$account || !$password) {
-            $this->error(__('Invalid parameters'));
-        }
-        $ret = $this->auth->login($account, $password);
-        if ($ret) {
-            $data = ['userinfo' => $this->auth->getUserinfo()];
-            $this->success(__('Logged in successful'), $data);
-        } else {
-            $this->error($this->auth->getError());
-        }
-    }
+
 
     /**
      * 手机验证码登录
@@ -67,8 +48,8 @@ class User extends Api
      */
     public function mobilelogin()
     {
-        $mobile = $this->request->post('mobile');
-        $captcha = $this->request->post('captcha');
+        $mobile = input('mobile');
+        $captcha = input('captcha');
         if (!$mobile || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
@@ -89,54 +70,155 @@ class User extends Api
             //如果已经有账号则直接登录
             $ret = $this->auth->direct($user->id);
         } else {
-            $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
+            $ret = $this->auth->register('', '', '', $mobile, []);
         }
         if ($ret) {
             Sms::flush($mobile, 'mobilelogin');
-            $data = ['userinfo' => $this->auth->getUserinfo()];
-            $this->success(__('Logged in successful'), $data);
+            $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
         } else {
             $this->error($this->auth->getError());
         }
     }
 
+    //微信登录,预先假注册
+    public function wechatlogin(){
+        $code = input('code','');
+        if(!$code){
+            $this->error();
+        }
+        //微信
+        $wechat = new Wechat();
+        $wxuserinfo = $wechat->getAccessToken($code);
+
+        if(!$wxuserinfo){
+            $this->error('openid获取失败');
+        }
+        if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
+            $this->error('openid获取失败');
+        }
+
+        $openid = $wxuserinfo['openid'];
+
+        //检查用户
+        $user = Db::name('user')->where('wechat_openid',$openid)->find();
+        if ($user) {
+            if ($user['status'] == -1) {
+                $this->error('账户已注销');
+            }
+            if ($user['status'] != 1) {
+                $this->error(__('Account is locked'));
+            }
+            //如果已经有账号则直接登录
+            $ret = $this->auth->direct($user['id']);
+
+            if ($ret) {
+                $userInfo = $this->auth->getUserinfo_simple();
+                $userInfo['is_register'] = 0;
+                $userInfo['code'] = $code;
+                $this->success(__('Logged in successful'), $userInfo);
+            } else {
+                $this->error($this->auth->getError());
+            }
+
+        } else {
+            //记录code和openid,绑定手机号的时候更新openid
+            $wechatCodeData = [
+                'code' => $code,
+                'openid' => $openid,
+                'createtime' => time(),
+            ];
+            $wechatCode = Db::name('wechat_code')->where(['openid'=>$openid])->find();
+            if (empty($wechatCode)) {
+                Db::name('wechat_code')->insertGetId($wechatCodeData);
+            } else {
+                Db::name('wechat_code')->where(['openid'=>$openid])->update($wechatCodeData);
+            }
+
+            //直接返回
+            $userInfo = [];
+            $userInfo['is_register'] = 1;
+            $userInfo['code'] = $code;
+            $this->success('获取信息成功', $userInfo);
+        }
+
+    }
+
     /**
-     * 注册会员
+     * 微信注册来的,绑定手机号
      *
      * @ApiMethod (POST)
-     * @param string $username 用户名
-     * @param string $password 密码
-     * @param string $email    邮箱
      * @param string $mobile   手机号
-     * @param string $code     验证码
+     * @param string $captcha 验证码
      */
-    public function register()
+    public function bindmobile()
     {
-        $username = $this->request->post('username');
-        $password = $this->request->post('password');
-        $email = $this->request->post('email');
-        $mobile = $this->request->post('mobile');
-        $code = $this->request->post('code');
-        if (!$username || !$password) {
+        $mobile  = input('mobile');
+        $captcha = input('captcha');
+        $code    = input('code');
+
+        if (!$mobile || !$captcha || !$code) {
             $this->error(__('Invalid parameters'));
         }
-        if ($email && !Validate::is($email, "email")) {
-            $this->error(__('Email is incorrect'));
-        }
-        if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
+        if (!Validate::regex($mobile, "^1\d{10}$")) {
             $this->error(__('Mobile is incorrect'));
         }
-        $ret = Sms::check($mobile, $code, 'register');
-        if (!$ret) {
+        if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
             $this->error(__('Captcha is incorrect'));
         }
-        $ret = $this->auth->register($username, $password, $email, $mobile, []);
-        if ($ret) {
-            $data = ['userinfo' => $this->auth->getUserinfo()];
-            $this->success(__('Sign up successful'), $data);
+
+        $wechatCodeWhere['code'] = $code;
+        $wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
+        if (empty($wechatCode)) {
+            $this->error('请先微信登录');
+        }
+
+        //检查appid绑定的用户
+        $user = Db::name('user')->where('wechat_openid',$wechatCode['openid'])->find();
+        if ($user) {
+            if ($user['status'] == -1) {
+                $this->error('账户已注销');
+            }
+            if ($user['status'] != 1) {
+                $this->error(__('Account is locked'));
+            }
+            //如果已经有账号则直接登录
+            $ret = $this->auth->direct($user['id']);
+            $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
+        }
+
+        //新的openid用户
+        $where = [];
+        $where['mobile'] = $mobile;
+        $userData = Db::name('user')->where($where)->find();//老用户
+        if (!empty($userData)) {
+            if (empty($userData['wechat_openid'])) {
+                Db::name('user')->where('id',$userData['id'])->update(['wechat_openid' => $wechatCode['openid']]);//老用户更新openid
+            } else {
+                if ($userData['wechat_openid'] != $wechatCode['openid']) {
+                    $this->error('该手机号已被其他用户绑定');
+                }
+            }
+            $ret = $this->auth->direct($userData['id']);
         } else {
+            $extend = [
+                'wechat_openid' => $wechatCode['openid'],
+            ];
+            $ret = $this->auth->register('', '','', $mobile, $extend);
+        }
+        if (!$ret) {
             $this->error($this->auth->getError());
         }
+
+        $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
+
+    }
+
+
+    //用户详细资料
+    public function userInfo(){
+        $info = $this->auth->getUserinfo();
+
+        $this->success(__('success'),$info);
     }
 
     /**
@@ -163,101 +245,148 @@ class User extends Api
      */
     public function profile()
     {
-        $user = $this->auth->getUser();
-        $username = $this->request->post('username');
-        $nickname = $this->request->post('nickname');
-        $bio = $this->request->post('bio');
-        $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
-        if ($username) {
-            $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
-            if ($exists) {
-                $this->error(__('Username already exists'));
+        $field_array = [
+            'avatar','nickname','gender',
+        ];
+
+        $data = [];
+        foreach($field_array as $key => $field){
+
+            //前端传不了post,改了
+            /*if(!request()->has($field,'post')){
+                continue;
+            }*/
+            if(!input('?'.$field)){
+                continue;
             }
-            $user->username = $username;
-        }
-        if ($nickname) {
-            $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
-            if ($exists) {
-                $this->error(__('Nickname already exists'));
+
+            $newone = input($field);
+
+            if($field == 'avatar'){
+                $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
+            }
+
+            if($field == 'nickname'){
+                $newone = Keyworld::sensitive($newone);
             }
-            $user->nickname = $nickname;
+
+
+            $data[$field] = $newone;
         }
-        $user->bio = $bio;
-        $user->avatar = $avatar;
-        $user->save();
+
+        //
+        if(isset($data['birthday'])){
+            $data['birthday'] = strtotime($data['birthday']);
+        }
+
+        if(empty($data)){
+            $this->success();
+        }
+        $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
+
         $this->success();
     }
 
     /**
-     * 修改邮箱
+     * 修改手机号
      *
      * @ApiMethod (POST)
-     * @param string $email   邮箱
+     * @param string $mobile  手机号
      * @param string $captcha 验证码
      */
-    public function changeemail()
+    public function changemobile()
     {
         $user = $this->auth->getUser();
-        $email = $this->request->post('email');
-        $captcha = $this->request->post('captcha');
-        if (!$email || !$captcha) {
+        $oldcaptcha = input('oldcaptcha');
+        $mobile = input('mobile');
+        $captcha = input('captcha');
+        if (!$oldcaptcha || !$mobile || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
-        if (!Validate::is($email, "email")) {
-            $this->error(__('Email is incorrect'));
+        if (!Validate::regex($mobile, "^1\d{10}$")) {
+            $this->error(__('Mobile is incorrect'));
         }
-        if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
-            $this->error(__('Email already exists'));
+        if($user->mobile == $mobile){
+            $this->error('新手机号不能与旧手机号相同');
         }
-        $result = Ems::check($email, $captcha, 'changeemail');
+        if (\app\common\model\User::where('mobile', $mobile)->find()) {
+            $this->error(__('Mobile already exist'));
+        }
+        $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
         if (!$result) {
             $this->error(__('Captcha is incorrect'));
         }
-        $verification = $user->verification;
-        $verification->email = 1;
-        $user->verification = $verification;
-        $user->email = $email;
+        $result = Sms::check($mobile, $captcha, 'changemobile');
+        if (!$result) {
+            $this->error(__('Captcha is incorrect'));
+        }
+
+        Sms::flush($user->mobile, 'changemobile');
+        Sms::flush($mobile, 'changemobile');
+
+        $user->mobile = $mobile;
         $user->save();
 
-        Ems::flush($email, 'changeemail');
         $this->success();
     }
 
+    //假注销
+    public function cancleUser(){
+        /*$captcha = input('captcha','');
+
+        if (!$captcha) {
+            $this->error(__('Invalid parameters'));
+        }
+
+        if (!Sms::check($this->auth->mobile, $captcha, 'mobilelogin')) {
+            $this->error(__('Captcha is incorrect'));
+        }*/
+
+        Db::name('user')->where('id',$this->auth->id)->update(['status'=>-1]);
+
+        $this->auth->logout();
+        $this->success('注销成功');
+    }
+
+    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
     /**
-     * 修改手机号
+     * 修改邮箱
      *
      * @ApiMethod (POST)
-     * @param string $mobile  手机号
+     * @param string $email   邮箱
      * @param string $captcha 验证码
      */
-    public function changemobile()
+    public function changeemail()
     {
         $user = $this->auth->getUser();
-        $mobile = $this->request->post('mobile');
-        $captcha = $this->request->post('captcha');
-        if (!$mobile || !$captcha) {
+        $email = input('email');
+        $captcha = input('captcha');
+        if (!$email || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
-        if (!Validate::regex($mobile, "^1\d{10}$")) {
-            $this->error(__('Mobile is incorrect'));
+        if (!Validate::is($email, "email")) {
+            $this->error(__('Email is incorrect'));
         }
-        if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
-            $this->error(__('Mobile already exists'));
+        if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
+            $this->error(__('Email already exists'));
         }
-        $result = Sms::check($mobile, $captcha, 'changemobile');
+        $result = Ems::check($email, $captcha, 'changeemail');
         if (!$result) {
             $this->error(__('Captcha is incorrect'));
         }
         $verification = $user->verification;
-        $verification->mobile = 1;
+        $verification->email = 1;
         $user->verification = $verification;
-        $user->mobile = $mobile;
+        $user->email = $email;
         $user->save();
 
-        Sms::flush($mobile, 'changemobile');
+        Ems::flush($email, 'changeemail');
         $this->success();
     }
 
+
+
     /**
      * 第三方登录
      *
@@ -268,8 +397,8 @@ class User extends Api
     public function third()
     {
         $url = url('user/index');
-        $platform = $this->request->post("platform");
-        $code = $this->request->post("code");
+        $platform = input("platform");
+        $code = input("code");
         $config = get_addon_config('third');
         if (!$config || !isset($config[$platform])) {
             $this->error(__('Invalid parameters'));
@@ -300,11 +429,11 @@ class User extends Api
      */
     public function resetpwd()
     {
-        $type = $this->request->post("type", "mobile");
-        $mobile = $this->request->post("mobile");
-        $email = $this->request->post("email");
-        $newpassword = $this->request->post("newpassword");
-        $captcha = $this->request->post("captcha");
+        $type = input("type", "mobile");
+        $mobile = input("mobile");
+        $email = input("email");
+        $newpassword = input("newpassword");
+        $captcha = input("captcha");
         if (!$newpassword || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
@@ -348,4 +477,66 @@ class User extends Api
             $this->error($this->auth->getError());
         }
     }
+
+    /**
+     * 会员登录
+     *
+     * @ApiMethod (POST)
+     * @param string $account  账号
+     * @param string $password 密码
+     */
+    public function login()
+    {
+        $account = input('account');
+        $password = input('password');
+        if (!$account || !$password) {
+            $this->error(__('Invalid parameters'));
+        }
+        $ret = $this->auth->login($account, $password);
+        if ($ret) {
+            $data = ['userinfo' => $this->auth->getUserinfo()];
+            $this->success(__('Logged in successful'), $data);
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
+
+    /**
+     * 注册会员
+     *
+     * @ApiMethod (POST)
+     * @param string $username 用户名
+     * @param string $password 密码
+     * @param string $email    邮箱
+     * @param string $mobile   手机号
+     * @param string $code     验证码
+     */
+    public function register()
+    {
+        $username = input('username');
+        $password = input('password');
+        $email = input('email');
+        $mobile = input('mobile');
+        $code = input('code');
+        if (!$username || !$password) {
+            $this->error(__('Invalid parameters'));
+        }
+        if ($email && !Validate::is($email, "email")) {
+            $this->error(__('Email is incorrect'));
+        }
+        if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
+            $this->error(__('Mobile is incorrect'));
+        }
+        $ret = Sms::check($mobile, $code, 'register');
+        if (!$ret) {
+            $this->error(__('Captcha is incorrect'));
+        }
+        $ret = $this->auth->register($username, $password, $email, $mobile, []);
+        if ($ret) {
+            $data = ['userinfo' => $this->auth->getUserinfo()];
+            $this->success(__('Sign up successful'), $data);
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
 }

+ 170 - 0
application/common/library/Alisms.php

@@ -0,0 +1,170 @@
+<?php
+
+namespace app\common\library;
+
+/**
+ * 阿里大于SMS短信发送
+ */
+class Alisms
+{
+    private $_params = [];
+    public $error = '';
+    protected $config = [];
+    protected static $instance;
+
+    public function __construct($options = [])
+    {
+        if ($config = config('alisms')) {
+            $this->config = array_merge($this->config, $config);
+        }
+        $this->config = array_merge($this->config, is_array($options) ? $options : []);
+    }
+
+    /**
+     * 单例
+     * @param array $options 参数
+     * @return Alisms
+     */
+    public static function instance($options = [])
+    {
+        if (is_null(self::$instance)) {
+            self::$instance = new static($options);
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 设置签名
+     * @param string $sign
+     * @return Alisms
+     */
+    public function sign($sign = '')
+    {
+        $this->_params['SignName'] = $sign;
+        return $this;
+    }
+
+    /**
+     * 设置参数
+     * @param array $param
+     * @return Alisms
+     */
+    public function param(array $param = [])
+    {
+        foreach ($param as $k => &$v) {
+            $v = (string)$v;
+        }
+        unset($v);
+        $param = array_filter($param);
+        $this->_params['TemplateParam'] = $param ? json_encode($param) : '{}';
+        return $this;
+    }
+
+    /**
+     * 设置模板
+     * @param string $code 短信模板
+     * @return Alisms
+     */
+    public function template($code = '')
+    {
+        $this->_params['TemplateCode'] = $code;
+        return $this;
+    }
+
+    /**
+     * 接收手机
+     * @param string $mobile 手机号码
+     * @return Alisms
+     */
+    public function mobile($mobile = '')
+    {
+        $this->_params['PhoneNumbers'] = $mobile;
+        return $this;
+    }
+
+    /**
+     * 立即发送
+     * @return boolean
+     */
+    public function send()
+    {
+        $this->error = '';
+        $params = $this->_params();
+        $params['Signature'] = $this->_signed($params);
+        $response = $this->_curl($params);
+        if ($response !== false) {
+            $res = (array)json_decode($response, true);
+            if (isset($res['Code']) && $res['Code'] == 'OK') {
+                return true;
+            }
+            $this->error = isset($res['Message']) ? $res['Message'] : 'InvalidResult';
+        } else {
+            $this->error = 'InvalidResult';
+        }
+        return false;
+    }
+
+    /**
+     * 获取错误信息
+     * @return string
+     */
+    public function getError()
+    {
+        return $this->error;
+    }
+
+    private function _params()
+    {
+        return array_merge([
+            'AccessKeyId'      => $this->config['key'],
+            'SignName'         => isset($this->config['sign']) ? $this->config['sign'] : '',
+            'Action'           => 'SendSms',
+            'Format'           => 'JSON',
+            'Version'          => '2017-05-25',
+            'SignatureVersion' => '1.0',
+            'SignatureMethod'  => 'HMAC-SHA1',
+            'SignatureNonce'   => uniqid(),
+            'Timestamp'        => gmdate('Y-m-d\TH:i:s\Z'),
+        ], $this->_params);
+    }
+
+    private function percentEncode($string)
+    {
+        $string = urlencode($string);
+        $string = preg_replace('/\+/', '%20', $string);
+        $string = preg_replace('/\*/', '%2A', $string);
+        $string = preg_replace('/%7E/', '~', $string);
+        return $string;
+    }
+
+    private function _signed($params)
+    {
+        $sign = $this->config['secret'];
+        ksort($params);
+        $canonicalizedQueryString = '';
+        foreach ($params as $key => $value) {
+            $canonicalizedQueryString .= '&' . $this->percentEncode($key) . '=' . $this->percentEncode($value);
+        }
+        $stringToSign = 'GET&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
+        $signature = base64_encode(hash_hmac('sha1', $stringToSign, $sign . '&', true));
+        return $signature;
+    }
+
+    private function _curl($params)
+    {
+        $uri = 'http://dysmsapi.aliyuncs.com/?' . http_build_query($params);
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($ch, CURLOPT_URL, $uri);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
+        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.98 Safari/537.36");
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        $reponse = curl_exec($ch);
+        curl_close($ch);
+        return $reponse;
+    }
+}

+ 32 - 11
application/common/library/Auth.php

@@ -26,7 +26,7 @@ class Auth
     //默认配置
     protected $config = [];
     protected $options = [];
-    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar'];
+    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'gender'];
 
     public function __construct($options = [])
     {
@@ -138,7 +138,7 @@ class Auth
     public function register($username, $password, $email = '', $mobile = '', $extend = [])
     {
         // 检测用户名、昵称、邮箱、手机号是否存在
-        if (User::getByUsername($username)) {
+        /*if (User::getByUsername($username)) {
             $this->setError('Username already exist');
             return false;
         }
@@ -149,7 +149,13 @@ class Auth
         if ($email && User::getByEmail($email)) {
             $this->setError('Email already exist');
             return false;
+        }*/
+
+        if(empty($mobile)){
+            $this->setError('手机号必填');
+            return false;
         }
+
         if ($mobile && User::getByMobile($mobile)) {
             $this->setError('Mobile already exist');
             return false;
@@ -159,17 +165,18 @@ class Auth
         $time = time();
 
         $data = [
-            'username' => $username,
-            'password' => $password,
-            'email'    => $email,
+//            'username' => $username,
+//            'password' => $password,
+//            'email'    => $email,
             'mobile'   => $mobile,
-            'level'    => 1,
-            'score'    => 0,
+//            'level'    => 1,
+//            'score'    => 0,
             'avatar'   => '',
         ];
         $params = array_merge($data, [
-            'nickname'  => preg_match("/^1[3-9]{1}\d{9}$/", $username) ? substr_replace($username, '****', 3, 4) : $username,
-            'salt'      => Random::alnum(),
+//            'nickname'  => preg_match("/^1[3-9]{1}\d{9}$/", $username) ? substr_replace($username, '****', 3, 4) : $username,
+            'nickname'  => get_rand_nick_name(),
+//            'salt'      => Random::alnum(),
             'jointime'  => $time,
             'joinip'    => $ip,
             'logintime' => $time,
@@ -177,7 +184,7 @@ class Auth
             'prevtime'  => $time,
             'status'    => 1
         ]);
-        $params['password'] = $this->getEncryptPassword($password, $params['salt']);
+//        $params['password'] = $this->getEncryptPassword($password, $params['salt']);
         $params = array_merge($params, $extend);
 
         //账号注册时需要开启事务,避免出现垃圾数据
@@ -186,6 +193,8 @@ class Auth
             $user = User::create($params, true);
 
             $this->_user = User::get($user->id);
+            $this->_user->username = 'u' . (10000 + $user->id);
+            $this->_user->save();
 
             //设置Token
             $this->_token = Random::uuid();
@@ -194,6 +203,9 @@ class Auth
             //设置登录状态
             $this->_logined = true;
 
+            //注册钱包
+            Db::name('user_wallet')->insertGetId(['user_id'=>$user->id]);
+
             //注册成功的事件
             Hook::listen("user_register_successed", $this->_user, $data);
             Db::commit();
@@ -214,7 +226,8 @@ class Auth
      */
     public function login($account, $password)
     {
-        $field = Validate::is($account, 'email') ? 'email' : (Validate::regex($account, '/^1\d{10}$/') ? 'mobile' : 'username');
+//        $field = Validate::is($account, 'email') ? 'email' : (Validate::regex($account, '/^1\d{10}$/') ? 'mobile' : 'username');
+        $field = 'mobile';
         $user = User::get([$field => $account]);
         if (!$user) {
             $this->setError('Account is incorrect');
@@ -388,6 +401,12 @@ class Auth
         return $this->_token;
     }
 
+    public function getUserinfo_simple(){
+        $userinfo = Token::get($this->_token);
+
+        return $userinfo;
+    }
+
     /**
      * 获取会员基本信息
      */
@@ -397,6 +416,8 @@ class Auth
         $allowFields = $this->getAllowFields();
         $userinfo = array_intersect_key($data, array_flip($allowFields));
         $userinfo = array_merge($userinfo, Token::get($this->_token));
+
+        $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
         return $userinfo;
     }
 

+ 81 - 0
application/common/library/Keyworld.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace app\common\library;
+
+use think\Hook;
+use think\Config;
+/**
+ * 关键词检索类
+ */
+class Keyworld
+{
+
+    /**
+     * @todo 敏感词过滤,返回结果
+     * @param array $list  定义敏感词一维数组
+     * @param string $string 要过滤的内容
+     * @return string $log 处理结果
+     */
+    public static function sensitive_old($string){
+        $count = 0; //违规词的个数
+        $sensitiveWord = '';  //违规词
+        $stringAfter = $string;  //替换后的内容
+        $list = config('keyworld');  //定义敏感词数组
+
+        $pattern = "/".implode("|",$list)."/i"; //定义正则表达式
+        if(preg_match_all($pattern, $string, $matches)){ //匹配到了结果
+            $patternList = $matches[0];  //匹配到的数组
+            $count = count($patternList);
+            //$sensitiveWord = implode(',', $patternList); //敏感词数组转字符串
+
+            //$replaceArray = array_combine($patternList,array_fill(0,count($patternList),'*')); //把匹配到的数组进行合并,替换使用
+            $replace_arr = [1=>'*',2=>'**',3=>'***',4=>'****',5=>'*****','more'=>'*****...',];
+            $replaceArray = [];
+            foreach($patternList as $key => $val){
+                $replaceArray[$val] = isset($replace_arr[mb_strlen($val)]) ? $replace_arr[mb_strlen($val)] : $replace_arr['more'];
+            }
+            $stringAfter = strtr($string, $replaceArray); //结果替换
+        }
+
+        /*$rs = [];
+        $rs['string'] = $string;
+        $rs['count'] = $count;
+        $rs['keyworld'] = $patternList;
+        $rs['newstring'] = $stringAfter;*/
+
+        return $stringAfter;
+    }
+
+    public static function sensitive($string){
+        if(empty($string)){
+            return $string;
+        }
+
+        $list = config('keyworld');  //定义敏感词数组
+        $replaceArray = [];          //含有的违禁词集合
+
+        foreach($list as $key => $word){
+            if(empty($word)){
+                continue;
+            }
+            $start = strpos($string,$word);
+            if($start !== false){
+                $replaceArray[$word] = '*';
+            }
+        }
+
+        $stringAfter = strtr($string, $replaceArray); //结果替换
+        return $stringAfter;
+    }
+
+    public static function checkAction($data,$fields){
+        //$string = 'likeyou小白喜欢小黑爱着的大黄'; //要过滤的内容
+        foreach($data as $key => $string){
+            if(in_array($key,$fields)){
+                $data[$key] = self::sensitive($string);
+            }
+        }
+
+        return $data;
+    }
+}

+ 171 - 0
application/common/library/Wechat.php

@@ -0,0 +1,171 @@
+<?php
+
+namespace app\common\library;
+
+use fast\Http;
+use think\Cache;
+use think\Session;
+
+/**
+ * 微信授权
+ *
+ */
+class Wechat
+{
+    private $app_id = '';
+    private $app_secret = '';
+
+    private $scope = 'snsapi_userinfo';
+
+    public function __construct()
+    {
+        $wxConfig = config('wechat_app_login');
+        $this->app_id = $wxConfig['appid'];
+        $this->app_secret = $wxConfig['secret'];
+    }
+
+    /**
+     * 获取微信授权链接
+     *
+     * @return string
+     */
+    /*public function getAuthorizeUrl()
+    {
+        $redirect_uri = addon_url('epay/api/wechat', [], true, true);
+        $redirect_uri = urlencode($redirect_uri);
+        $state = \fast\Random::alnum();
+        Session::set('state', $state);
+        return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->app_id}&redirect_uri={$redirect_uri}&response_type=code&scope={$this->scope}&state={$state}#wechat_redirect";
+    }*/
+
+    /**
+     * 获取微信openid
+     *
+     * @return mixed|string
+     */
+
+    /*
+     array(5) {
+                  ["access_token"] => string(89) "49_r4I-StVANS8uYWTUHG86GJ-g1iH6mMFWy-9LeOta--2l6Bzg8LVDQFu8VSARu87atETzVJFZ-fndy-aQqEb8wQ"
+                  ["expires_in"] => int(7200)
+                  ["refresh_token"] => string(89) "49_8Vfa-imGcRmUwcESvpvMcEkiuh8kmD_movl9bIz9DV5GonZrqfIya5NgT7G-NMeJ7KTuCjMrSJi4BtojjDxnCQ"
+                  ["openid"] => string(28) "o8lxjwRjlDortQKhTk1dpHjQxcBU"
+                  ["scope"] => string(15) "snsapi_userinfo"
+            }
+     * */
+
+    public function getOpenid($code = '')
+    {
+        $openid = Session::get('openid');
+        if (!$openid) {
+
+            $token = $this->getAccessToken($code);
+            $openid = isset($token['openid']) ? $token['openid'] : '';
+            if ($openid) {
+                Session::set("openid", $openid);
+            }
+        }
+        return $openid;
+    }
+
+    /*
+    array(2) {
+              ["ret"] => bool(true)
+              ["msg"] => string(307) "{"openid":"o8lxjwRjlDortQKhTk1dpHjQxcBU","nickname":"科","sex":1,"language":"zh_CN","city":"临沂","province":"山东","country":"中国","headimgurl":"https:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/LGYWIv4F5vxZ2zCM9GEUynoQeJ6ibX9IfoKPAWLlGIugn1mgaAMPuqxzPBDQ3ktLEv2ia7HmOeJYTg5LofG8YlwQ\/132","privilege":[]}"
+            }
+     */
+    public function getwxuserinfo($code = '')
+    {
+        $wxuserinfo = Session::get('wxuserinfo');
+        if (!$wxuserinfo) {
+
+            $token = $this->getAccessToken($code);
+
+            $openid = isset($token['openid']) ? $token['openid'] : '';
+
+            $access_token = isset($token['access_token']) ? $token['access_token'] : '';
+
+            $ret = Http::sendRequest('https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN');
+            if ($ret['ret']) {
+                $wxuserinfo = json_decode($ret['msg'], true);
+                Session::set('wxuserinfo', $wxuserinfo);
+            }else{
+                $wxuserinfo = [];
+            }
+
+        }
+        return $wxuserinfo;
+    }
+
+
+    /**
+     * 获取授权token网页授权
+     *
+     * @param string $code
+     * @return mixed|string
+     */
+    public function getAccessToken($code = '')
+    {
+        $params = [
+            'appid'      => $this->app_id,
+            'secret'     => $this->app_secret,
+            'code'       => $code,
+            'grant_type' => 'authorization_code'
+        ];
+        $ret = Http::sendRequest('https://api.weixin.qq.com/sns/oauth2/access_token', $params, 'GET');
+        if ($ret['ret']) {
+            $ar = json_decode($ret['msg'], true);
+            return $ar;
+        }
+        return [];
+    }
+
+   /* public function getPublicAccessToken(){
+        $ret = Http::sendRequest('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$this->app_id.'&secret='.$this->app_secret);
+
+        if ($ret['ret']) {
+            $ar = json_decode($ret['msg'], true);
+
+            return $ar['access_token'];
+        }
+    }*/
+
+    //{"errcode":0,"errmsg":"ok","msgid":2054095443608862720}
+    /*public function send($ac,$openid,$first,$keyword1,$keyword2,$keyword3,$remark,$color){
+
+        $params = [
+            "touser"     => $openid,
+            "template_id"       => "lEUyDmLgwIaFDi9SNlIosXe-4fD43SiqSOZigIPOfJ8",
+            'url' => 'https://yanglaoweb.lanmaonet.com',
+            "data" => [
+                "first" => ["value"=>$first,"color"=>$color],
+                "keyword1" => ["value"=>$keyword1,"color"=>"#173177"],
+                "keyword2" => ["value"=>$keyword2,"color"=>"#173177"],
+                "keyword3" => ["value"=>$keyword3,"color"=>"#173177"],
+                "remark" => ["value"=>$remark,"color"=>$color],
+            ],
+            'miniprogram' => [],
+        ];
+
+        $rest = curl_post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$ac,json_encode($params));
+
+    }*/
+
+    /*public function getJsticket($code = '')
+    {
+        $jsticket = Session::get('jsticket');
+        if (!$jsticket) {
+            $token = $this->getAccessToken($code);
+            $params = [
+                'access_token' => 'token',
+                'type'         => 'jsapi',
+            ];
+            $ret = Http::sendRequest('https://api.weixin.qq.com/cgi-bin/ticket/getticket', $params, 'GET');
+            if ($ret['ret']) {
+                $ar = json_decode($ret['msg'], true);
+                return $ar;
+            }
+        }
+        return $jsticket;
+    }*/
+}

+ 2 - 2
application/common/model/User.php

@@ -42,8 +42,8 @@ class User extends Model
     {
         if (!$value) {
             //如果不需要启用首字母头像,请使用
-            //$value = '/assets/img/avatar.png';
-            $value = letter_avatar($data['nickname']);
+            $value = '/assets/img/avatar.png';
+            //$value = letter_avatar($data['nickname']);
         }
         return $value;
     }

+ 14 - 0
application/config.php

@@ -320,6 +320,14 @@ return [
         'redis_selectdb' => 0,
     ],
 
+    //阿里云短信配置,  借用tken
+    'alisms' =>[
+        'template_cn' => 'SMS_267360101', //国内
+        'sign' => 'TKEN',
+        'key' => 'LTAI5tE7djEZAXJcLtxshRu5',
+        'secret' => 'MK7sRjd2rpZ4PEbngf76PvKhvpTJWc',
+    ],
+
     //腾讯cos
     'cos'                  => [
         'appid' => '',
@@ -340,6 +348,12 @@ return [
 
     ],
 
+    //开放平台的
+    'wechat_app_login' => [
+        'appid'  => 'wx4148b31582a36cbc',
+        'secret' => '5c56f3d50113caf5d105279305a2ca44',
+    ],
+
     //各种url
     'pay_notify_url' => 'https://jiankangyijia.huxiukeji.cn',  //支付异步回调域名
 ];

+ 1 - 0
application/extra/site.php

@@ -71,4 +71,5 @@ return array (
   'doctor_ios_update_force' => '0',
   'doctor_ios_update_title' => '新的版本',
   'doctor_ios_update_info' => '界是你没有挽过的船新版本',
+  'kefuphoneno' => '400-1234-1175',
 );

+ 3 - 3
application/extra/wallet.php

@@ -8,13 +8,13 @@ return [
 /////////////////用户////////
         1 => '系统调节',//money + -
 
-        10 => '充值',//money +
+        10 => '钱包充值到账',//money +
 
         11 => '图文订单',//money -
         12 => '视频订单',//money -
 
 
-        21 => '提现',      //money -
+        21 => '钱包余额提现',//money -
         22 => '提现拒绝返回',//money +
 
 
@@ -23,7 +23,7 @@ return [
         111 => '图文订单', //money +
         112 => '视频订单', //money +
 
-        121 => '提现',       //money -
+        121 => '钱包余额提现', //money -
         122 => '提现拒绝返回', //money +