123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\Ems;
- use app\common\library\Sms;
- use fast\Random;
- use think\Config;
- use think\Validate;
- use think\Db;
- use miniprogram\wxBizDataCrypt;
- use alipaysdkphpallmaster\aop\AopClient;
- use alipaysdkphpallmaster\aop\request\AlipaySystemOauthTokenRequest;
- /**
- * 会员接口
- */
- class User extends Api
- {
- protected $noNeedLogin = ['login','appmobilelogin', 'getAlipayUserid','AlipayMiniProgramLogin','aliminimobilelogin','mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third', 'getUserOpenid','getAppOpenid','wxMiniProgramLogin','wxAPPLogin'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- if (!Config::get('fastadmin.usercenter')) {
- $this->error(__('User center already closed'));
- }
- }
- /**
- * 手机验证码登录。app端用的
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function aliminimobilelogin(){
- $mobile = $this->request->post('mobile');
- $captcha = $this->request->post('captcha');
- $openid = $this->request->post('user_id');
- $introcode = $this->request->post('introcode','');
- if (!$mobile || !$captcha || !$openid) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- // 获取openid和sessionkey
- $openidInfo = Db::name('user_sessionkey_alipay')->where(['user_id'=>$openid])->find();
- if(!$openidInfo){
- $this->error('user_id获取失败');
- }
- //
- $check_user = Db::name('user')->where('ali_user_id',$openidInfo['user_id'])->where('mobile','neq',$mobile)->find();
- if($check_user){
- $this->error('已经绑定手机号'.$check_user['mobile'].',请使用该手机号登录');
- }
- //
- $intro_uid = 0;
- if(!empty($introcode)){
- $intro_uid = Db::name('user')->where('introcode',$introcode)->value('id');
- if(empty($intro_uid)){
- $this->error('请填写正确的邀请码或者不填');
- }
- }
- //登录与注册
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- if ($user->status == 0) {
- $this->error(__('Account is locked'));
- }
- if ($user->status == 2) {
- $this->error('该用户已注销');
- }
- if (!empty($user->ali_user_id)){
- if($user->ali_user_id != $openidInfo['user_id']){
- $this->error('请使用初始注册的支付宝账号进行登录');
- }
- }
- //修改最新的openid。其他渠道注册,本渠道第一次来就赋值
- /*$user->ali_user_id = $openid;
- $user->save();*/
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- } else {
- // 用户信息不存在时使用
- $extend = [
- 'ali_user_id' => $openid,
- 'intro_uid' => $intro_uid,
- ];
- $ret = $this->auth->register_mobile($mobile, Random::alnum(), '', $mobile, $extend);
- //注册赠送积分
- $register_gift_score = intval(config('site.register_gift_score'));
- if($register_gift_score > 0){
- $wallet = new \app\common\model\Wallet;
- $wallet_rs = $wallet->lockChangeAccountRemain($this->auth->id,'score',$register_gift_score,22,'注册赠送积分','user',$this->auth->id);
- }
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = ['userinfo' => $this->getUserinfo('return')];
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 手机验证码登录。app端用的
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function appmobilelogin(){
- $mobile = $this->request->post('mobile');
- $captcha = $this->request->post('captcha');
- $openid = $this->request->post('openid');
- $introcode = $this->request->post('introcode','');
- if (!$mobile || !$captcha || !$openid) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- // 获取openid和sessionkey
- $openidInfo = Db::name('user_sessionkey')->where(['app_openid'=>$openid])->find();
- if(!$openidInfo){
- $this->error('openid获取失败');
- }
- //
- $check_user = Db::name('user')->where('unionid',$openidInfo['unionid'])->where('mobile','neq',$mobile)->find();
- if($check_user){
- $this->error('该微信已经绑定手机号'.$check_user['mobile'].',请使用该手机号登录');
- }
- //
- $intro_uid = 0;
- if(!empty($introcode)){
- $intro_uid = Db::name('user')->where('introcode',$introcode)->value('id');
- if(empty($intro_uid)){
- $this->error('请填写正确的邀请码或者不填');
- }
- }
- //登录与注册
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- if ($user->status == 0) {
- $this->error(__('Account is locked'));
- }
- if ($user->status == 2) {
- $this->error('该用户已注销');
- }
- if (!empty($user->unionid)){
- if($user->unionid != $openidInfo['unionid']){
- $this->error('请使用初始注册的微信账号进行登录');
- }
- }else{
- //修改最新的openid。其他渠道注册,本渠道第一次来就赋值
- $user->unionid = $openidInfo['unionid']; //支付宝注册来的,就得给赋值
- $user->app_openid = $openid;
- $user->save();
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- } else {
- // 用户信息不存在时使用
- $extend = [
- 'app_openid' => $openid,
- 'unionid' => $openidInfo['unionid'],
- 'intro_uid' => $intro_uid,
- ];
- $ret = $this->auth->register_mobile($mobile, Random::alnum(), '', $mobile, $extend);
- //注册赠送积分
- $register_gift_score = intval(config('site.register_gift_score'));
- if($register_gift_score > 0){
- $wallet = new \app\common\model\Wallet;
- $wallet_rs = $wallet->lockChangeAccountRemain($this->auth->id,'score',$register_gift_score,22,'注册赠送积分','user',$this->auth->id);
- }
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = ['userinfo' => $this->getUserinfo('return')];
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 手机验证码登录。小程序端用的
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function mobilelogin()
- {
- $mobile = $this->request->post('mobile');
- $captcha = $this->request->post('captcha');
- $openid = $this->request->post('openid');
- $introcode = $this->request->post('introcode','');
- if (!$mobile || !$captcha || !$openid) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- // 获取openid和sessionkey
- $openidInfo = Db::name('user_sessionkey')->where(['openid'=>$openid])->find();
- if(!$openidInfo){
- $this->error('openid获取失败');
- }
- //
- $check_user = Db::name('user')->where('mini_openid',$openidInfo['openid'])->where('mobile','neq',$mobile)->find();
- if($check_user){
- $this->error('该微信已经绑定手机号'.$check_user['mobile'].',请使用该手机号登录');
- }
- //
- $intro_uid = 0;
- if(!empty($introcode)){
- $intro_uid = Db::name('user')->where('introcode',$introcode)->value('id');
- if(empty($intro_uid)){
- $this->error('请填写正确的邀请码或者不填');
- }
- }
- //登录与注册
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- if ($user->status == 0) {
- $this->error(__('Account is locked'));
- }
- if ($user->status == 2) {
- $this->error('该用户已注销');
- }
- if (!empty($user->unionid)){
- if($user->unionid != $openidInfo['unionid']){
- $this->error('请使用初始注册的微信账号进行登录');
- }
- }else{
- //修改最新的sessionkey和openid。其他渠道注册,本渠道第一次来就赋值
- // $user->unionid = $openidInfo['unionid']; //支付宝注册的,就得赋值
- $user->mini_openid = $openid;
- $user->mini_sessionkey = $openidInfo['sessionkey'];
- $user->save();
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- } else {
- // 用户信息不存在时使用
- $extend = [
- 'mini_openid' => $openid,
- 'mini_sessionkey'=> $openidInfo['sessionkey'],
- // 'unionid' => $openidInfo['unionid'],
- 'intro_uid' => $intro_uid,
- ];
- $ret = $this->auth->register_mobile($mobile, Random::alnum(), '', $mobile, $extend);
- //注册赠送积分
- $register_gift_score = intval(config('site.register_gift_score'));
- if($register_gift_score > 0){
- $wallet = new \app\common\model\Wallet;
- $wallet_rs = $wallet->lockChangeAccountRemain($this->auth->id,'score',$register_gift_score,22,'注册赠送积分','user',$this->auth->id);
- }
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = ['userinfo' => $this->getUserinfo('return')];
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 退出登录
- * @ApiMethod (POST)
- */
- public function logout()
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
- $this->auth->logout();
- $this->success(__('Logout successful'));
- }
- //注销用户
- public function cancellation(){
- Db::name('user')->where('id',$this->auth->id)->update(['status'=>2]);
- $this->auth->logout();
- $this->success('注销成功');
- }
- //用户详细资料
- public function getUserinfo($type = 1){
- $info = $this->auth->getUserinfo();
- if($type == 'return'){
- return $info;
- }
- $this->success(__('success'),$info);
- }
- /**
- * 修改会员个人信息
- *
- * @ApiMethod (POST)
- * @param string $avatar 头像地址
- * @param string $username 用户名
- * @param string $nickname 昵称
- * @param string $bio 个人简介
- */
- public function profile()
- {
- $user = $this->auth->getUser();
- $nickname = $this->request->post('nickname','');
- $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
- if(!empty($nickname)){
- $user->nickname = $nickname;
- }
- if(!empty($avatar)){
- $user->avatar = $avatar;
- }
- $user->updatetime = time();
- $user->save();
- $this->success();
- }
- /*
- * 获取阿里小程序user_id 类似于 unionid
- array(7) {
- ["access_token"] => string(40) "authbseB9a88caaf0c4f431e853b3f47c7c2bX55"
- ["alipay_user_id"] => string(32) "20881082573776119399662512314555"
- ["auth_start"] => string(19) "2023-03-27 16:50:11"
- ["expires_in"] => int(31536000)
- ["re_expires_in"] => int(31536000)
- ["refresh_token"] => string(40) "authbseBd9f5b3f1f07145a3b734a9ca08c8dF55"
- ["user_id"] => string(16) "2088802394079558"
- }
- * */
- public function getAlipayUserid(){
- // code值
- $code = $this->request->param('code');
- if (!$code) {
- $this->error(__('Invalid parameters'));
- }
- $openidInfo = $this->alipay_oauthtoken($code);
- if(!isset($openidInfo['access_token'])) {
- $this->error('access_token获取失败',$openidInfo);
- }
- if(!isset($openidInfo['user_id'])) {
- $this->error('用户user_id获取失败',$openidInfo);
- }
- $user_id = $openidInfo['user_id'];
- $check = Db::name('user_sessionkey_alipay')->where('user_id',$user_id)->find();
- if($check){
- $res = Db::name('user_sessionkey_alipay')->where('user_id',$user_id)->update($openidInfo);
- }else{
- $res = Db::name('user_sessionkey_alipay')->insertGetId($openidInfo);
- }
- $result = [
- 'user_id' => $user_id,
- ];
- if($res !== false) {
- $this->success('获取成功',$result);
- } else {
- $this->error('获取失败');
- }
- }
- /**
- * 阿里小程序登录
- */
- public function AlipayMiniProgramLogin() {
- $openid = $this->request->request('user_id');// openid值
- if (!$openid) {
- $this->error(__('Invalid parameters'));
- }
- // 用户登录逻辑 === 开始
- $user_sessionkey = Db::name('user_sessionkey_alipay')->where('user_id',$openid)->find();
- $userInfo = Db::name('user')->where(['ali_user_id'=>$user_sessionkey['user_id']])->find();
- // 判断用户是否已经存在
- if($userInfo) { // 登录
- if ($userInfo['status'] == 0) {
- $this->error(__('Account is locked'));
- }
- if ($userInfo['status'] == 2) {
- $this->error('该用户已注销');
- }
- $update = [
- 'logintime' => time(),
- ];
- Db::name('user')->where('id',$userInfo['id'])->update($update);
- $res = $this->auth->direct($userInfo['id']);
- } else {
- //这里不在给注册,而是只能mobilelogin来注册
- $this->error('登录失败,请先使用手机号注册','',-1);
- }
- $userInfo = $this->getUserinfo('return');
- if($res) {
- if(empty($userInfo['mobile'])){
- $this->success("登录成功!",$userInfo,-1);
- }
- $this->success("登录成功!",$userInfo);
- } else {
- $this->error("登录失败!");
- }
- }
- //获取阿里授权
- private function alipay_oauthtoken($code = '')
- {
- $config = config('Alimini');
- $aop = new AopClient ();
- $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
- $aop->appId = $config['appId'];
- $aop->rsaPrivateKey = $config['rsaPrivateKey'];
- $aop->alipayrsaPublicKey=$config['alipayrsaPublicKey'];
- $aop->signType = 'RSA2';
- $request = new AlipaySystemOauthTokenRequest ();
- $request->setGrantType("authorization_code");
- $request->setCode($code);
- $request->setRefreshToken('');
- $result = $aop->execute ( $request);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- /*$resultCode = $result->$responseNode->code;
- //dump($resultCode);
- if(!empty($resultCode)&&$resultCode == 10000){
- echo "成功";
- } else {
- echo "失败";
- }*/
- return (array)$result->$responseNode;
- }
- //获取app用户的access_token和unionid
- /*
- {
- "code":1,
- "msg":"获取成功",
- "time":"1677578250",
- "data":{
- "access_token":"66_p3_21ZTj9yWf6urG5OVBctFCFSyd0uvAxVrhWybtdTugxLgkJXM48PreDtD8HM5vrpNRKKjzWcqnvB01P7NYKS8iqwr8u2hnryiNILFeUGo",
- "expires_in":7200,
- "refresh_token":"66_NpmP0-lNl0ek1Nsad8OGAjuwznMG0KSq_8d3rmrkKNhvFmW2_K5oxlwr0kNFOsvM90s6ODc3bONvbF1zmqYIx9JLlG9By7vf94YWJk3602E",
- "openid":"oCvQ560NwtAZf-g4EqoYSypastJ8",
- "scope":"snsapi_userinfo",
- "unionid":"oOPcI6Jzozsffndh4CzVGXmwLejU"
- }
- }
- */
- public function getAppOpenid(){
- // code值
- $code = $this->request->param('code');
- if (!$code) {
- $this->error(__('Invalid parameters'));
- }
- $config = config('wechatlogin');
- $wechat = new \app\common\library\Wechat($config['AppID'],$config['AppSecret']);
- $openidInfo = $wechat->getAccessToken($code);
- if(!isset($openidInfo['access_token'])) {
- $this->error('access_token获取失败',$openidInfo);
- }
- if(!isset($openidInfo['openid'])) {
- $this->error('用户openid获取失败',$openidInfo);
- }
- if(!isset($openidInfo['unionid'])){
- $this->error('unionid不存在',$openidInfo);
- }
- // 获取的结果存入数据库
- $find = Db::name('user_sessionkey')->where(['unionid'=>$openidInfo['unionid']])->find();
- if($find) {
- $update = [];
- $update['createtime'] = time();
- $update['access_token'] = $openidInfo['access_token'];
- $update['app_openid'] = $openidInfo['openid'];
- $res = Db::name('user_sessionkey')->where(['unionid'=>$openidInfo['unionid']])->update($update);
- } else {
- $insert = [];
- $insert['unionid'] = isset($openidInfo['unionid']) ? $openidInfo['unionid'] : '';
- $insert['createtime'] = time();
- $insert['access_token'] = $openidInfo['access_token'];
- $insert['app_openid'] = $openidInfo['openid'];
- $res = Db::name('user_sessionkey')->insertGetId($insert);
- }
- if($res !== false) {
- $this->success('获取成功',$openidInfo);
- } else {
- $this->error('获取失败');
- }
- }
- //微信app授权登录,
- public function wxAPPLogin(){
- $openid = $this->request->request('openid');// openid值
- if (!$openid) {
- $this->error(__('Invalid parameters'));
- }
- // 用户登录逻辑 === 开始
- $user_sessionkey = Db::name('user_sessionkey')->where('app_openid',$openid)->find();
- $userInfo = Db::name('user')->where(['unionid'=>$user_sessionkey['unionid']])->find();
- // 判断用户是否已经存在
- if($userInfo) { // 登录
- if ($userInfo['status'] == 0) {
- $this->error(__('Account is locked'));
- }
- if ($userInfo['status'] == 2) {
- $this->error('该用户已注销');
- }
- $update = [
- 'app_openid' => $user_sessionkey['app_openid'],//已经有的不需要更新
- 'logintime' => time(),
- ];
- Db::name('user')->where('id',$userInfo['id'])->update($update);
- $res = $this->auth->direct($userInfo['id']);
- } else {
- //这里不在给注册,而是只能mobilelogin来注册
- $this->error('登录失败,请先使用手机号注册','',-1);
- }
- $userInfo = $this->getUserinfo('return');
- if($res) {
- if(empty($userInfo['mobile'])){
- $this->success("登录成功!",$userInfo,-1);
- }
- $this->success("登录成功!",$userInfo);
- } else {
- $this->error("登录失败!");
- }
- }
- /**
- * 获取用户openid
- */
- public function getUserOpenid_old() {
- // code值
- $code = $this->request->param('code');
- if (!$code) {
- $this->error(__('Invalid parameters'));
- }
- $config = config('wxMiniProgram');
- $getopenid = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
- $openidInfo = $this->getJson($getopenid);
- if(!isset($openidInfo['openid'])) {
- $this->error('用户openid获取失败',$openidInfo);
- }
- if(!isset($openidInfo['unionid'])){
- $this->error('unionid不存在',$openidInfo);
- }
- // 获取的结果存入数据库
- $find = Db::name('user_sessionkey')->where(['unionid'=>$openidInfo['unionid']])->find();
- if($find) {
- $update = [];
- $update['openid'] = $openidInfo['openid'];
- $update['sessionkey'] = $openidInfo['session_key'];
- $update['createtime'] = time();
- $res = Db::name('user_sessionkey')->where(['unionid'=>$openidInfo['unionid']])->update($update);
- } else {
- $insert = [];
- $insert['openid'] = $openidInfo['openid'];
- $insert['sessionkey'] = $openidInfo['session_key'];
- $insert['unionid'] = isset($openidInfo['unionid']) ? $openidInfo['unionid'] : '';
- $insert['createtime'] = time();
- $res = Db::name('user_sessionkey')->insertGetId($insert);
- }
- if($res !== false) {
- $this->success('获取成功',$openidInfo);
- } else {
- $this->error('获取失败');
- }
- }
- public function getUserOpenid() {
- // code值
- $code = $this->request->param('code');
- if (!$code) {
- $this->error(__('Invalid parameters'));
- }
- $config = config('wxMiniProgram');
- $getopenid = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
- $openidInfo = $this->getJson($getopenid);
- if(!isset($openidInfo['openid'])) {
- $this->error('用户openid获取失败',$openidInfo);
- }
- /*if(!isset($openidInfo['unionid'])){
- $this->error('unionid不存在',$openidInfo);
- }*/
- // 获取的结果存入数据库
- $find = Db::name('user_sessionkey')->where(['openid'=>$openidInfo['openid']])->find();
- if($find) {
- $update = [];
- $update['openid'] = $openidInfo['openid'];
- $update['sessionkey'] = $openidInfo['session_key'];
- $update['createtime'] = time();
- $res = Db::name('user_sessionkey')->where(['openid'=>$openidInfo['openid']])->update($update);
- } else {
- $insert = [];
- $insert['openid'] = $openidInfo['openid'];
- $insert['sessionkey'] = $openidInfo['session_key'];
- // $insert['unionid'] = isset($openidInfo['unionid']) ? $openidInfo['unionid'] : '';
- $insert['createtime'] = time();
- $res = Db::name('user_sessionkey')->insertGetId($insert);
- }
- if($res !== false) {
- $this->success('获取成功',$openidInfo);
- } else {
- $this->error('获取失败');
- }
- }
- /**
- * 微信小程序授权登录
- */
- public function wxMiniProgramLogin() {
- $openid = $this->request->request('openid');// openid值
- if (!$openid) {
- $this->error(__('Invalid parameters'));
- }
- // 用户登录逻辑 === 开始
- $user_sessionkey = Db::name('user_sessionkey')->where('openid',$openid)->find();
- $userInfo = Db::name('user')->where(['mini_openid'=>$user_sessionkey['openid']])->find();
- // 判断用户是否已经存在
- if($userInfo) { // 登录
- if ($userInfo['status'] == 0) {
- $this->error(__('Account is locked'));
- }
- if ($userInfo['status'] == 2) {
- $this->error('该用户已注销');
- }
- $update = [
- 'mini_openid' => $user_sessionkey['openid'],//已经有的不需要更新
- 'mini_sessionkey' => $user_sessionkey['sessionkey'],
- 'logintime' => time(),
- ];
- Db::name('user')->where('id',$userInfo['id'])->update($update);
- $res = $this->auth->direct($userInfo['id']);
- } else {
- //这里不在给注册,而是只能mobilelogin来注册
- $this->error('登录失败,请先使用手机号注册','',-1);
- }
- $userInfo = $this->getUserinfo('return');
- if($res) {
- if(empty($userInfo['mobile'])){
- $this->success("登录成功!",$userInfo,-1);
- }
- $this->success("登录成功!",$userInfo);
- } else {
- $this->error("登录失败!");
- }
- }
- /**
- * json 请求
- * @param $url
- * @return mixed
- */
- private function getJson($url){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $output = curl_exec($ch);
- curl_close($ch);
- return json_decode($output, true);
- }
- }
|