| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942 |
- <?php
- namespace App\Common\Services;
- use App\Exceptions\ApiException;
- use Illuminate\Support\Facades\Log;
- class UserCenterService
- {
- private $appCode;
- private $appKey;
- private $verKey;
- private $operationKey;
- private $url;
- public function __construct()
- {
- $config = config('api.user_center_config');
- $this->appCode = $config['app_code'];
- $this->appKey = $config['app_key'];
- $this->verKey = $config['ver_key'];
- $this->url = $config['url'];
- $this->operationKey = $config['operation_key'];
- //Log::info(json_encode($config));
- }
- /**
- * http请求
- * @param $method 请求方式 GET|POST|PUT|DELETE
- * @param $url 请求地址
- * @param array $params 请求参数
- * @param array $headers 请求带的header头
- * @return string 返回数据
- * @throws ApiException
- */
- public function request($method, $url, $params = [], $headers = [])
- {
- $headers['X-Requested-With'] = 'XMLHttpRequest';
- return httpClient($method, $url, $params, $headers);
- }
- /**
- * 登录
- * @param $username
- * @param $password
- * @param string $redirect
- * @param string $checkCode
- * @return array
- * @throws ApiException
- */
- public function pwdLogin($username, $password)
- {
- $ip = getClientIp(0, true);
- $res = $this->request('post', $this->url . 'app/user/login', [
- 'user_name' => $username,
- 'password' => $password,
- 'app_code' => $this->appCode,
- 'app_key' => $this->appKey,
- 'ip' => $ip
- ]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 是否返回成功
- * @param $res
- * @return bool
- */
- private function isSuccess($res)
- {
- if (!empty($res) && is_array($res) && $res['code'] == 0) {
- return true;
- }
- return false;
- }
- /**
- * 登出
- * @param $apiToken
- * @return boolean
- * @throws ApiException
- */
- public function logout($apiToken)
- {
- $res = $this->request('post', $this->url . 'app/user/logout', ['api_token' => $apiToken], ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 获取主帐号详情
- * @return mixed|string
- * @throws ApiException
- */
- public function getMasterSysUserInfo($apiToken)
- {
- $res = $this->request('post', $this->url . 'app/user/master-user-info', [], ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 获取帐号详情
- * @return mixed|string
- * @throws ApiException
- */
- public function getSysUserInfo($apiToken)
- {
- $res = $this->request('post', $this->url . 'app/user/base-info', [
- 'app_code' => $this->appCode
- ], ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 授权接口
- * @param $token
- * @return array
- * @throws ApiException
- */
- public function getAuth($apiToken)
- {
- $res = $this->request('post', $this->url . 'app/user/get-auth', [
- 'app_code' => $this->appCode,
- 'app_key' => $this->appKey
- ], ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 心跳接口
- * @param $apiToken
- * @return mixed|string
- * @throws ApiException
- */
- public function heartBeat($apiToken, $throwError = false)
- {
- $res = $this->request('post', $this->url . 'app/user/heart-beat', [], ['api-token' => $apiToken]);
- //file_put_contents(storage_path('logs/hearBeat.log'), $res."\r\n", FILE_APPEND);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 修改密码
- * @param integer $type 0 根据帐号 1根据手机 2根据旧邮箱
- * @param string $password 密码
- * @param string $confirm_password 确认密码
- * @param string $oldPassword 旧密码 类型(0)必填
- * @param string $validCode 验证码 类型(1、2)必填
- * @return mixed|string|array
- * @throws ApiException
- */
- public function updatePwd($type, $password, $confirm_password, $oldPassword = '', $validCode = '', $apiToken)
- {
- $res = $this->request('post', $this->url . 'app/user/update-pwd', [
- 'type' => $type,
- 'password' => $password,
- 'confirm_password' => $confirm_password,
- 'old_password' => $oldPassword,
- 'valid_code' => $validCode,
- ], ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 手机号查看用户是否存在
- * @param $phone
- * @return mixed
- * @throws ApiException
- */
- public function checkSysUserPhoneUnique($phone, $throwError = true)
- {
- $res = $this->request('post', $this->url . 'app/user/check-client-phone-unique', [
- 'phone' => $phone
- ]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- if ($throwError) {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- } else {
- //10012 手机号已被注册
- return $resData;
- }
- }
- }
- /**
- * 检查注册用户名是否存在 暂时不开发用户名注册
- * @param $phone
- * @return mixed
- * @throws ApiException
- */
- public function checkSysUserUserNameUnique($userName, $throwError = true)
- {
- $res = $this->request('post', $this->url . 'app/user/check-client-user-name-unique', [
- 'user_name' => $userName
- ]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- if ($throwError) {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- } else {
- return $resData;
- }
- }
- }
- /**
- * 检查注册邮箱是否存在
- * @param $phone
- * @return mixed
- * @throws ApiException
- */
- public function checkSysUserEmailUnique($email, $throwError = true)
- {
- $res = $this->request('post', $this->url . 'app/user/check-client-email-unique', [
- 'email' => $email
- ]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- if ($throwError) {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- } else {
- //10014 邮箱已被注册
- return $resData;
- }
- }
- }
- /**
- * 检查帐号是否为主帐号
- * @param $phone
- * @return mixed
- * @throws ApiException
- */
- public function checkSysUserIsMaster($params, $throwError = true)
- {
- $checkData = [];
- if (!empty($params['user_name'])) {
- $checkData['user_name'] = $params['user_name'];
- }
- if (!empty($params['email'])) {
- $checkData['email'] = $params['email'];
- }
- if (!empty($params['phone'])) {
- $checkData['phone'] = $params['phone'];
- }
- $res = $this->request('post', $this->url . 'app/user/check-client-user-is-master', $checkData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- if ($throwError) {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- } else {
- return $resData;
- }
- }
- }
- /**
- * 获取短信验证码
- * @param $phone
- * @param $type
- * @return mixed
- * @throws ApiException
- */
- public function getSmsCode($phone,$countryCode, $type = 0)
- {
- $res = $this->request('get', $this->url . 'common/get-sms-code', [
- 'phone' => $phone,
- 'type' => $type,
- 'country_code' => $countryCode,
- ]);
- // $res = '{"code":0,"message":"","data":1}';
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 获取短信验证码
- * @param $email
- * @return mixed
- * @throws ApiException
- */
- public function getEmailCode($email,$language='zh-cn',$footer='')
- {
- $res = $this->request('get', $this->url . 'common/get-email-code', [
- 'email' => $email,
- 'language' => $language,
- 'footer' => $footer,
- ]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- if($resData['code']==10021) {
- throw new ApiException('common.email_empty', '邮箱不能为空');
- }
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 登录
- * @param $username
- * @param $password
- * @param string $redirect
- * @param string $checkCode
- * @return array ['status'=>1,'redirect'=>'']
- * @throws ApiException
- */
- public function phoneLogin($phone, $validCode,$countryCode=86)
- {
- $ip = getClientIp(0, true);
- $res = $this->request('post', $this->url . 'app/user/phone-login', [
- 'phone' => $phone,
- 'valid_code' => $validCode,
- 'country_code' => $countryCode,
- 'app_code' => $this->appCode,
- 'app_key' => $this->appKey,
- 'ip' => $ip
- ]);
- // $res = '{"code":0,"message":"","data":{"api_token":"d3506997fe83325eb0cca61de31737d8","is_admin":1,"expire":604800,"nick_name":"李肖明","user_name":"lixming","real_name":"","company_id":10327,"invalid_time":"2028-04-15 23:59:59"}}';
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 获取子帐号
- * @param $companyId
- * @return array
- * @throws ApiException
- */
- public function getSysUserSubUser($keyword, $apiToken)
- {
- $res = $this->request('post', $this->url . 'app/user/get-client-sub-user', ['keyword' => $keyword], ['api-token' => $apiToken]);
- //file_put_contents(storage_path('logs/aaa.log'), $res."\r\n", FILE_APPEND);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 修改子帐号
- * @param array $params id nick_name password real_name status
- * @param $apiToken
- * @return array
- * @throws ApiException
- */
- public function updateSubAccount($params = [], $apiToken)
- {
- $res = $this->request('post', $this->url . 'app/user/update-sub-account', $params, ['api-token' => $apiToken]);
- //file_put_contents(storage_path('logs/aaa.log'), $res."\r\n", FILE_APPEND);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 删除
- * @param integer $sysUserId 用户中心id
- * @return array
- * @throws ApiException
- */
- public function delSubAccount($sysUserId, $apiToken)
- {
- $res = $this->request('post', $this->url . 'app/user/del-sub-account', ['id' => $sysUserId], ['api-token' => $apiToken]);
- //file_put_contents(storage_path('logs/aaa.log'), $res."\r\n", FILE_APPEND);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 添加子账号
- * @param array params 子帐号参数
- * @param array params.user_name 帐号
- * @param array params.nick_name 昵称
- * @param array params.password 密码
- * @return array
- * @throws ApiException
- */
- public function addSubAccount($params = [], $apiToken)
- {
- $subAccountData = [];
- $subAccountData['user_name'] = $params['user_name'];
- $subAccountData['nick_name'] = !empty($params['nick_name']) ? $params['nick_name'] : '';
- $subAccountData['password'] = $params['password'];
- $res = $this->request('post', $this->url . 'app/user/add-sub-account', $subAccountData, ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 注册用户
- * @param array params 注册用户参数
- * @param string params.password 密码
- * @param string params.confirm_password 确认密码
- * @param string params.phone 手机
- * @param string params.email 邮箱
- * @param string params.valid_code 验证码
- * @param string params.nick_name 昵称
- * @param string params.app_code 应用code
- * @param string params.app_key 应用key
- * @param string params.ver_Key 应用版本
- * @param integer params.auto_login 自动登录
- * */
- public function registerSysUser($params)
- {
- $nowTime = nowTime();
- $registerData = [];
- if (!empty($params['password'])) {
- $registerData['password'] = $params['password'];
- }
- if (!empty($params['confirm_password'])) {
- $registerData['confirm_password'] = $params['confirm_password'];
- }
- if (!empty($params['phone'])) {
- $registerData['phone'] = $params['phone'];
- }
- if (!empty($params['email'])) {
- $registerData['email'] = $params['email'];
- }
- if (!empty($params['valid_code'])) {
- $registerData['valid_code'] = $params['valid_code'];
- }
- if (!empty($params['nick_name'])) {
- $registerData['nick_name'] = $params['nick_name'];
- }
- if (isset($params['auto_login'])) {
- $registerData['auto_login'] = empty($params['auto_login']) ? 0 : $params['auto_login'];
- }
- $registerData['app_code'] = $this->appCode;
- $registerData['app_key'] = $this->appKey;
- $registerData['ver_Key'] = $this->verKey;
- $registerData['start_time'] = $nowTime;
- $registerData['end_time'] = '2099-12-31 23:59:59';
- $res = $this->request('post', $this->url . 'app/user/register', $registerData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 忘记密码 获取重置密码的token
- * @param array params 获取重置密码的token
- * @param integer params.type 类型 1手机 2邮箱
- * @param integer params.valid_code 验证码
- * @param string params.email 邮箱
- * @param string params.phone 手机
- * */
- public function getResetPwdToken($params)
- {
- $resetParams = [];
- $resetParams['type'] = $params['type'];
- $resetParams['valid_code'] = $params['valid_code'];
- if (!empty($params['email'])) {
- $resetParams['email'] = $params['email'];
- }
- if (!empty($params['phone'])) {
- $resetParams['phone'] = $params['phone'];
- }
- $res = $this->request('post', $this->url . 'app/user/reset-pwd-validate', $resetParams);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 根据reset_token 重置密码
- * @param string password 密码
- * @param string confirm_password 确认密码
- * @param string reset_token 重置tokem
- * */
- public function resetPasswordByToken($params)
- {
- $resetParams = [];
- $resetParams['password'] = $params['password'];
- $resetParams['confirm_password'] = $params['confirm_password'];
- $resetParams['reset_token'] = $params['reset_token'];
- $res = $this->request('post', $this->url . 'app/user/reset-pwd', $resetParams);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 绑定应用
- * @param string apiToken
- * */
- public function appBind($apiToken)
- {
- $nowTime = nowTime();
- $bindData = [];
- $bindData['app_code'] = $this->appCode;
- $bindData['app_key'] = $this->appKey;
- $bindData['ver_key'] = $this->verKey;
- $bindData['start_time'] = $nowTime;
- $bindData['end_time'] = '2099-12-31 23:59:59';
- $res = $this->request('post', $this->url . 'app/user/app-bind', $bindData, ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 绑定应用
- * @param string apiToken
- * */
- public function appBindById($params)
- {
- $bindData = [];
- $bindData['app_code'] = $params['app_code'];
- $bindData['app_key'] = $params['app_key'];
- $bindData['ver_key'] = $params['ver_key'];
- $bindData['start_time'] = $params['start_time'];;
- $bindData['end_time'] = $params['end_time'];;
- $bindData['user_id'] = $params['user_id'];;
- $bindData['operation_key'] = $this->operationKey;
- $res = $this->request('post', $this->url . 'app/user/app-bind-by-id', $bindData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 绑定应用
- * @param string apiToken
- * */
- public function appBindUp($params,$throw=true)
- {
- $bindData = [];
- $bindData['app_code'] = $this->appCode;
- $bindData['app_key'] = $this->appKey;
- $verKey=$params['ver_key'];
- $bindData['ver_key'] = $verKey;
- $bindData['bind_type'] =$params['bind_type'];//bind_type 绑定类型 0 新增 1续费 2升级 3降级
- $bindData['user_id'] =$params['user_id'];//bind_type 绑定类型 0 新增 1续费 2升级 3降级
- $bindData['operation_key'] = $this->operationKey;
- if(isset($params['start_time'])){
- $bindData['start_time'] = $params['start_time'];
- }
- if(isset($params['end_time'])){
- $bindData['end_time'] = $params['end_time'];
- }
- $res = $this->request('post', $this->url . 'app/user/manage-up-app-bind', $bindData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- if($throw){
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }else{
- return false;
- }
- }
- }
- /**
- * 绑定应用
- * @param string apiToken
- * */
- public function addExpandPacket($params)
- {
- $bindData = [];
- $bindData['app_code'] = $this->appCode;
- $bindData['app_key'] = $this->appKey;
- $bindData['packet_key'] = $params['packet_key'];
- $bindData['start_time'] =$params['start_time'];
- $bindData['user_id'] =$params['user_id'];
- $bindData['operation_key'] = $this->operationKey;
- $res = $this->request('post', $this->url . 'app/user/add-expand-packet', $bindData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 变更绑定手机获取变更绑定的reset_token
- * @param array params 获取重置密码的token
- * @param integer params.type 类型 1当前手机 2邮箱
- * @param string params.valid_code 验证码
- * */
- public function getBindPhoneResetToken($params, $apiToken)
- {
- $resetParams = [];
- $resetParams['type'] = $params['type'];
- $resetParams['valid_code'] = $params['valid_code'];
- $res = $this->request('post', $this->url . 'app/user/get-bind-phone-reset-token', $resetParams, ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 绑定手机
- * @param array params 获取重置密码的token
- * @param integer params.type 类型 1手机 2邮箱
- * @param string params.valid_code 验证码
- * */
- public function userPhoneBind($params, $apiToken)
- {
- $resetParams = [];
- $resetParams['phone'] = $params['phone'];
- $resetParams['valid_code'] = $params['valid_code'];
- if (isset($params['reset_token'])) {
- $resetParams['reset_token'] = $params['reset_token'];
- }
- $res = $this->request('post', $this->url . 'app/user/bind-phone', $resetParams, ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 变更绑定邮箱获取变更绑定的reset_token
- * @param array params 获取重置密码的token
- * @param integer params.type 类型 1当前手机 2邮箱
- * @param string params.valid_code 验证码
- * */
- public function getBindEmailResetToken($params, $apiToken)
- {
- $resetParams = [];
- $resetParams['type'] = $params['type'];
- $resetParams['valid_code'] = $params['valid_code'];
- $res = $this->request('post', $this->url . 'app/user/get-bind-email-reset-token', $resetParams, ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 绑定邮箱
- * @param array params 获取重置密码的token
- * @param integer params.type 类型 1当前手机 2邮箱
- * @param string params.valid_code 验证码
- * */
- public function userEmailBind($params, $apiToken)
- {
- $resetParams = [];
- $resetParams['email'] = $params['email'];
- $resetParams['valid_code'] = $params['valid_code'];
- if (isset($params['reset_token'])) {
- $resetParams['reset_token'] = $params['reset_token'];
- }
- $res = $this->request('post', $this->url . 'app/user/bind-email', $resetParams, ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 子帐号修改密码
- * */
- public function subAccountUpdatePwd($params, $apiToken)
- {
- $updateParams = [];
- $updateParams['password'] = $params['password'];
- $updateParams['confirm_password'] = $params['confirm_password'];
- $updateParams['old_password'] = $params['old_password'];
- $res = $this->request('post', $this->url . 'app/user/sub-account-update-pwd', $updateParams, ['api-token' => $apiToken]);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 注册用户
- * @param array params 注册用户参数
- * @param string params.password 密码
- * @param string params.confirm_password 确认密码
- * @param string params.phone 手机
- * @param string params.email 邮箱
- * @param string params.valid_code 验证码
- * @param string params.nick_name 昵称
- * @param string params.app_code 应用code
- * @param string params.app_key 应用key
- * @param string params.ver_Key 应用版本
- * @param integer params.auto_login 自动登录
- * */
- public function preRegister($params)
- {
- $nowTime = nowTime();
- $registerData = [];
- if (!empty($params['phone'])) {
- $registerData['phone'] = $params['phone'];
- $registerData['country_code'] = empty($params['country_code'])?'86':$params['country_code'];
- }
- if (!empty($params['email'])) {
- $registerData['email'] = $params['email'];
- }
- if (!empty($params['valid_code'])) {
- $registerData['valid_code'] = $params['valid_code'];
- }
- $registerData['app_code'] = $this->appCode;
- $registerData['app_key'] = $this->appKey;
- $registerData['ver_Key'] = $this->verKey;
- $registerData['start_time'] = $nowTime;
- $registerData['end_time'] = '2099-12-31 23:59:59';
- $res = $this->request('post', $this->url . 'app/user/pre-register', $registerData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 确认注册
- * */
- public function confirmRegister($params){
- $confirmParams = [];
- $confirmParams['password'] = $params['password'];
- $confirmParams['confirm_password'] = $params['confirm_password'];
- $confirmParams['pre_register_key'] = $params['pre_register_key'];
- if (!empty($params['auto_login'])) {
- //是否自动登陆
- $confirmParams['auto_login'] = $params['auto_login'];
- }
- $res = $this->request('post', $this->url . 'app/user/confirm-register', $confirmParams);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 更新用户数值权限使用量
- * @return mixed
- * @throws ApiException
- * */
- public function updateBindUse($params){
- $updateBindData = [];
- $updateBindData['app_code'] = $this->appCode;
- $updateBindData['app_key'] = $this->appKey;
- $updateBindData['operation_key'] = $this->operationKey;
- $updateBindData['type_numerical_key'] = $params['type_numerical_key'];
- $updateBindData['user_id'] = $params['user_id'];
- $updateBindData['update_value'] = $params['update_value'];
- $res = $this->request('post', $this->url . 'app/user/update-bind-use', $updateBindData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 获取用户数值权限使用量
- * */
- public function getBindUse($params){
- $updateBindData = [];
- $updateBindData['app_code'] = $this->appCode;
- $updateBindData['app_key'] = $this->appKey;
- $updateBindData['operation_key'] = $this->operationKey;
- $updateBindData['user_id'] = $params['user_id'];
- $updateBindData['type_numerical_key'] = empty($params['type_numerical_key'])?'':$params['type_numerical_key'];
- $res = $this->request('post', $this->url . 'app/user/get-bind-use', $updateBindData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 获取用户已绑定(开通)应用
- * @param string apiToken
- * */
- public function getBindAppList($userId)
- {
- $bindData = [];
- $bindData['app_code'] = $this->appCode;
- $bindData['user_id'] =$userId;
- $bindData['operation_key'] = $this->operationKey;
- $res = $this->request('post', $this->url . 'app/user/get-bind-app-list', $bindData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- /**
- * 获取应用的版本列表
- * */
- public function getAppVerList()
- {
- $bindData = [];
- $bindData['app_code'] = $this->appCode;
- $bindData['operation_key'] = $this->operationKey;
- $res = $this->request('post', $this->url . 'app/user/get-app-ver-list', $bindData);
- $resData = json_decode($res, true);
- if ($this->isSuccess($resData)) {
- return $resData['data'];
- } else {
- $message = empty($resData['message']) ? '' : $resData['message'];
- throw new ApiException(1004,['msg'=> $message]);
- }
- }
- }
|