|
@@ -15,7 +15,7 @@ use think\Db;
|
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
- protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'registercheck', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
|
|
+ protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'registercheck', 'resetpwd', 'changeemail', 'changemobile', 'third', 'getopenid', 'getagreement', 'wxlogin'];
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
|
@@ -80,15 +80,22 @@ class User extends Api
|
|
|
$this->error(__('Captcha is incorrect'));
|
|
|
}
|
|
|
$user = \app\common\model\User::getByMobile($mobile);
|
|
|
- if ($user) {
|
|
|
- if ($user->status != 'normal') {
|
|
|
- $this->error(__('Account is locked'));
|
|
|
- }
|
|
|
- //如果已经有账号则直接登录
|
|
|
- $ret = $this->auth->direct($user->id);
|
|
|
- } else {
|
|
|
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
|
|
|
+ if (!$user) {
|
|
|
+ $this->error('用户尚未注册');
|
|
|
}
|
|
|
+ if ($user['status'] != 1) {
|
|
|
+ $this->error(__('Account is locked'));
|
|
|
+ }
|
|
|
+// if ($user) {
|
|
|
+// if ($user->status != 'normal') {
|
|
|
+// $this->error(__('Account is locked'));
|
|
|
+// }
|
|
|
+// //如果已经有账号则直接登录
|
|
|
+// $ret = $this->auth->direct($user->id);
|
|
|
+// } else {
|
|
|
+// $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
|
|
|
+// }
|
|
|
+ $ret = $this->auth->direct($user->id);
|
|
|
if ($ret) {
|
|
|
Sms::flush($mobile, 'mobilelogin');
|
|
|
$data = ['userinfo' => $this->auth->getUserinfo()];
|
|
@@ -108,7 +115,7 @@ class User extends Api
|
|
|
* @param string $mobile 手机号
|
|
|
* @param string $code 验证码
|
|
|
*/
|
|
|
- public function register()
|
|
|
+ /*public function register()
|
|
|
{
|
|
|
$mobile = $this->request->post('mobile', '', 'trim'); //手机号
|
|
|
$code = $this->request->post('code', '', 'trim'); //验证码
|
|
@@ -241,7 +248,7 @@ class User extends Api
|
|
|
} else {
|
|
|
$this->error($this->auth->getError());
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
//注册第一步验证
|
|
|
public function registercheck()
|
|
@@ -1097,5 +1104,164 @@ class User extends Api
|
|
|
$this->success('个人账单明细', $data);
|
|
|
}
|
|
|
|
|
|
+ //关于我们/免责协议/用户协议/隐私政策
|
|
|
+ public function getagreement()
|
|
|
+ {
|
|
|
+ $type = input('type', 0, 'intval');
|
|
|
+ if (!in_array($type, [1, 2, 3, 4])) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = Db::name('platform_info')->field('title, content')->where(['type' => $type])->find();
|
|
|
+
|
|
|
+ $this->success('协议', $info);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取openid
|
|
|
+ public function getopenid() {
|
|
|
+ //code
|
|
|
+ $code = $this->request->param('code', '', 'trim');// code值
|
|
|
+ if (!$code) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $config = config('wxchatpay');
|
|
|
+ $getopenid_url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['app_id'].'&secret='.$config['app_secret'].'&js_code='.$code.'&grant_type=authorization_code';
|
|
|
+
|
|
|
+ $openidInfo = httpRequest($getopenid_url, 'GET');//$this->getJson($getopenid_url);
|
|
|
+ $openidInfo = json_decode($openidInfo,true);
|
|
|
+
|
|
|
+ if(!isset($openidInfo['openid'])) {
|
|
|
+ $this->error('用户openid获取失败', $openidInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('success', $openidInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //微信登录
|
|
|
+ public function wxlogin() {
|
|
|
+ $openid = input('openid', '', 'trim');
|
|
|
+ if (!$openid) {
|
|
|
+ $this->error('参数缺失');
|
|
|
+ }
|
|
|
|
|
|
+ $user = \app\common\model\User::getByOpenid($openid);
|
|
|
+ if (!$user) {
|
|
|
+ $this->error('用户尚未注册', [], 5);
|
|
|
+ }
|
|
|
+ if ($user['status'] != 1) {
|
|
|
+ $this->error(__('Account is locked'));
|
|
|
+ }
|
|
|
+ $ret = $this->auth->direct($user->id);
|
|
|
+ if ($ret) {
|
|
|
+ $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
+ $this->success(__('Logged in successful'), $data);
|
|
|
+ } else {
|
|
|
+ $this->error($this->auth->getError());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //注册
|
|
|
+ public function register()
|
|
|
+ {
|
|
|
+ $mobile = $this->request->post('mobile', '', 'trim'); //手机号
|
|
|
+ $code = $this->request->post('code', '', 'trim'); //验证码
|
|
|
+ $birthday = $this->request->post('birthday', '', 'strtotime'); //生日
|
|
|
+ $gender = $this->request->post('gender', 0, 'intval'); //性别:1=男,2=女
|
|
|
+ $invite_no = $this->request->post('invite_no', '', 'trim'); //邀请码
|
|
|
+ $openid = $this->request->post('openid', '', 'trim'); //微信openid
|
|
|
+ $nickname = $this->request->post('nickname', '', 'trim'); //微信昵称
|
|
|
+ $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars'); //微信头像
|
|
|
+
|
|
|
+ $openidcount = Db::name('user')->where(['openid' => $openid])->count('id');
|
|
|
+ if ($openidcount) {
|
|
|
+ $this->error('微信已经注册,请直接登录');
|
|
|
+ }
|
|
|
+ if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
+ $this->error(__('Mobile is incorrect'));
|
|
|
+ }
|
|
|
+ $count = Db::name('user')->where(['mobile' => $mobile])->count('id');
|
|
|
+ if ($count) {
|
|
|
+ $this->error('手机号已被注册');
|
|
|
+ }
|
|
|
+ if (iconv_strlen($code, 'utf-8') != config('alisms.length')) {
|
|
|
+ $this->error(__('Captcha is incorrect'));
|
|
|
+ }
|
|
|
+ $ret = Sms::check($mobile, $code, 'register');
|
|
|
+ if (!$ret) {
|
|
|
+ $this->error(__('Captcha is incorrect'));
|
|
|
+ }
|
|
|
+ if (!$birthday || $birthday >= time()) {
|
|
|
+ $this->error('请选择正确生日');
|
|
|
+ }
|
|
|
+ if (!in_array($gender, [1, 2])) {
|
|
|
+ $this->error('请选择性别');
|
|
|
+ }
|
|
|
+ $invitecount = Db::name('user')->where(['invite_no' => $invite_no])->count('id');
|
|
|
+ if (!$invitecount) {
|
|
|
+ $this->error('邀请码不存在');
|
|
|
+ }
|
|
|
+ if (!$nickname || !$avatar) {
|
|
|
+ $this->error('参数缺失');
|
|
|
+ }
|
|
|
+ if (iconv_strlen($nickname, 'utf-8') > 30 || iconv_strlen($avatar, 'utf-8') > 255) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $ip = request()->ip();
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'nickname' => $nickname,
|
|
|
+ 'province' => $province,
|
|
|
+ 'city' => $city,
|
|
|
+ 'area' => $area,
|
|
|
+ 'address' => $address,
|
|
|
+ 'createtime' => $time
|
|
|
+ ];
|
|
|
+ $params = array_merge($data, [
|
|
|
+ 'mobile' => $mobile,
|
|
|
+ 'password' => $password,
|
|
|
+ 'avatar' => '/assets/img/avatar.png',
|
|
|
+ 'salt' => Random::alnum(),
|
|
|
+ 'jointime' => $time,
|
|
|
+ 'joinip' => $ip,
|
|
|
+ 'logintime' => $time,
|
|
|
+ 'loginip' => $ip,
|
|
|
+ 'prevtime' => $time,
|
|
|
+ 'is_auth' => 1
|
|
|
+ ]);
|
|
|
+ $params['password'] = md5(md5($password) . $params['salt']);
|
|
|
+
|
|
|
+ //开启事务
|
|
|
+ Db::startTrans();
|
|
|
+
|
|
|
+ $rs = Db::name('user')->insertGetId($params);
|
|
|
+ if (!$rs) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('注册失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['user_id'] = $rs;
|
|
|
+ $data['idcard'] = $idcard;
|
|
|
+ $data['zimage'] = $zimage;
|
|
|
+ $data['fimage'] = $fimage;
|
|
|
+ $data['recommender'] = $recommender;
|
|
|
+ $data['recommender_mobile'] = $recommender_mobile;
|
|
|
+
|
|
|
+ $rt = Db::name('user_auth')->insertGetId($data);
|
|
|
+ if (!$rt) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('注册失败');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+
|
|
|
+ $ret = $this->auth->login($mobile, $password);
|
|
|
+ if ($ret) {
|
|
|
+ $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
+ $this->success(__('Sign up successful'), $data);
|
|
|
+ } else {
|
|
|
+ $this->error($this->auth->getError());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|