|
@@ -1,6 +1,7 @@
|
|
<?php
|
|
<?php
|
|
namespace app\api\controller;
|
|
namespace app\api\controller;
|
|
use app\common\controller\Api;
|
|
use app\common\controller\Api;
|
|
|
|
+use app\common\model\User as UserModel;
|
|
use app\common\model\UserRelation;
|
|
use app\common\model\UserRelation;
|
|
use app\common\model\User;
|
|
use app\common\model\User;
|
|
use liuniu\MiniProgramService;
|
|
use liuniu\MiniProgramService;
|
|
@@ -26,7 +27,7 @@ class MiniProgram extends Api
|
|
list($code, $post_cache_key, $login_type) = UtilService::postMore([
|
|
list($code, $post_cache_key, $login_type) = UtilService::postMore([
|
|
['code', ''],
|
|
['code', ''],
|
|
['cache_key', ''],
|
|
['cache_key', ''],
|
|
- ['login_type', '']
|
|
+ ['login_type', '2']
|
|
], $request, true);
|
|
], $request, true);
|
|
$session_key = cache('post_cache_key',$post_cache_key);
|
|
$session_key = cache('post_cache_key',$post_cache_key);
|
|
if (!$code && !$session_key)
|
|
if (!$code && !$session_key)
|
|
@@ -55,18 +56,37 @@ class MiniProgram extends Api
|
|
if ($e->getCode() == '-41003') $this->error('获取会话密匙失败');
|
|
if ($e->getCode() == '-41003') $this->error('获取会话密匙失败');
|
|
}
|
|
}
|
|
@file_put_contents("user.txt",json_encode($userInfo).'--'.json_encode($userInfoCong));
|
|
@file_put_contents("user.txt",json_encode($userInfo).'--'.json_encode($userInfoCong));
|
|
- if (!isset($userInfoCong['openid'])) $this->error('openid获取失败');
|
|
|
|
if (!isset($userInfo['unionId'])) $userInfo['unionId'] = '';
|
|
if (!isset($userInfo['unionId'])) $userInfo['unionId'] = '';
|
|
- $userInfo['openId'] = $userInfoCong['openid'];
|
|
+ if(!$userInfo['openId']) $userInfo['openId'] = $userInfoCong['openid'];
|
|
|
|
+ if(!$userInfo['openId']) $this->error('获取openId失败!');
|
|
$userInfo['spid'] = $data['spread_spid'];
|
|
$userInfo['spid'] = $data['spread_spid'];
|
|
$userInfo['code'] = $data['spread_code'];
|
|
$userInfo['code'] = $data['spread_code'];
|
|
|
|
+ $userInfo['openId'] = $userInfo['openId'];
|
|
|
|
+ $userInfo['unionid'] = $userInfo['unionId'];
|
|
$userInfo['session_key'] = $session_key;
|
|
$userInfo['session_key'] = $session_key;
|
|
$userInfo['login_type'] = $login_type;
|
|
$userInfo['login_type'] = $login_type;
|
|
|
|
+ if(isset($userInfo['unionId']) && $userInfo['unionId'] != '' && ($uid = UserRelation::where('unionid', $userInfo['unionId'])->where('login_type', '<>', 0)->value('user_id')))
|
|
|
|
+ {
|
|
|
|
+ UserRelation::where('user_id',$uid)->update($userInfo);
|
|
|
|
+ if (!UserRelation::where(['user_id' => $uid])->find()) {
|
|
|
|
+ $userInfo = UserRelation::where('user_id', $uid)->find();
|
|
|
|
+ UserModel::setRoutineUser($userInfo, 0);
|
|
|
|
+ } else {
|
|
|
|
+ if ($login_type) $userInfo['login_type'] = 3;
|
|
|
|
+ UserModel::updateWechatUser($userInfo, $data['spread_spid']);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ } else if ($uid = UserRelation::where(['openid' => $userInfo['openId']])->where('login_type', '<>', 0)->value('user_id')) {
|
|
|
|
+ UserRelation::where('user_id',$uid)->update($userInfo);
|
|
|
|
+ if ($login_type) $userInfo['login_type'] = $login_type;
|
|
|
|
+ UserModel::updateWechatUser($userInfo, $uid);
|
|
|
|
+ } else {
|
|
|
|
+ $userInfo['login_type'] = $login_type;
|
|
|
|
+ UserModel::setRoutineUser($userInfo, $data['spread_spid']);
|
|
|
|
+ }
|
|
$user = User::where('id', UserRelation::openidToUid($userInfo['openId'], 'routine_openid'))->find();
|
|
$user = User::where('id', UserRelation::openidToUid($userInfo['openId'], 'routine_openid'))->find();
|
|
if (!$user)
|
|
if (!$user)
|
|
$this->error('获取用户失败');
|
|
$this->error('获取用户失败');
|
|
-
|
|
|
|
$this->auth->direct($user['id']);
|
|
$this->auth->direct($user['id']);
|
|
return $this->success('登录成功', $this->auth->getUserinfo());
|
|
return $this->success('登录成功', $this->auth->getUserinfo());
|
|
|
|
|