|
@@ -12,13 +12,14 @@ use think\Validate;
|
|
|
use app\common\library\Token;
|
|
|
use think\Db;
|
|
|
use app\common\model\UserDeviceInfo;
|
|
|
+use onlogin\onlogin;
|
|
|
|
|
|
/**
|
|
|
* 会员接口,登录,注册,修改资料等
|
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
- protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
|
|
+ protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'onlogin'];
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
|
@@ -178,6 +179,74 @@ class User extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 运营商一键登录
|
|
|
+ */
|
|
|
+ public function onLogin()
|
|
|
+ {
|
|
|
+ $accessToken = input('accessToken');// 运营商预取号获取到的token
|
|
|
+ $token = input('tokenT');// 易盾返回的token
|
|
|
+ if (!$accessToken || !$token) {
|
|
|
+ $this->error("参数获取失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = array(
|
|
|
+ // 运营商预取号获取到的token
|
|
|
+ "accessToken" => $accessToken,
|
|
|
+ // 易盾返回的token
|
|
|
+ "token" => $token
|
|
|
+ );
|
|
|
+
|
|
|
+ // 获取密钥配置
|
|
|
+ $configInfo = config("onLogin");
|
|
|
+ $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
|
|
|
+
|
|
|
+ $onret = $onlogin->check($params);
|
|
|
+
|
|
|
+// $ret = [];
|
|
|
+// $ret["code"] = 200;
|
|
|
+// $ret["msg"] = "ok";
|
|
|
+// $ret["data"] = [
|
|
|
+// "phone" => "17574504021",
|
|
|
+// "resultCode" => 0
|
|
|
+// ];
|
|
|
+
|
|
|
+ if ($onret["code"] == 200) {
|
|
|
+ $mobile = $onret["data"]["phone"];
|
|
|
+ if (empty($mobile)) {
|
|
|
+ // 取号失败,建议进行二次验证,例如短信验证码
|
|
|
+ $this->error("取号登录失败,请用验证码方式登录!");
|
|
|
+ } else {
|
|
|
+ // 取号成功, 执行登录等流程
|
|
|
+ // 用户登录逻辑 === 开始
|
|
|
+
|
|
|
+ $user = \app\common\model\User::getByMobile($mobile);
|
|
|
+ if ($user) {
|
|
|
+ if ($user->status != 1) {
|
|
|
+ $this->error(__('Account is locked'));
|
|
|
+ }
|
|
|
+ //如果已经有账号则直接登录
|
|
|
+ $ret = $this->auth->direct($user->id);
|
|
|
+ $is_register = 0;
|
|
|
+ } else {
|
|
|
+ $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
|
|
|
+ $is_register = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //结果
|
|
|
+ $rs['userinfo'] = $this->auth->getUserinfo();
|
|
|
+ $rs['is_register'] = $is_register;
|
|
|
+ if ($ret) {
|
|
|
+ $this->success(__('Logged in successful'), $rs);
|
|
|
+ } else {
|
|
|
+ $this->error($this->auth->getError());
|
|
|
+ }
|
|
|
+ // 用户登录逻辑 === 结束
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->error("登录失败,请用验证码方式登录!");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//用户详细资料
|
|
|
public function userInfo($type = 1){
|
|
@@ -622,7 +691,7 @@ class User extends Api
|
|
|
$user->save();
|
|
|
|
|
|
Sms::flush($mobile, 'changemobile');
|
|
|
- $this->success();
|
|
|
+ $this->success('success',$this->userInfo('return'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -785,4 +854,7 @@ class User extends Api
|
|
|
//首页接口调用,这里不反回信息
|
|
|
// $this->success("更新成功!");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|