2018-12-28 18:58:37 +08:00
|
|
|
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | ShopXO 国内领先企业级B2C免费开源电商系统
|
|
|
|
// +----------------------------------------------------------------------
|
2021-03-16 10:34:52 +08:00
|
|
|
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
|
2018-12-28 18:58:37 +08:00
|
|
|
// +----------------------------------------------------------------------
|
2021-03-16 10:34:52 +08:00
|
|
|
// | Licensed ( https://opensource.org/licenses/mit-license.php )
|
2018-12-28 18:58:37 +08:00
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Author: Devil
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
2021-07-20 23:45:54 +08:00
|
|
|
use app\service\ApiService;
|
2021-04-11 15:51:06 +08:00
|
|
|
use app\service\SystemBaseService;
|
2019-01-17 00:37:20 +08:00
|
|
|
use app\service\UserService;
|
|
|
|
use app\service\OrderService;
|
|
|
|
use app\service\GoodsService;
|
|
|
|
use app\service\MessageService;
|
2019-07-03 21:03:28 +08:00
|
|
|
use app\service\AppCenterNavService;
|
2020-01-06 18:53:24 +08:00
|
|
|
use app\service\BuyService;
|
2020-07-03 23:18:46 +08:00
|
|
|
use app\service\GoodsFavorService;
|
|
|
|
use app\service\GoodsBrowseService;
|
|
|
|
use app\service\IntegralService;
|
2018-12-28 18:58:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-01T21:51:08+0800
|
|
|
|
*/
|
|
|
|
class User extends Common
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* [__construct 构造方法]
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-03T12:39:08+0800
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
// 调用父类前置方法
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-04 23:14:21 +08:00
|
|
|
* 用户登录
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
2018-12-28 18:58:37 +08:00
|
|
|
*/
|
2021-03-04 23:14:21 +08:00
|
|
|
public function Login()
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn(UserService::Login($this->data_post));
|
2021-03-04 23:14:21 +08:00
|
|
|
}
|
2018-12-28 18:58:37 +08:00
|
|
|
|
2021-03-04 23:14:21 +08:00
|
|
|
/**
|
|
|
|
* 用户登录-验证码发送
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function LoginVerifySend()
|
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn(UserService::LoginVerifySend($this->data_post));
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-04 23:14:21 +08:00
|
|
|
* 用户注册
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function Reg()
|
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn(UserService::Reg($this->data_post));
|
2021-03-04 23:14:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户注册-验证码发送
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
2018-12-28 18:58:37 +08:00
|
|
|
*/
|
|
|
|
public function RegVerifySend()
|
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn(UserService::RegVerifySend($this->data_post));
|
2021-03-04 23:14:21 +08:00
|
|
|
}
|
2018-12-28 18:58:37 +08:00
|
|
|
|
2021-03-04 23:14:21 +08:00
|
|
|
/**
|
|
|
|
* 密码找回
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function ForgetPwd()
|
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn(UserService::ForgetPwd($this->data_post));
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-04 23:14:21 +08:00
|
|
|
* 密码找回-验证码发送
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function ForgetPwdVerifySend()
|
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn(UserService::ForgetPwdVerifySend($this->data_post));
|
2021-03-04 23:14:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户-验证码显示
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function UserVerifyEntry()
|
|
|
|
{
|
|
|
|
$params = [
|
|
|
|
'width' => 100,
|
2021-04-28 14:33:03 +08:00
|
|
|
'height' => 28,
|
2021-03-04 23:14:21 +08:00
|
|
|
'key_prefix' => input('type', 'user_reg'),
|
|
|
|
];
|
|
|
|
$verify = new \base\Verify($params);
|
|
|
|
$verify->Entry();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* app用户手机绑定
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function AppMobileBind()
|
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn(UserService::AppMobileBind($this->data_post));
|
2021-03-04 23:14:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* app用户手机绑定-验证码发送
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function AppMobileBindVerifySend()
|
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn(UserService::AppMobileBindVerifySend($this->data_post));
|
2021-03-04 23:14:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 支付宝用户授权
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-04
|
|
|
|
* @desc description
|
2018-12-28 18:58:37 +08:00
|
|
|
*/
|
|
|
|
public function AlipayUserAuth()
|
|
|
|
{
|
|
|
|
// 参数
|
2021-07-20 23:45:54 +08:00
|
|
|
if(!empty($this->data_post['authcode']))
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 授权
|
|
|
|
$result = (new \base\Alipay())->GetAuthSessionKey(MyC('common_app_mini_alipay_appid'), $this->data_post['authcode']);
|
|
|
|
if($result['status'] == 0)
|
2021-05-19 15:10:00 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 先从数据库获取用户信息
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'alipay_openid', $result['data']['user_id']);
|
|
|
|
if(empty($user))
|
|
|
|
{
|
|
|
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['user_id']]);
|
|
|
|
} else {
|
|
|
|
// 用户状态
|
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
// 标记用户存在
|
|
|
|
$user['is_user_exist'] = 1;
|
|
|
|
$ret = DataReturn('授权登录成功', 0, $user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ret = DataReturn($result['msg'], -100);
|
2021-05-19 15:10:00 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
} else {
|
|
|
|
$ret = DataReturn('授权码为空', -1);
|
2019-06-28 16:18:04 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2019-06-28 16:18:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 支付宝小程序获取用户信息
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-11-06
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function AlipayUserInfo()
|
|
|
|
{
|
|
|
|
// 参数校验
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'openid',
|
|
|
|
'error_msg' => 'openid为空',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($this->data_post, $p);
|
2021-07-20 23:45:54 +08:00
|
|
|
if($ret === true)
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 先从数据库获取用户信息
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'alipay_openid', $this->data_post['openid']);
|
|
|
|
if(empty($user))
|
2021-05-19 15:10:00 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
$this->data_post['nickname'] = isset($this->data_post['nickName']) ? $this->data_post['nickName'] : '';
|
|
|
|
$this->data_post['gender'] = empty($this->data_post['gender']) ? 0 : (($this->data_post['gender'] == 'f') ? 1 : 2);
|
|
|
|
$ret = UserService::AuthUserProgram($this->data_post, 'alipay_openid');
|
|
|
|
} else {
|
|
|
|
// 用户状态
|
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
$ret = DataReturn('授权成功', 0, $user);
|
|
|
|
}
|
2021-05-19 15:10:00 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
} else {
|
|
|
|
$ret = DataReturn($ret, -1);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
2019-01-02 01:55:03 +08:00
|
|
|
/**
|
|
|
|
* 微信小程序获取用户授权
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-11-06
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function WechatUserAuth()
|
|
|
|
{
|
2019-03-02 23:17:30 +08:00
|
|
|
// 授权
|
2020-09-21 10:03:26 +08:00
|
|
|
$result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->GetAuthSessionKey($this->data_post);
|
|
|
|
if($result['status'] == 0)
|
2019-01-02 01:55:03 +08:00
|
|
|
{
|
2021-03-04 21:50:30 +08:00
|
|
|
// unionid
|
|
|
|
$unionid = empty($result['data']['unionid']) ? '' : $result['data']['unionid'];
|
|
|
|
|
2019-11-28 17:14:13 +08:00
|
|
|
// 先从数据库获取用户信息
|
2021-03-04 21:50:30 +08:00
|
|
|
$user = UserService::AppUserInfoHandle(null, 'weixin_openid', $result['data']['openid']);
|
|
|
|
if(empty($user) && !empty($unionid))
|
|
|
|
{
|
|
|
|
// 根据unionid获取数据
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'weixin_unionid', $unionid);
|
|
|
|
}
|
2019-11-28 17:14:13 +08:00
|
|
|
if(empty($user))
|
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['openid'], 'unionid'=>$unionid]);
|
2021-06-21 23:47:37 +08:00
|
|
|
} else {
|
|
|
|
// 如果用户openid为空则绑定到用户下面
|
|
|
|
if(empty($user['weixin_openid']))
|
|
|
|
{
|
2021-06-21 23:50:29 +08:00
|
|
|
if(UserService::UserOpenidBind($user['id'], $result['data']['openid'], 'weixin_openid'))
|
2021-06-21 23:47:37 +08:00
|
|
|
{
|
|
|
|
// 登录数据更新
|
2021-06-21 23:55:55 +08:00
|
|
|
$user = UserService::AppUserInfoHandle($user['id']);
|
2021-06-21 23:47:37 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-28 17:14:13 +08:00
|
|
|
}
|
2020-02-12 12:12:43 +08:00
|
|
|
|
2021-05-19 15:10:00 +08:00
|
|
|
// 用户状态
|
2021-07-20 23:45:54 +08:00
|
|
|
if(!empty($user))
|
2021-05-19 15:10:00 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
// 标记用户存在
|
|
|
|
$user['is_user_exist'] = 1;
|
|
|
|
$ret = DataReturn('授权登录成功', 0, $user);
|
|
|
|
}
|
2021-05-19 15:10:00 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
} else {
|
|
|
|
$ret = DataReturn($result['msg'], -10);
|
2019-01-02 01:55:03 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2019-01-02 01:55:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 微信小程序获取用户信息
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-11-06
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function WechatUserInfo()
|
|
|
|
{
|
2019-03-02 23:17:30 +08:00
|
|
|
// 参数校验
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'openid',
|
|
|
|
'error_msg' => 'openid为空',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
2021-03-04 21:50:30 +08:00
|
|
|
'key_name' => 'auth_data',
|
|
|
|
'error_msg' => '授权数据为空',
|
2019-03-02 23:17:30 +08:00
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($this->data_post, $p);
|
2021-07-20 23:45:54 +08:00
|
|
|
if($ret === true)
|
2019-01-02 01:55:03 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 先从数据库获取用户信息
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'weixin_openid', $this->data_post['openid']);
|
|
|
|
if(empty($user))
|
2021-05-19 15:10:00 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 字段名称不一样参数处理
|
|
|
|
$auth_data = is_array($this->data_post['auth_data']) ? $this->data_post['auth_data'] : json_decode(htmlspecialchars_decode($this->data_post['auth_data']), true);
|
|
|
|
$auth_data['nickname'] = isset($auth_data['nickName']) ? $auth_data['nickName'] : '';
|
|
|
|
$auth_data['avatar'] = isset($auth_data['avatarUrl']) ? $auth_data['avatarUrl'] : '';
|
|
|
|
$auth_data['gender'] = empty($auth_data['gender']) ? 0 : (($auth_data['gender'] == 2) ? 1 : 2);
|
|
|
|
|
|
|
|
// 公共参数处理
|
|
|
|
$auth_data['weixin_unionid'] = isset($this->data_post['unionid']) ? $this->data_post['unionid'] : '';
|
|
|
|
$auth_data['openid'] = $this->data_post['openid'];
|
|
|
|
$auth_data['referrer']= isset($this->data_post['referrer']) ? $this->data_post['referrer'] : 0;
|
|
|
|
$ret = UserService::AuthUserProgram($auth_data, 'weixin_openid');
|
|
|
|
} else {
|
|
|
|
// 用户状态
|
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
$ret = DataReturn('授权成功', 0, $user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ret = DataReturn($ret, -1);
|
2019-01-02 01:55:03 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2019-01-02 01:55:03 +08:00
|
|
|
}
|
|
|
|
|
2018-12-28 18:58:37 +08:00
|
|
|
/**
|
|
|
|
* 百度小程序获取用户信息
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-11-06
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function BaiduUserAuth()
|
|
|
|
{
|
2020-01-29 20:25:53 +08:00
|
|
|
$config = [
|
|
|
|
'appid' => MyC('common_app_mini_baidu_appid'),
|
|
|
|
'key' => MyC('common_app_mini_baidu_appkey'),
|
|
|
|
'secret' => MyC('common_app_mini_baidu_appsecret'),
|
|
|
|
];
|
|
|
|
$result = (new \base\Baidu($config))->GetAuthSessionKey($this->data_post);
|
2018-12-28 18:58:37 +08:00
|
|
|
if($result['status'] == 0)
|
|
|
|
{
|
2019-11-29 20:53:08 +08:00
|
|
|
// 先从数据库获取用户信息
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'baidu_openid', $result);
|
2021-07-20 23:45:54 +08:00
|
|
|
if(!empty($user))
|
2021-05-19 15:10:00 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 用户状态
|
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
// 标记用户存在
|
|
|
|
$user['is_user_exist'] = 1;
|
|
|
|
$ret = DataReturn('授权登录成功', 0, $user);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']]);
|
2021-05-19 15:10:00 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
} else {
|
|
|
|
$ret = DataReturn($result['msg'], -10);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
2019-11-29 20:53:08 +08:00
|
|
|
/**
|
|
|
|
* 百度小程序获取用户信息
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-11-06
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function BaiduUserInfo()
|
|
|
|
{
|
|
|
|
// 参数校验
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'openid',
|
|
|
|
'error_msg' => 'openid为空',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'encrypted_data',
|
|
|
|
'error_msg' => '解密数据为空',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'iv',
|
|
|
|
'error_msg' => 'iv为空,请重试',
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($this->data_post, $p);
|
2021-07-20 23:45:54 +08:00
|
|
|
if($ret === true)
|
2019-11-29 20:53:08 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 先从数据库获取用户信息
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'baidu_openid', $this->data_post['openid']);
|
|
|
|
if(empty($user))
|
2019-11-29 20:53:08 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
$config = [
|
|
|
|
'appid' => MyC('common_app_mini_baidu_appid'),
|
|
|
|
'key' => MyC('common_app_mini_baidu_appkey'),
|
|
|
|
'secret' => MyC('common_app_mini_baidu_appsecret'),
|
|
|
|
];
|
|
|
|
$result = (new \base\Baidu($config))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid']);
|
|
|
|
|
|
|
|
if($result['status'] == 0 && !empty($result['data']))
|
|
|
|
{
|
|
|
|
$result['nickname'] = isset($result['data']['nickname']) ? $result['data']['nickname'] : '';
|
|
|
|
$result['avatar'] = isset($result['data']['headimgurl']) ? $result['data']['headimgurl'] : '';
|
|
|
|
$result['gender'] = empty($result['data']['sex']) ? 0 : (($result['data']['sex'] == 2) ? 1 : 2);
|
|
|
|
$result['openid'] = $result['data']['openid'];
|
|
|
|
$result['referrer']= isset($this->data_post['referrer']) ? $this->data_post['referrer'] : 0;
|
|
|
|
$ret = UserService::AuthUserProgram($result, 'baidu_openid');
|
|
|
|
} else {
|
|
|
|
$ret = DataReturn($result['msg'], -1);
|
|
|
|
}
|
2020-01-07 15:32:47 +08:00
|
|
|
} else {
|
2021-07-20 23:45:54 +08:00
|
|
|
// 用户状态
|
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
$ret = DataReturn('授权成功', 0, $user);
|
|
|
|
}
|
2019-11-29 20:53:08 +08:00
|
|
|
}
|
|
|
|
} else {
|
2021-07-20 23:45:54 +08:00
|
|
|
$ret = DataReturn($ret, -1);
|
2019-11-29 20:53:08 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2019-11-29 20:53:08 +08:00
|
|
|
}
|
|
|
|
|
2019-10-27 10:00:12 +08:00
|
|
|
/**
|
|
|
|
* 头条小程序用户授权
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2019-10-27
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function ToutiaoUserAuth()
|
|
|
|
{
|
2020-01-28 18:11:30 +08:00
|
|
|
$config = [
|
2019-10-29 20:13:35 +08:00
|
|
|
'appid' => MyC('common_app_mini_toutiao_appid'),
|
|
|
|
'secret' => MyC('common_app_mini_toutiao_appsecret'),
|
2019-10-27 10:00:12 +08:00
|
|
|
];
|
2020-01-28 18:11:30 +08:00
|
|
|
$result = (new \base\Toutiao($config))->GetAuthSessionKey($this->data_post);
|
2019-10-27 10:00:12 +08:00
|
|
|
if($result['status'] == 0)
|
|
|
|
{
|
2019-12-02 11:36:44 +08:00
|
|
|
// 先从数据库获取用户信息
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'toutiao_openid', $result);
|
|
|
|
if(empty($user))
|
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']]);
|
|
|
|
} else {
|
|
|
|
// 用户状态
|
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
// 标记用户存在
|
|
|
|
$user['is_user_exist'] = 1;
|
|
|
|
$ret = DataReturn('授权登录成功', 0, $user);
|
|
|
|
}
|
2021-05-19 15:10:00 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
} else {
|
|
|
|
$ret = DataReturn($result['msg'], -10);
|
2019-10-27 10:00:12 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2019-10-27 10:00:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 头条小程序获取用户信息
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2019-10-27
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function ToutiaoUserInfo()
|
|
|
|
{
|
|
|
|
// 参数校验
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'openid',
|
|
|
|
'error_msg' => 'openid为空',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'userinfo',
|
|
|
|
'error_msg' => '用户信息为空',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($this->data_post, $p);
|
2021-07-20 23:45:54 +08:00
|
|
|
if($ret === true)
|
2019-10-27 10:00:12 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 先从数据库获取用户信息
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'toutiao_openid', $this->data_post['openid']);
|
|
|
|
if(empty($user))
|
2019-10-27 10:00:12 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
$result = json_decode(htmlspecialchars_decode($this->data_post['userinfo']), true);
|
|
|
|
if(is_array($result))
|
|
|
|
{
|
|
|
|
$result['nickname'] = isset($result['nickName']) ? $result['nickName'] : '';
|
|
|
|
$result['avatar'] = isset($result['avatarUrl']) ? $result['avatarUrl'] : '';
|
|
|
|
$result['gender'] = empty($result['gender']) ? 0 : (($result['gender'] == 2) ? 1 : 2);
|
|
|
|
$result['openid'] = $this->data_post['openid'];
|
|
|
|
$result['referrer']= isset($this->data_post['referrer']) ? $this->data_post['referrer'] : 0;
|
|
|
|
$ret = UserService::AuthUserProgram($result, 'toutiao_openid');
|
|
|
|
} else {
|
|
|
|
$ret = DataReturn(empty($result) ? '获取用户信息失败' : $result, -1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 用户状态
|
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
$ret = DataReturn('授权成功', 0, $user);
|
|
|
|
}
|
2019-10-27 10:00:12 +08:00
|
|
|
}
|
|
|
|
} else {
|
2021-07-20 23:45:54 +08:00
|
|
|
$ret = DataReturn($ret, -1);
|
2019-10-27 10:00:12 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2019-10-27 10:00:12 +08:00
|
|
|
}
|
|
|
|
|
2019-10-31 14:51:15 +08:00
|
|
|
/**
|
|
|
|
* QQ小程序获取用户授权
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2019-10-31
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function QQUserAuth()
|
|
|
|
{
|
|
|
|
// 参数
|
2021-07-20 23:45:54 +08:00
|
|
|
if(!empty($this->data_post['authcode']))
|
2019-10-31 14:51:15 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 授权
|
|
|
|
$result = (new \base\QQ(MyC('common_app_mini_qq_appid'), MyC('common_app_mini_qq_appsecret')))->GetAuthSessionKey($this->data_post['authcode']);
|
|
|
|
if($result !== false)
|
2019-12-01 00:37:54 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 先从数据库获取用户信息
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'qq_openid', $result);
|
|
|
|
if(empty($user))
|
|
|
|
{
|
|
|
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result]);
|
|
|
|
} else {
|
|
|
|
// 用户状态
|
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
// 标记用户存在
|
|
|
|
$user['is_user_exist'] = 1;
|
|
|
|
$ret = DataReturn('授权登录成功', 0, $user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ret = DataReturn('授权登录失败', -100);
|
2021-05-19 15:10:00 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
} else {
|
|
|
|
$ret = DataReturn('授权码为空', -1);
|
2019-10-31 14:51:15 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2019-10-31 14:51:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* QQ小程序获取用户信息
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2019-10-31
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public function QQUserInfo()
|
|
|
|
{
|
|
|
|
// 参数校验
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'openid',
|
|
|
|
'error_msg' => 'openid为空',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'encrypted_data',
|
|
|
|
'error_msg' => '解密数据为空',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'iv',
|
|
|
|
'error_msg' => 'iv为空,请重试',
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($this->data_post, $p);
|
2021-07-20 23:45:54 +08:00
|
|
|
if($ret === true)
|
2019-10-31 14:51:15 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 先从数据库获取用户信息
|
|
|
|
$user = UserService::AppUserInfoHandle(null, 'qq_openid', $this->data_post['openid']);
|
|
|
|
if(empty($user))
|
2019-10-31 14:51:15 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
$result = (new \base\QQ(MyC('common_app_mini_qq_appid'), MyC('common_app_mini_qq_appsecret')))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid']);
|
|
|
|
if(is_array($result))
|
|
|
|
{
|
|
|
|
$result['nickname'] = isset($result['nickName']) ? $result['nickName'] : '';
|
|
|
|
$result['avatar'] = isset($result['avatarUrl']) ? $result['avatarUrl'] : '';
|
|
|
|
$result['gender'] = empty($result['gender']) ? 0 : (($result['gender'] == 2) ? 1 : 2);
|
|
|
|
$result['qq_unionid'] = isset($result['unionId']) ? $result['unionId'] : '';
|
|
|
|
$result['openid'] = $result['openId'];
|
|
|
|
$result['referrer']= isset($this->data_post['referrer']) ? $this->data_post['referrer'] : 0;
|
|
|
|
$ret = UserService::AuthUserProgram($result, 'qq_openid');
|
|
|
|
} else {
|
|
|
|
$ret = DataReturn(empty($result) ? '获取用户信息失败' : $result, -1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 用户状态
|
|
|
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
|
|
|
if($ret['code'] == 0)
|
|
|
|
{
|
|
|
|
$ret = DataReturn('授权成功', 0, $user);
|
|
|
|
}
|
|
|
|
}
|
2019-10-31 14:51:15 +08:00
|
|
|
} else {
|
2021-07-20 23:45:54 +08:00
|
|
|
$ret = DataReturn($ret, -1);
|
2019-10-31 14:51:15 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2019-10-31 14:51:15 +08:00
|
|
|
}
|
|
|
|
|
2018-12-28 18:58:37 +08:00
|
|
|
/**
|
|
|
|
* [ClientCenter 用户中心]
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @datetime 2018-05-21T15:21:52+0800
|
|
|
|
*/
|
|
|
|
public function Center()
|
|
|
|
{
|
|
|
|
// 登录校验
|
2019-03-02 23:17:30 +08:00
|
|
|
$this->IsLogin();
|
2018-12-28 18:58:37 +08:00
|
|
|
|
|
|
|
// 订单总数
|
2019-01-10 11:49:18 +08:00
|
|
|
$where = ['user_id'=>$this->user['id'], 'is_delete_time'=>0, 'user_is_delete_time'=>0];
|
2018-12-28 18:58:37 +08:00
|
|
|
$user_order_count = OrderService::OrderTotal($where);
|
|
|
|
|
|
|
|
// 商品收藏总数
|
|
|
|
$where = ['user_id'=>$this->user['id']];
|
2020-07-03 23:18:46 +08:00
|
|
|
$user_goods_favor_count = GoodsFavorService::GoodsFavorTotal($where);
|
2018-12-28 18:58:37 +08:00
|
|
|
|
|
|
|
// 商品浏览总数
|
|
|
|
$where = ['user_id'=>$this->user['id']];
|
2020-07-03 23:18:46 +08:00
|
|
|
$user_goods_browse_count = GoodsBrowseService::GoodsBrowseTotal($where);
|
2018-12-28 18:58:37 +08:00
|
|
|
|
|
|
|
// 未读消息总数
|
2019-01-10 11:48:09 +08:00
|
|
|
$params = ['user'=>$this->user, 'is_more'=>1, 'is_read'=>0];
|
2018-12-28 18:58:37 +08:00
|
|
|
$common_message_total = MessageService::UserMessageTotal($params);
|
|
|
|
|
|
|
|
// 用户订单状态
|
2019-10-07 18:06:26 +08:00
|
|
|
$user_order_status = OrderService::OrderStatusStepTotal(['user_type'=>'user', 'user'=>$this->user, 'is_comments'=>1, 'is_aftersale'=>1]);
|
2018-12-28 18:58:37 +08:00
|
|
|
|
2020-07-03 23:18:46 +08:00
|
|
|
// 用户积分
|
2021-03-06 13:10:20 +08:00
|
|
|
$integral = IntegralService::UserIntegral($params['user']['id']);
|
|
|
|
$user_integral = (!empty($integral) && !empty($integral['integral'])) ? $integral['integral'] : 0;
|
2020-07-03 23:18:46 +08:00
|
|
|
|
2018-12-28 18:58:37 +08:00
|
|
|
// 初始化数据
|
|
|
|
$result = array(
|
2020-07-03 23:18:46 +08:00
|
|
|
'integral' => $user_integral,
|
2018-12-28 18:58:37 +08:00
|
|
|
'avatar' => $this->user['avatar'],
|
|
|
|
'nickname' => $this->user['nickname'],
|
|
|
|
'username' => $this->user['username'],
|
2020-12-06 13:28:34 +08:00
|
|
|
'user_name_view' => $this->user['user_name_view'],
|
2018-12-28 18:58:37 +08:00
|
|
|
'user_order_status' => $user_order_status['data'],
|
|
|
|
'user_order_count' => $user_order_count,
|
|
|
|
'user_goods_favor_count' => $user_goods_favor_count,
|
|
|
|
'user_goods_browse_count' => $user_goods_browse_count,
|
|
|
|
'common_message_total' => $common_message_total,
|
2019-07-03 21:03:28 +08:00
|
|
|
'navigation' => AppCenterNavService::AppCenterNav(),
|
2020-01-06 18:53:24 +08:00
|
|
|
'common_cart_total' => BuyService::UserCartTotal(['user'=>$this->user]),
|
2018-12-28 18:58:37 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
// 返回数据
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn(SystemBaseService::DataReturn($result));
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
2020-09-20 20:00:58 +08:00
|
|
|
|
|
|
|
/**
|
2020-09-21 10:03:26 +08:00
|
|
|
* 小程序用户手机一键绑定
|
2020-09-20 20:00:58 +08:00
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-09-20
|
|
|
|
* @desc description
|
|
|
|
*/
|
2020-09-21 10:03:26 +08:00
|
|
|
public function OnekeyUserMobileBind()
|
2020-09-20 20:00:58 +08:00
|
|
|
{
|
|
|
|
// 参数校验
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'openid',
|
|
|
|
'error_msg' => 'openid为空',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'encrypted_data',
|
|
|
|
'error_msg' => '解密数据为空',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'iv',
|
|
|
|
'error_msg' => 'iv为空,请重试',
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($this->data_post, $p);
|
2021-07-20 23:45:54 +08:00
|
|
|
if($ret === true)
|
2020-09-20 20:00:58 +08:00
|
|
|
{
|
2021-07-20 23:45:54 +08:00
|
|
|
// 根据不同平台处理数据解密逻辑
|
|
|
|
$mobile = '';
|
|
|
|
$error_msg = '';
|
|
|
|
switch(APPLICATION_CLIENT_TYPE)
|
|
|
|
{
|
|
|
|
// 微信
|
|
|
|
case 'weixin' :
|
|
|
|
$result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid']);
|
|
|
|
if($result['status'] == 0 && !empty($result['data']) && !empty($result['data']['purePhoneNumber']))
|
|
|
|
{
|
|
|
|
$mobile = $result['data']['purePhoneNumber'];
|
|
|
|
} else {
|
|
|
|
$error_msg = $result['msg'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// 百度
|
|
|
|
case 'baidu' :
|
|
|
|
$config = [
|
|
|
|
'appid' => MyC('common_app_mini_baidu_appid'),
|
|
|
|
'key' => MyC('common_app_mini_baidu_appkey'),
|
|
|
|
'secret' => MyC('common_app_mini_baidu_appsecret'),
|
|
|
|
];
|
|
|
|
$result = (new \base\Baidu($config))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid'], 'mobile_bind');
|
|
|
|
if($result['status'] == 0 && !empty($result['data']) && !empty($result['data']['mobile']))
|
|
|
|
{
|
|
|
|
$mobile = $result['data']['mobile'];
|
|
|
|
} else {
|
|
|
|
$error_msg = $result['msg'];
|
|
|
|
}
|
|
|
|
break;
|
2020-09-21 10:03:26 +08:00
|
|
|
|
2021-07-20 23:45:54 +08:00
|
|
|
// 默认
|
|
|
|
default :
|
|
|
|
$error_msg = APPLICATION_CLIENT_TYPE.'平台还未开发手机一键登录';
|
|
|
|
}
|
|
|
|
if(empty($mobile) || !empty($error_msg))
|
|
|
|
{
|
|
|
|
$ret = DataReturn(empty($error_msg) ? '数据解密失败' : $error_msg, -1);
|
|
|
|
} else {
|
|
|
|
// 用户信息处理
|
|
|
|
$this->data_post['mobile'] = $mobile;
|
|
|
|
$this->data_post['is_onekey_mobile_bind'] = 1;
|
|
|
|
$ret = UserService::AuthUserProgram($this->data_post, APPLICATION_CLIENT_TYPE.'_openid');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ret = DataReturn($ret, -1);
|
2020-09-20 23:26:30 +08:00
|
|
|
}
|
2021-07-20 23:45:54 +08:00
|
|
|
return ApiService::ApiDataReturn($ret);
|
2020-09-20 20:00:58 +08:00
|
|
|
}
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
?>
|