request->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['mobile', 'captcha', 'password'], 'required'], ['mobile', 'match', 'pattern' => '/[0-9]+$/', 'message' => '请输入正确的手机号码'], [['mobile'], 'integer'], ['password', 'string', 'length' => [6, 11]], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); //短信验证码 if (YII_ENV == 'prod') { if (!Sms::checkValidateCode($params['mobile'], $params['captcha'],Sms::SMS_TYPE_UPDATE_PASS)) return $this->error('验证码不正确'); } $user = User::findOne(['mobile'=>$params['mobile'],'mall_id'=>$this->mall_id,'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]); if(empty($user)) return $this->error('此手机号未注册'); if(empty($user->status)) return $this->error('此手机号被禁用'); $user->password = Yii::$app->getSecurity()->generatePasswordHash(trim($params['password'])); if ($user->save() === false) return $this->error(User::getStaticError()); return $this->success('设置成功'); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * h5注册 * @return \yii\web\Response */ public function actionRegister() { try { if (\Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $mall_id = $this->mall_id; $res = Yii::$app->services->validate->validate($params, [ [['mobile', 'password', 'confirm_password'], 'required'], [['captcha'], 'safe'], ['mobile', 'match', 'pattern' => '/[0-9]+$/', 'message' => '请输入正确的手机号码'], ['invite_mobile', 'match', 'pattern' => '/[0-9]+$/', 'message' => '请输入正确的推荐人手机号码'], ['password', 'string', 'length' => [6, 11]], ['password', 'match', 'pattern' => '/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]+$/', 'message' => '密码必须是字母加数字'], ['confirm_password', 'compare', 'compareAttribute' => 'password', 'message' => '两次密码不一致'], [['nickname'], 'string'], ['mobile', function ($attribute) use ($mall_id) { $where[] = ['mall_id' => $mall_id]; $where[] = ['or', ['mobile' => trim($this->$attribute)], ['username' => trim($this->$attribute)]]; if (User::getUser($where)) $this->addError($attribute, '手机号码已存在'); }], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 获取公共配置 $basic = Yii::$app->services->setting->mall->get($this->mall_id, 'basic'); $basic['is_write_name'] = !isset($basic['is_write_name']) ? 0 : $basic['is_write_name']; // 要不要强制填写昵称 if ($basic['is_write_name']) { // 要 if (empty($params['nickname'])) { return $this->error('昵称不能为空'); } } else { // 不要 $params['nickname'] = '游客' . substr(time(), -4) . mt_rand(100, 999); } $mall_setting = Yii::$app->services->setting->mall->get($mall_id, 'user'); $check_sms_code_value = $mall_setting['check_sms_code'] ?? 1; if(empty($params['captcha']) && $check_sms_code_value) return $this->error('请输入验证码'); //短信验证码 开启验证码注册才检查 if (YII_ENV == 'prod' && $check_sms_code_value) { //短信验证码 if (!Sms::checkValidateCode($params['mobile'], $params['captcha'],Sms::SMS_TYPE_REGISTER)) return $this->error('验证码不正确'); } $params['mall_id'] = $this->mall_id; $params['username'] = $params['mobile']; $params['parent_id'] = $this->parent_id; $params['password'] = Yii::$app->getSecurity()->generatePasswordHash($params['password']); $params['source'] = empty($this->source) ? User::SOURCE_SHARE_INDEX : $this->source; $params['platform'] = User::PLATFORM_H5; $res = User::setData($params); if ($res === false) return $this->error(User::getStaticError()); // 触发注册成功事件,事务提交完成后触发 $event = new UserRegisterEvent($this->mall_id); $data = ['user_id' => $res->id, 'platform' => 'h5']; Yii::$app->services->events->dispatch($event, $data, $event->listeners); return $this->success('注册成功'); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * h5登录 * @return mixed|void */ public function actionLogin() { try { if (Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['username'], 'required'], [['captcha', 'password', 'device_type', 'device_mac'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $user = User::loginByH5($params); if ($user === false) return $this->error(User::getStaticError()); $token = Yii::$app->services->apiAccessToken->getAccessToken($user, 'api'); // 触发登录成功事件,事务提交完成后触发 $event = new UserLoginEvent($this->mall_id); Yii::$app->services->events->dispatch($event, [ 'mall_id' => $this->mall_id, 'nickname' => $user->nickname, 'user_id' => $user->id, 'platform' => 'h5', 'ip' => ArrayHelper::get_client_ip(), 'device_type' => $params['device_type'] ?? '', 'device_mac' => $params['device_mac'] ?? '', ], $event->listeners); return $this->success('登录成功', $token); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 登出 * * @return array|mixed */ public function actionLogout() { if (Yii::$app->services->apiAccessToken->disableByAccessToken(Yii::$app->user->identity->access_token)) return $this->success('退出成功'); return $this->error('退出失败'); } /** * 权限验证 * * @param string $action 当前的方法 * @param null $model 当前的模型类 * @param array $params $_GET变量 * @throws \yii\web\BadRequestHttpException */ public function checkAccess($action, $model = null, $params = []) { // 方法名称 if (in_array($action, ['index', 'view', 'update', 'create', 'delete'])) { throw new \yii\web\BadRequestHttpException('权限不足'); } } /** * 获取注册短信验证码 * @return mixed|void * @throws \Overtrue\EasySms\Exceptions\NoGatewayAvailableException */ public function actionRegisterSmsCode() { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['mobile'], 'required', 'message' => '请输入手机号码'], [['mobile','area_code'], 'integer'], [['sms_type'], 'string'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $area_code = '';// 初始化区号 $gateways = 'domestic';// 默认国内短信 // 检测是登录并且区号不为空则使用国际短信 if (!empty($this->user) && !empty($this->user->area_code)&&$this->user->area_code!=86) { $gateways = 'international'; $area_code = $this->user->area_code; } // 判断是否有区号 if (!empty($params['area_code']) && $params['area_code'] != 86) { $gateways = 'international'; $area_code = $params['area_code']; } $notice_sms_status = \Yii::$app->services->setting->mall->get($this->mall_id, 'notice_sms.status'); if(empty($notice_sms_status)) return $this->error('短信提醒未开启'); //$params['sms_type'] = $params['sms_type'] ?: 'register'; $params['sms_type'] = $params['sms_type'] ?: ''; $sms = new Sms($this->mall_id, $gateways); try { if ($sms->sendCaptcha($params['mobile'], $area_code,$params['sms_type']) === false) return $this->error('发送失败'); }catch (\Exception $e){ return $this->error($e->getMessage()); } return $this->success('发送成功'); } /** * @desc:授权登录 * @Author: hua * @Date: 2021/10/22 * @Time: 16:51 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionAuthLogin() { return $this->_handleAuth('weixin'); // $requests = Yii::$app->request; // $wechat_form = new WechatForm(['mall_id'=>$this->mall_id]); // $params_data = @file_get_contents('php://input'); // if (!empty($params_data)) $json_data = json_decode($params_data, true); // $params = array_merge($requests->get(), $requests->post(), $json_data ?? []); // $res = Yii::$app->services->validate->validate($params, [ // [['code', 'encryptedData', 'iv', 'key'], 'string'], // [['user_id', 'activity_id', 'share_user_id'], "integer"] // ]); // if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // $params['mall_id'] = $this->mall_id; // $params['source'] = empty($this->source) ? User::SOURCE_SHARE_INDEX : $this->source; // $result = $wechat_form->authorized($params); // if ($result === false) return $this->error($wechat_form::getStaticError()); // return $this->success('成功', $result); } /** * @desc:小程序授权登录 * @Author: hua * @Date: 2021/10/22 * @Time: 9:37 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionMiniLogin() { return $this->_handleAuth('mp-weixin'); // $requests = Yii::$app->request; // $wechat_form = new WechatForm(['mall_id'=>$this->mall_id]); // $params_data = @file_get_contents('php://input'); // if (!empty($params_data)) $json_data = json_decode($params_data, true); // $params = array_merge($requests->get(), $requests->post(), $json_data ?? []); // $res = Yii::$app->services->validate->validate($params, [ // [['code', 'encryptedData', 'iv', 'key'], 'string'], // [['user_id', 'activity_id', 'share_user_id'], "integer"] // ]); // if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // $params['mall_id'] = $this->mall_id; // $params['source'] = empty($this->source) ? User::SOURCE_SHARE_INDEX : $this->source; // $result = $wechat_form->miniAuthorized($params); // if ($result === false) return $this->error($wechat_form::getStaticError()); // return $this->success('成功', $result); } /** * app端微信授权登录 * @Author: zal * @Date: 2020-12-24 * @Time: 17:33 * @return array * @throws \Exception */ public function actionAppAuthLogin() { return $this->_handleAuth('app-weixin'); // $requests = Yii::$app->request; // $wechat_form = new WechatForm(['mall_id'=>$this->mall_id]); // $params_data = @file_get_contents('php://input'); // if (!empty($params_data)) $json_data = json_decode($params_data, true); // $params = array_merge($requests->get(), $requests->post(), $json_data ?? []); // $res = Yii::$app->services->validate->validate($params, [ // [['userData'], 'string'], // [['user_id', 'activity_id', 'share_user_id'], "integer"], // ]); // if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // $params['mall_id'] = $this->mall_id; // $params['user_id'] = $this->user_id; // $params['source'] = empty($this->source) ? User::SOURCE_SHARE_INDEX : $this->source; // $result = $wechat_form->appAuthLogin($params); // if ($result === false) return $this->error($wechat_form::getStaticError()); // return $this->success('成功', $result); } /** * 授权处理 * @Author bing * @DateTime 2021-12-08 10:50:35 * @copyright: Copyright (c) 2020 广东七件事集团 * @return mixed/void * @param $scene */ private function _handleAuth($scene){ $requests = Yii::$app->request; $params_data = @file_get_contents('php://input'); if (!empty($params_data)) $json_data = json_decode($params_data, true); $params = array_merge($requests->get(), $requests->post(), $json_data ?? []); $rules = [ [['code', 'encryptedData', 'iv', 'key'], 'string'], [['user_id', 'activity_id', 'share_user_id'], "integer"], [['device_type', 'device_mac'], 'safe'], ]; switch($scene){ case 'weixin' : $method = 'authorized'; break; case 'mp-weixin' : $method = 'miniAuthorized'; break; case 'app-weixin' : $rules = [ [['userData'], 'string'], [['user_id', 'activity_id', 'share_user_id'], "integer"], [['platform'], "string"], ]; $params['user_id'] = $this->user_id; $method = 'appAuthLogin'; break; } $res = Yii::$app->services->validate->validate($params,$rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $params['source'] = empty($this->source) ? User::SOURCE_SHARE_INDEX : $this->source; $wechat_form = new WechatForm(['mall_id'=>$this->mall_id]); $result = $wechat_form->$method($params); if ($result === false){ $is_log_off_del = \Yii::$app->services->setting->mall->get($this->mall_id, 'user.is_log_off_del'); if (!empty($is_log_off_del)) { if($wechat_form::getStaticError()=='账号已注销'){ return $this->success($wechat_form::getStaticError()); } } return $this->error($wechat_form::getStaticError()); } if(isset($result['user_id'])) unset($result['user_id']); return $this->success('操作成功', $result); } /** * @desc:小程序授权手机号 * @Author: hua * @Date: 2021/10/22 * @Time: 14:20 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionAuthPhone() { return $this->_handleBindMobile('mp_weixin'); // $requests = Yii::$app->request; // $wechat_form = new WechatForm(['mall_id'=>$this->mall_id]); // $params_data = @file_get_contents('php://input'); // if (!empty($params_data)) $json_data = json_decode($params_data, true); // $params = array_merge($requests->get(), $requests->post(), $json_data ?? []); // $res = Yii::$app->services->validate->validate($params, [ // [['code', 'encryptedData', 'iv', 'key'], 'string'], // [['user_id', 'activity_id', 'share_user_id'], "integer"] // ]); // if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // $params['mall_id'] = $this->mall_id; // $params['user_id'] = $this->user_id; // $params['parent_id'] = $this->parent_id; // $params['source'] = empty($this->source) ? User::SOURCE_SHARE_INDEX : $this->source; // $result = $wechat_form->authorizedMobilePhone($params); // if ($result === false) return $this->error($wechat_form::getStaticError()); // return $this->success('成功', $result); } /** * @desc:绑定绑定手机号码 * @Author: hua * @Date: 2021/10/22 * @Time: 14:32 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed */ public function actionBind() { return $this->_handleBindMobile(); // $requests = Yii::$app->request; // $params =$requests->post(); // $res = Yii::$app->services->validate->validate($params, [ // [["mobile",'captcha','openid','platform'],'string'] // ]); // if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // $params['user_id'] = $this->user_id; // $params['mall_id'] = $this->mall_id; // $params['parent_id'] = $this->parent_id; // $result = User::bind($params); // if ($result === false) return $this->error(User::getStaticError()); // return $this->success('成功', $result); } private function _handleBindMobile($scene=''){ $requests = Yii::$app->request; switch ($scene){ case "mp_weixin": $params_data = @file_get_contents('php://input'); Yii::error("小程序授权信息:" . $params_data); if (!empty($params_data)) $json_data = json_decode($params_data, true); $params = array_merge($requests->get(), $requests->post(), $json_data ?? []); $rules = [ [['code', 'encryptedData', 'iv', 'key'], 'string'], [['user_id', 'activity_id', 'share_user_id', 'source'], "integer"], [['invite_mobile'], "safe"], ['invite_mobile', 'match', 'pattern' => '/[0-9]+$/', 'message' => '请输入正确的推荐人手机号码'], [['encryptedData'],'required'] ]; $params['source'] = empty($this->source) ? User::SOURCE_SHARE_INDEX : $this->source; $obj = new WechatForm(['mall_id'=>$this->mall_id]); $method = 'authorizedMobilePhone'; break; default: $params =$requests->post(); $rules = [ [["mobile",'captcha','openid','platform'],'string'], [['invite_mobile'], "safe"], ['invite_mobile', 'match', 'pattern' => '/[0-9]+$/', 'message' => '请输入正确的推荐人手机号码'], ]; $obj = new User(); $method = 'bind'; break; } $res = Yii::$app->services->validate->validate($params, $rules); $params['mall_id'] = $this->mall_id; $params['user_id'] = $this->user_id; $params['parent_id'] = $this->parent_id; Yii::error("注册的参数:" . Json::encode($params)); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $result = $obj->$method($params); if ($result === false) return $this->error($obj::getStaticError()); return $this->success('操作成功', $result); } /** * @desc:desc * @Author: hua * @Date: 2021/10/26 * @Time: 14:15 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException * @throws \Psr\SimpleCache\InvalidArgumentException */ public function actionJssdkConfig() { try{ $wechat_form = new WechatForm(['mall_id'=>$this->mall_id]); if (empty(Yii::$app->params['wechatConfig']['app_id'])) return $this->error('请设置公众号配置'); $result = $wechat_form->getJsSdkConfig(); return $this->success('操作成功', $result); }catch(\Exception $e){ return $this->error($e->getMessage()); } } public function actionCancellation() { try { $user_id = $this->user_id; if(empty($user_id)) return $this->error('请先登录'); $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['captcha'], 'required'], [['captcha'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); if (!Sms::checkValidateCode($this->user['mobile'], $params['captcha'], Sms::SMS_TYPE_USER_CANCELLATION)) throw new Exception('验证码不正确'); Yii::$app->services->apiAccessToken->disableByAccessToken(Yii::$app->user->identity->access_token); $res = User::updateAll(['status' => StatusEnum::DISABLED], ['id'=>$user_id]); if ($res === false) return $this->error(User::getStaticError()); $event = new UserCancellationEvent($this->mall_id); \Yii::$app->services->events->dispatch($event, [ 'mall_id' => $this->mall_id, 'user_id' => $user_id, 'operator_user_id' => $user_id, ], $event->listeners); return $this->success('操作成功'); }catch (Exception $e){ return $this->error($e->getMessage()); } } public function actionSmsCode() { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['area_code'], 'integer'], [['sms_type'], 'string'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $area_code = '';// 初始化区号 $gateways = 'domestic';// 默认国内短信 // 检测是登录并且区号不为空则使用国际短信 if (!empty($this->user) && !empty($this->user->area_code)&&$this->user->area_code!=86) { $gateways = 'international'; $area_code = $this->user->area_code; } // 判断是否有区号 if (!empty($params['area_code']) && $params['area_code'] != 86) { $gateways = 'international'; $area_code = $params['area_code']; } $notice_sms_status = \Yii::$app->services->setting->mall->get($this->mall_id, 'notice_sms.status'); if(empty($notice_sms_status)) return $this->error('短信提醒未开启'); $params['mobile'] = $this->user['mobile']; $params['sms_type'] = $params['sms_type'] ?: ''; $sms = new Sms($this->mall_id, $gateways); try { if ($sms->sendCaptcha($params['mobile'], $area_code,$params['sms_type']) === false) return $this->error('发送失败'); }catch (\Exception $e){ return $this->error($e->getMessage()); } return $this->success('发送成功'); } /** * 支付宝小程序授权登录 * @desc 根据authCode 获取用户信息调用 alipay.system.oauth.token 取得 user_id 和 token(授权令牌)。 * 使用的 scope 包含 auth_user,则服务端继续使用所取得的 token 调用 alipay.user.info.share 最终获得用户信息。 * @return mixed|void * @throws \Exception */ public function actionAuthAlipayMini() { $params = Yii::$app->request->post(); $rules = [ [['authCode'], 'string'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form = new AlipayMiniForm($this->mall_id); $result = $form->authorize($params['authCode'], $this->parent_id); if(!$result){ \Yii::error('actionAuthAlipayMini:'.$form->getError()); return $this->error($form->getError()); } return $this->success('操作成功',$result); } /** * 支付宝小程序授权手机号 * @return mixed|void */ public function actionMobileAlipayMini() { $params = Yii::$app->request->post(); $rules = [ [['data','openid'], 'string'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $data = json_decode($params['data'],true); $new_params['mall_id'] = $this->mall_id; $new_params['user_id'] = $this->user_id; $new_params['parent_id'] = $this->parent_id; $new_params['encryptData'] = $data['response']; $new_params['openid'] = $params['openid']; $form = new AlipayMiniForm($this->mall_id); $result = $form->authorizedMobilePhone($new_params); if(!$result){ return $this->error($form->getError()); } return $this->success('操作成功',$result); } public function actionMobileAlipayMiniByCode() { try{ $requests = Yii::$app->request; $params =$requests->post(); $rules = [ [['mobile','captcha','open_id'],'string'], [['invite_mobile'], "safe"], ['invite_mobile', 'match', 'pattern' => '/[0-9]+$/', 'message' => '请输入正确的推荐人手机号码'], [['mobile','captcha','open_id'],'required'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form = new AlipayMiniForm($this->mall_id); $result = $form->bindMobileBySms($params['open_id'],$params['mobile'],$params['captcha']); if(!$result){ return $this->error($form->getError()); } return $this->success('操作成功',$result); }catch (\Exception $e){ return $this->error($e->getMessage()); } } /** * 根据open_id 修改微信头像昵称 * @return mixed|void */ public function actionSaveWechat() { try{ $rules = [ [['openid', 'nickName', 'avatarUrl'], 'string'], // [['openid', 'nickName', 'avatarUrl'], 'required'], [['openid'], 'required'], [['nickName'], 'required', 'message' => '请输入昵称'], [['avatarUrl'], 'required', 'message' => '请上传头像'], ]; $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); $where = [['mall_id' => $this->mall_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]]; $where[] = ['platform' => 'mp-wx']; if (!empty($params["openid"])) $where[] = ['openid' => $params["openid"]]; //if (!empty($params["platform"])) $where[] = ['platform' => $params["platform"]]; $user_info = UserInfo::getOne($where); if(!$user_info){ $info = [ 'user_id' => 0, 'mall_id' => $this->mall_id, 'openid' => $params['openid'], 'platform_data' => json_encode($params), 'platform' => User::PLATFORM_MP_WX ]; UserInfo::setData($info); }else{ if(!$user_info->user_id){ $platform_data = json_decode($user_info->platform_data,true); $platform_data['headimgurl'] = $params['avatarUrl']; $platform_data['avatarUrl'] = $params['avatarUrl']; $platform_data['nickName'] = $params['nickName']; $user_info->platform_data = json_encode($platform_data); $user_info->save(); } } return $this->success('操作成功'); }catch(\Exception $e){ return $this->error($e->getMessage()); } } /** * 获取支付宝优惠券access token * @return mixed|void|null */ public function actionGetAlipayVoucherAccessToken() { try { $rules = [ [['code'], 'string'], [['code'], 'required', 'message' => '请输入code'], ]; $params = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); // 校验当前系统是否安装了支付宝商家券插件 if (!MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_ALIPAY_MCH_COUPON)) { throw new \Exception('您还未安装当前插件'); } $res = (new OauthTokenService([ 'mall_id' => $this->mall_id, 'code' => $params['code'] ]))->exec(); if (empty($res['access_token'])) throw new \Exception('获取token失败'); // 缓存 // "alipay:voucher:access_token:{$this->user_id}" Yii::$app->cache->set(RedisKeyEnum::suffix(RedisKeyEnum::ALIPAY_ACCESS_TOKEN, "voucher:{$this->user_id}"), $res['access_token'], $res['expires_in'] - 10); return $this->success('获取成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } }