diff --git a/app/AdminRest.php b/app/AdminRest.php new file mode 100644 index 0000000..e0fa6f5 --- /dev/null +++ b/app/AdminRest.php @@ -0,0 +1,272 @@ + 无限开版 其他 = 几开版 + * @var array + */ + protected $card_auth_version = 0; + + /** + * 可开通名片数量 + * 0 => 无限开版 其他 = 名片数量 + * @var array + */ + protected $card_auth_card = 0; + + public function __construct ( App $app ) + { + + + parent::__construct( $app ); + + //获取method + $this->_method = $this->request->method( true ); + + $this->_is_weiqin = longbingIsWeiqin(); + //获取app名称 + $this->_app = $app->http->getName(); + //获取controller + $this->_controller = $this->request->controller(); + //获取action名称 + $this->_action = $this->request->action(); + //获取param + $this->_param = $this->request->param(); + //获取body参数 + $this->_input = json_decode( $this->request->getInput(), true ); + //获取头部信息 + $this->_header = $this->request->header(); + //获取请求host + $this->_host = $this->_header[ 'host' ]; + //获取访问ip + $this->_ip = $_SERVER[ 'REMOTE_ADDR' ]; + + if ( $this->_is_weiqin ) { + + global $_GPC, $_W; + + $this->_uniacid = $_W[ 'uniacid' ]; + + if (empty($_W['user']) || empty($_W[ 'uniacid' ])) { + + echo json_encode(['code' => 401, 'error' => '请登录管理系统!']); + exit; + } + + }else{ + + //获取token 通过header获取token,如果不存在,则从param中获取。 + if ( !isset( $this->_header[ 'token' ] ) || empty($this->_header[ 'token' ])) + { + if(!isset( $this->_param[ 'token' ] ) || empty($this->_param[ 'token' ])) + { + //返回数数据 + echo json_encode(['code' => 401, 'error' => '请重新登录!']); + exit; + }else{ + $this->_header[ 'token' ] = $this->_param[ 'token' ]; + } + } + + //获取token + $this->_token = $this->_header[ 'token' ] ; + //语言 + if ( isset( $this->_header[ 'lang' ] ) ) $this->_lang = $this->_header[ 'lang' ]; + //获取用户信息 + $this->_user = getUserForToken( $this->_token ); + + if ($this->_user == null) { + + echo json_encode(['code' => 401, 'error' => '请登录系统!']); + exit; + } + + $this->_uniacid = !empty( $this->_user ) && isset( $this->_user[ 'uniacid' ] ) ? $this->_user[ 'uniacid' ] : 2; + } + + landNotice($this->_uniacid); + + + + } + + //返回请求成功的数据 + public function success ( $data, $code = 200 ) + { + $result[ 'data' ] = $data; + $result[ 'code' ] = $code; + $result[ 'sign' ] = null; + //复杂的签名 + // if(isset($this->_user['keys'])){ + // $result['sign'] = rsa2CreateSign($this->_user['keys'] ,json_encode($data)); + // } + //简单的签名 + if ( !empty( $this->_token ) ) $result[ 'sign' ] = createSimpleSign( $this->_token, is_string( $data ) ? $data : json_encode( $data ) ); + return $this->response( $result, 'json', $code ); + } + + //返回错误数据 + public function error ( $msg, $code = 400 ) + { + $result[ 'error' ] = Lang::get($msg); + $result[ 'code' ] = $code; + return $this->response( $result, 'json', 200 ); + } + + /** + * 输出返回数据 + * @access protected + * @param mixed $data 要返回的数据 + * @param String $type 返回类型 JSON XML + * @param integer $code HTTP状态码 + * @return Response + */ + protected function response ( $data, $type = 'json', $code = 200 ) + { + return Response::create( $data, $type )->code( $code ); + } + + /** + * REST 调用 + * @access public + * @param string $method 方法名 + * @return mixed + * @throws \Exception + */ + public function _empty ( $method ) + { + if ( method_exists( $this, $method . '_' . $this->method . '_' . $this->type ) ) { + // RESTFul方法支持 + $fun = $method . '_' . $this->method . '_' . $this->type; + } + elseif ( $this->method == $this->restDefaultMethod && method_exists( $this, $method . '_' . $this->type ) ) { + $fun = $method . '_' . $this->type; + } + elseif ( $this->type == $this->restDefaultType && method_exists( $this, $method . '_' . $this->method ) ) { + $fun = $method . '_' . $this->method; + } + if ( isset( $fun ) ) { + return App::invokeMethod( [ + $this, + $fun + ] + ); + } + else { + // 抛出异常 + throw new \Exception( 'error action :' . $method ); + } + } + + + + /** + * + * 获取支付信息 + */ + public function payConfig (){ + $uniacid_id = !empty($uniacid)?$uniacid:$this->_uniacid; + + $pay = Db::name('lbfarm_pay_config')->where(['uniacid'=>$uniacid_id])->find(); + + $config = Db::name( 'lbfarm_config')->where(['uniacid' => $uniacid_id])->find(); + + if(empty($pay[ 'mch_id' ])||empty($pay[ 'pay_key' ])){ + $this->errorMsg('未配置支付信息'); + } + $setting[ 'payment' ][ 'merchant_id' ] = $pay[ 'mch_id' ]; + $setting[ 'payment' ][ 'key' ] = $pay[ 'pay_key' ]; + $setting[ 'payment' ][ 'cert_path' ] = $pay[ 'cert_path' ]; + $setting[ 'payment' ][ 'key_path' ] = $pay[ 'key_path' ]; + $setting[ 'app_id' ] = $config['appid']; + $setting[ 'secret' ] = $config['appsecret']; + return $setting; + } + + + /** + * User: chenniang + * Date: 2019-09-12 20:37 + * @param string $msg + * @return void + * descption:直接抛出异常 + */ + protected function errorMsg($msg = '',$code = 400){ + $msg = Lang::get($msg); + $this->results($msg,$code); + } + + /** + * 返回封装后的 API 数据到客户端 + * @access protected + * @param mixed $msg 提示信息 + * @param mixed $data 要返回的数据 + * @param int $code 错误码,默认为0 + * @param string $type 输出类型,支持json/xml/jsonp + * @param array $header 发送的 Header 信息 + * @return void + * @throws HttpResponseException + */ + protected function results($msg, $code, array $header = []) + { + $result = [ + 'error' => $msg, + 'code' => $code, + ]; + $response = Response::create($result, 'json', 200)->header($header); + throw new HttpResponseException($response); + } +} diff --git a/app/AgentRest.php b/app/AgentRest.php new file mode 100644 index 0000000..c34f053 --- /dev/null +++ b/app/AgentRest.php @@ -0,0 +1,325 @@ +_header = $this->request->header(); + if (defined('IS_WEIQIN')) { + global $_GPC, $_W; + $this->_uniacid = $_W[ 'uniacid' ]; + $this->_user = $_W['user']; + $role_map = [ + 'founder' => 'admin', + 'operator' => 'guest', + ]; + $this->_role = $role_map[$_W['role']] ?? 'guest'; + + if (empty($this->_user)) { + echo json_encode(['code' => 401, 'error' => '用户没有登录']); + exit; + } + if (!$_W['isfounder']) { + echo json_encode(['code' => 401, 'error' => '非超级管理员']); + exit; + } + $this->_user['role_name']='admin'; + } else { + //获取token + if ( isset( $this->_header[ 'token' ] ) ) $this->_token = $this->_header[ 'token' ]; + + + //获取用户信息 + if ( !empty( $this->_token ) ) $this->_user = getUserForToken( $this->_token ); + //获取角色名称 + if ( !empty( $this->_user ) && isset( $this->_user[ 'role_name' ] ) ) $this->_role = $this->_user[ 'role_name' ]; + + + if ($this->_user == null) { + echo json_encode(['code' => 401, 'error' => '用户没有登录']); + exit; + } + + $this->_uniacid = !empty( $this->_user ) && isset( $this->_user[ 'uniacid' ] ) ? $this->_user[ 'uniacid' ] : -1; + +// if ($this->_user['role_name'] != 'admin') { +// echo json_encode(['code' => 401, 'error' => '非超级管理员']); +// exit; +// } + } + + //获取app名称 +// $this->_app = $this->request->app(); + $this->_app = $app->http->getName(); + //获取controller + $this->_controller = $this->request->controller(); + //获取action名称 + $this->_action = $this->request->action(); + + //获取method + $this->_method = $this->request->method( true ); + //获取param + $this->_param = $this->request->param(); + + //获取配置信息 + $this->_config = Db::name( 'longbing_card_config' ) + ->where( [ 'uniacid' => $this->_uniacid ] ) + ->find(); + + if(in_array($this->_method,['options','Options','OPTIONS'])){ + echo true;exit; + } + //获取body参数 + $this->_input = json_decode( $this->request->getInput(), true ); + + // //判断是否为json + // if(!isset($this->request->header()['Content-Type'])) { + // $this->_header['Content-Type'] = 'application/json'; + // $this->app->request->withHeader($this->_header); + // } + + //获取该应用下面所有的uniacid + $this->_uniacid_arr = $this->getUniacid(); + //语言 + if ( isset( $this->_header[ 'lang' ] ) ) $this->_token = $this->_header[ 'lang' ]; + //获取请求host + $this->_host = $this->_header[ 'host' ]; + //获取访问ip + $this->_ip = $_SERVER[ 'REMOTE_ADDR' ]; + // 控制器初始化 + $this->initialize(); + //是否是微擎 + $this->_is_weiqin = longbingIsWeiqin(); + } + + //返回请求成功的数据 + public function success ( $data, $code = 200 ) + { + $result[ 'data' ] = $data; + $result[ 'code' ] = $code; + $result[ 'sign' ] = null; + //复杂的签名 + // if(isset($this->_user['keys'])){ + // $result['sign'] = rsa2CreateSign($this->_user['keys'] ,json_encode($data)); + // } + //简单的签名 + if ( !empty( $this->_token ) ) $result[ 'sign' ] = createSimpleSign( $this->_token, is_string( $data ) ? $data : json_encode( $data ) ); + return $this->response( $result, 'json', $code ); + } + + //返回错误数据 + public function error ( $msg, $code = 400 ) + { +// dd($this->request);die; +// var_dump($this->_app ,$this->_controller ,$this->_action);die; + $result[ 'error' ] = Lang::get($msg); + $result[ 'code' ] = $code; + return $this->response( $result, 'json', 200 ); + } + + /** + * 输出返回数据 + * @access protected + * @param mixed $data 要返回的数据 + * @param String $type 返回类型 JSON XML + * @param integer $code HTTP状态码 + * @return Response + */ + protected function response ( $data, $type = 'json', $code = 200 ) + { + return Response::create( $data, $type )->code( $code ); + } + + /** + * REST 调用 + * @access public + * @param string $method 方法名 + * @return mixed + * @throws \Exception + */ + public function _empty ( $method ) + { + if ( method_exists( $this, $method . '_' . $this->method . '_' . $this->type ) ) { + // RESTFul方法支持 + $fun = $method . '_' . $this->method . '_' . $this->type; + } + elseif ( $this->method == $this->restDefaultMethod && method_exists( $this, $method . '_' . $this->type ) ) { + $fun = $method . '_' . $this->type; + } + elseif ( $this->type == $this->restDefaultType && method_exists( $this, $method . '_' . $this->method ) ) { + $fun = $method . '_' . $this->method; + } + if ( isset( $fun ) ) { + return App::invokeMethod( [ + $this, + $fun + ] + ); + } + else { + // 抛出异常 + throw new \Exception( 'error action :' . $method ); + } + } + + /** + * @Purpose: 获取formId + * + * @Author: zzf + * + * @Return: mixed 查询返回值(结果集对象) + */ + + public function getFormId ( $to_uid ) + { + // 七天前开始的的时间戳 + // $beginTime = mktime( 0, 0, 0, date( 'm' ), date( 'd' ) - 6, date( 'Y' ) ); + $beginTime = strtotime(date('Y-m-d',time()))-86400*6; + $formId = Db::name( 'longbing_card_formId' ) + ->where( [ 'user_id' => $to_uid ] ) + ->order( 'id desc' ) + ->select(); + if ( empty( $formId ) ) + { + return false; + } + if ( $formId[ 0 ][ 'create_time' ] < $beginTime ) + { + Db::name( 'longbing_card_formId' ) + ->where( [ 'id' => $formId[ 0 ][ 'id' ] ] ) + ->delete(); + $this->getFormId( $to_uid ); + } + else + { + Db::name( 'longbing_card_formId' ) + ->where( [ 'id' => $formId[ 0 ][ 'id' ] ] ) + ->delete(); + return $formId[ 0 ][ 'formId' ]; + } + } + + /** + * + * 获取支付信息 + */ + public function payConfig (){ + $pay = Db::name('longbing_card_config_pay')->where(['uniacid'=>$this->_uniacid])->find(); + if(empty($pay)){ + $this->errorMsg('no config of pay'); + } + $setting[ 'payment' ][ 'merchant_id' ] = $pay[ 'mch_id' ]; + $setting[ 'payment' ][ 'key' ] = $pay[ 'pay_key' ]; + $setting[ 'payment' ][ 'cert_path' ] = $pay[ 'cert_path' ]; + $setting[ 'payment' ][ 'key_path' ] = $pay[ 'key_path' ]; + $setting[ 'app_id' ] = $this->_config['appid']; + $setting[ 'secret' ] = $this->_config['app_secret']; + return $setting; + } + + + /** + * User: chenniang + * Date: 2019-09-12 20:37 + * @param string $msg + * @return void + * descption:直接抛出异常 + */ + protected function errorMsg($msg = '',$code = 400){ + $msg = Lang::get($msg); + $this->results($msg,$code); + } + + /** + * 返回封装后的 API 数据到客户端 + * @access protected + * @param mixed $msg 提示信息 + * @param mixed $data 要返回的数据 + * @param int $code 错误码,默认为0 + * @param string $type 输出类型,支持json/xml/jsonp + * @param array $header 发送的 Header 信息 + * @return void + * @throws HttpResponseException + */ + protected function results($msg, $code, array $header = []) + { + $result = [ + 'error' => $msg, + 'code' => $code, + ]; + $response = Response::create($result, 'json', 200)->header($header); + throw new HttpResponseException($response); + } + + /** + * @author chenniang + * @DataTime: 2020-06-05 09:13 + * @功能说明:获取微擎的uniacid(同应用下面的)array + */ + public function getUniacid(){ + + if(defined('IS_WEIQIN')){ + //模块名字 + $app_model_name = APP_MODEL_NAME; + + $dis[] = ['modules','like','%'.$app_model_name.'%']; + //获取该应用下面的所有uniacid + $uniacid = Db::name('wxapp_versions')->where($dis)->column('uniacid'); + }else{ + + $uniacid = [$this->_user['uniacid']]; + } + return $uniacid; + } +} diff --git a/app/ApiRest.php b/app/ApiRest.php new file mode 100644 index 0000000..dcd78a9 --- /dev/null +++ b/app/ApiRest.php @@ -0,0 +1,573 @@ + 'https://retail.xiaochengxucms.com/defaultAvatar.png', + // 默认内容图片 + 'image' => 'https://retail.xiaochengxucms.com/lbCardDefaultImage.png', + ); + + protected $_is_weiqin = false ; + + protected $check_url = ""; + + /** + * 无需登录的方法,同时也就不需要鉴权了 + * @var array + */ + protected $noNeedLogin = []; + + + public function __construct ( App $app ) + { + + + parent::__construct( $app ); + + if(in_array($this->_method,['options','Options','OPTIONS'])){ + + echo true;exit; + } + + //获取param + $this->_param = $this->request->param(); + //获取body参数 + $this->_input = json_decode( $this->request->getInput(), true ); + //获取头部信息 + $this->_header = $this->request->header(); + + + $this->is_app = !empty($this->_header['isapp'])?$this->_header['isapp']:0; + + if ( defined( 'IS_WEIQIN' ) ) + { + global $_GPC, $_W; + $this->_uniacid = $_W[ 'uniacid' ]; + } + else + { + if(isset($this->_param[ 'i' ])) + { + $this->_uniacid = $this->_param[ 'i' ]; + } + + } + + if ( defined( 'LONGBING_CARD_UNIACID' ) ) + { + + define( 'LONGBING_CARD_UNIACID', $this->_uniacid ); + } + + // $this->shareChangeData($this->_param); + //获取autograph 小程序用户唯一标示 + if ( isset( $this->_header[ 'autograph' ] ) && $this->_header[ 'autograph' ]) + { + $this->autograph = $this->_header['autograph']; + } + else + { + if(!$this->match($this->noNeedLogin)){ + + $this->errorMsg('need login',401); + + } + } + //获取配置信息 + $this->_config = longbingGetAppConfig($this->_uniacid); + //语言 + if ( isset( $this->_header[ 'lang' ] ) ) $this->_token = $this->_header[ 'lang' ]; + + if(!empty($this->autograph)&&!$this->match($this->noNeedLogin)){ + + $this->_user_id = $this->getUserId(); + + $this->_user = $this->getUserInfo(); + } + + landNotice($this->_uniacid); + + } + + + /** + * @author chenniang + * @DataTime: 2020-08-21 17:43 + * @功能说明: + */ + public function shareChangeData($input){ + + $arr = [ + + 'farm/app/Index/getYsToken', + + 'farm/app/Index/ysStartTurn', + + 'farm/app/Index/ysStopTurn', + + 'farm/app/Index/getMonitorInfo', + + 'farm/app/Index/index', + + 'farm/app/Index/couponList', + + 'farm/app/IndexClaim/claimCateList', + + 'farm/app/IndexLand/landList', + + 'farm/app/IndexClaim/claimBanner', + + 'farm/app/IndexClaim/claimCateList', + + 'farm/app/IndexClaim/claimList', + + 'farm/app/IndexGoods/goodsIndex', + + 'farm/app/IndexGoods/carInfo', + + 'farm/app/IndexGoods/goodsList', + + 'farm/app/IndexUser/userInfo', + + 'farm/app/IndexUser/index', + + 'farm/app/IndexUser/farmerInfo', + + 'farm/app/Index/configInfo', + ]; + + if(!empty($input['s'])&&in_array($input['s'],$arr)){ + + $input['s'] = trim(strrchr($input['s'], '/'),'/'); + + $this->noNeedLogin[] = $input['s']; + } + + return true; + } + + + /** + * @author chenniang + * @DataTime: 2020-07-09 12:00 + * @功能说明:检测方法传递 + */ + public function match($arr){ + + + $arr = is_array($arr) ? $arr : explode(',', $arr); + if (!$arr) + { + return FALSE; + } + $arr = array_map('strtolower', $arr); + // 是否存在 + if (in_array(strtolower($this->request->action()), $arr) || in_array('*', $arr)) + { + return TRUE; + } + + // 没找到匹配 + return FALSE; + } + + //返回请求成功的数据 + public function success ( $data, $code = 200 ) + { + $result[ 'data' ] = LongbingGetWxApiReturnData($data); + $result[ 'code' ] = $code; + $result[ 'sign' ] = null; + //复杂的签名 + // if(isset($this->_user['keys'])){ + // $result['sign'] = rsa2CreateSign($this->_user['keys'] ,json_encode($data)); + // } + //简单的签名 + if ( !empty( $this->_token ) ) $result[ 'sign' ] = createSimpleSign( $this->_token, is_string( $data ) ? $data : json_encode( $data ) ); + return $this->response( $result, 'json', $code ); + } + + //返回错误数据 + public function error ( $msg, $code = 400 ) + { +// $result[ 'error' ] = Lang::get($msg); +// $result[ 'code' ] = $code; + $result = $this->getErrorData($msg, $code); + return $this->response( $result, 'json', 200 ); + } + + public function getErrorData($msg, $code = 400) + { + $result[ 'error' ] = Lang::get($msg); + $result[ 'code' ] = $code; + return $result; + } + /** + * 输出返回数据 + * @access protected + * @param mixed $data 要返回的数据 + * @param String $type 返回类型 JSON XML + * @param integer $code HTTP状态码 + * @return Response + */ + protected function response ( $data, $type = 'json', $code = 200 ) + { + return Response::create( $data, $type )->code( $code ); + } + + /** + * REST 调用 + * @access public + * @param string $method 方法名 + * @return mixed + * @throws \Exception + */ + public function _empty ( $method ) + { + if ( method_exists( $this, $method . '_' . $this->method . '_' . $this->type ) ) + { + // RESTFul方法支持 + $fun = $method . '_' . $this->method . '_' . $this->type; + } + elseif ( $this->method == $this->restDefaultMethod && method_exists( $this, $method . '_' . $this->type ) ) + { + $fun = $method . '_' . $this->type; + } + elseif ( $this->type == $this->restDefaultType && method_exists( $this, $method . '_' . $this->method ) ) + { + $fun = $method . '_' . $this->method; + } + if ( isset( $fun ) ) + { + return App::invokeMethod( [ $this, $fun ] + ); + } + else + { + // 抛出异常 + throw new \Exception( 'error action :' . $method ); + } + } + + /** + * @Purpose: 通过小程序端的用户标示获取用户信息 + * + * @Author: zzf + * + * @Return: mixed 查询返回值(结果集对象) + */ + protected function getUserInfo () + { + + $value = getCache($this->autograph, $this->_uniacid); + + if(empty($value)){ + + $this->errorMsg('need login',401); + } + + if(empty($value['phone'])){ + + // $this->errorMsg('need phone',403); + + } + + $user_model = new \app\farm\model\User(); + + $value['balance'] = $user_model->where(['id'=>$value['id']])->value('balance'); + + return $value; + } + + + /** + * @author chenniang + * @DataTime: 2021-03-19 15:22 + * @功能说明:获取当前的门店信息 + */ + public function getStoreInfo($err=1){ + + $user_id = $this->getUserId(); + + $user_model = new \app\farm\model\User(); + + $cap_id = $user_model->where(['id'=>$user_id])->value('last_store_id'); + + $cap_info = []; + + if(!empty($cap_id)){ + + $cap_model = new Farmer(); + + $dis = [ + + 'id' => $cap_id, + + 'status' => 2, + + 'business_status' => 1, + + 'type' => 2, + ]; + + $cap_info = $cap_model->dataInfo($dis); + } + + if(empty($cap_info)&&$err==1){ + + // $this->errorMsg('请选择店铺',-407); + + } + + return $cap_info; + + } + + + + /** + * @Purpose: 通过小程序端的用户标示获取用户id + * + * @Author: zzf + * + * @Return: mixed 查询返回值(结果集对象) + */ + protected function getUserId () + { + + $value = getCache( $this->autograph, $this->_uniacid ); + + if($this->is_app==1){ + + + $user_model = new \app\farm\model\User(); + + $id = $user_model->where(['check'=>1])->value('id'); + + return $id; + } + + if ( ($value === false &&!$this->match($this->noNeedLogin))) + { + + $this->errorMsg('need login',401); + + } + + +// if($this->match($this->noNeedLogin)&&empty($value)){ +// +// $user_model = new \app\farm\model\User(); +// +// $value =$user_model->dataInfo(['uniacid'=>$this->_uniacid,'check'=>1]); +// +// // setCache($this->autograph,$value,7200,$this->_uniacid); +// } + +// if ( (!empty($value['check']) &&!$this->match($this->noNeedLogin))) +// { +// +// $this->errorMsg('need login',401); +// +// } + + + return !empty($value[ 'id' ])?$value[ 'id' ]:0; + } + /** + * + * 获取支付信息 + */ + + + + public function payConfig ($uniacid = '1',$is_app=7){ + + if($is_app==7){ + + $is_app = $this->is_app; + } + + $uniacid_id = !empty($uniacid)?$uniacid:$this->_uniacid; + + $pay = Db::name('lbfarm_pay_config')->where(['uniacid'=>$uniacid_id])->find(); + + $config = Db::name( 'lbfarm_config')->where(['uniacid' => $uniacid_id])->find(); + + if(empty($pay[ 'mch_id' ])||empty($pay[ 'pay_key' ])){ + + // $this->errorMsg('未配置支付信息'); + } + + $setting[ 'payment' ][ 'merchant_id' ] = $pay[ 'mch_id' ]; + + $setting[ 'payment' ][ 'key' ] = $pay[ 'pay_key' ]; + + $setting[ 'payment' ][ 'cert_path' ] = $pay[ 'cert_path' ]; + + $setting[ 'payment' ][ 'key_path' ] = $pay[ 'key_path' ]; + + $setting[ 'payment' ][ 'ali_appid' ] = $pay[ 'ali_appid' ]; + + $setting[ 'payment' ][ 'ali_privatekey' ] = $pay[ 'ali_privatekey' ]; + + $setting[ 'payment' ][ 'ali_publickey' ] = $pay[ 'ali_publickey' ]; + + if($is_app==0){ + + $setting[ 'app_id' ] = $config['appid']; + + $setting[ 'secret' ] = $config['appsecret']; + + }elseif($is_app==1){ + + $setting[ 'app_id' ] = $config['app_app_id']; + + $setting[ 'secret' ] = $config['app_app_secret']; + + }else{ + + $setting[ 'app_id' ] = $config['web_app_id']; + + $setting[ 'secret' ] = $config['web_app_secret']; + + } + + $setting[ 'is_app' ]= $is_app; + + return $setting; + } + + /** + * @Purpose: 获取formId + * + * @Author: zzf + * + * @Return: mixed 查询返回值(结果集对象) + */ + + public function getFormId ( $to_uid ) + { + return []; + // 七天前开始的的时间戳 + // $beginTime = mktime( 0, 0, 0, date( 'm' ), date( 'd' ) - 6, date( 'Y' ) ); + $beginTime = strtotime(date('Y-m-d',time()))-86400*6; + $formId = Db::name( 'longbing_card_formId' ) + ->where( [ 'user_id' => $to_uid ] ) + ->order( 'id desc' ) + ->select(); + if ( empty( $formId ) ) + { + return false; + } + if ( $formId[ 0 ][ 'create_time' ] < $beginTime ) + { + Db::name( 'longbing_card_formId' ) + ->where( [ 'id' => $formId[ 0 ][ 'id' ] ] ) + ->delete(); + $this->getFormId( $to_uid ); + } + else + { + Db::name( 'longbing_card_formId' ) + ->where( [ 'id' => $formId[ 0 ][ 'id' ] ] ) + ->delete(); + return $formId[ 0 ][ 'formId' ]; + } + } + /** + * User: chenniang + * Date: 2019-09-12 20:37 + * @param string $msg + * @return void + * descption:直接抛出异常 + */ + protected function errorMsg($msg = '',$code = 400){ + $msg = Lang::get($msg); + $this->results($msg,$code); + } + + /** + * User: chenniang + * Date: 2019-09-12 20:42 + * @param $msg + * @param int $code + * @param array $header + * @return void + * descption:直接抛出状态 + */ + protected function results($msg, $code, array $header = []) + { + $result = [ + 'error' => $msg, + 'code' => $code, + ]; + $response = Response::create($result, 'json', 200)->header($header); + throw new HttpResponseException($response); + } +} diff --git a/app/BaseController.php b/app/BaseController.php new file mode 100644 index 0000000..7403416 --- /dev/null +++ b/app/BaseController.php @@ -0,0 +1,113 @@ + +// +---------------------------------------------------------------------- +declare (strict_types = 1); + +namespace app; + +use think\App; +use think\exception\ValidateException; +use think\Validate; + +/** + * 控制器基础类 + */ +abstract class BaseController +{ + /** + * Request实例 + * @var \think\Request + */ + protected $request; + + /** + * 应用实例 + * @var \think\App + */ + protected $app; + + /** + * 是否批量验证 + * @var bool + */ + protected $batchValidate = false; + + /** + * 控制器中间件 + * @var array + */ + protected $middleware = []; + + /** + * 构造方法 + * @access public + * @param App $app 应用对象 + */ + public function __construct(App $app) + { + + longbing_check_install(); + + $this->app = $app; + + $this->request = $this->app->request; + + $this->_method = $this->request->method( true ); + + if(in_array($this->_method,['options','Options','OPTIONS'])){ + echo true;exit; + } + // 控制器初始化 + $this->initialize(); + + } + + // 初始化 + protected function initialize() + {} + + /** + * 验证数据 + * @access protected + * @param array $data 数据 + * @param string|array $validate 验证器名或者验证规则数组 + * @param array $message 提示信息 + * @param bool $batch 是否批量验证 + * @return array|string|true + * @throws ValidateException + */ + protected function validate(array $data, $validate, array $message = [], bool $batch = false) + { + if (is_array($validate)) { + $v = new Validate(); + $v->rule($validate); + } else { + if (strpos($validate, '.')) { + // 支持场景 + list($validate, $scene) = explode('.', $validate); + } + $class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate); + $v = new $class(); + if (!empty($scene)) { + $v->scene($scene); + } + } + + $v->message($message); + + // 是否批量验证 + if ($batch || $this->batchValidate) { + $v->batch(true); + } + + return $v->failException(true)->check($data); + } + +} diff --git a/app/BaseControllerV2.php b/app/BaseControllerV2.php new file mode 100644 index 0000000..16a64ff --- /dev/null +++ b/app/BaseControllerV2.php @@ -0,0 +1,80 @@ + +// +---------------------------------------------------------------------- +declare (strict_types = 1); + +namespace app; + +use think\Request; + +/** + * 控制器基础类 + */ +abstract class BaseControllerV2 +{ + +//唯一app标示 + public $_uniacid = 0; + //query参数 + public $_param = []; + //头部token + public $_token = null; + // + public $_autograph = null; + //请求对象 $request 兼容处理,即将废弃 + protected $request; + protected $_request; + + public function __construct(Request $request) + { + + $this->request = $request; + $this->_request = $this->request; + $this->_param = $this->request->param(); + $this->_token = $this->request->header('token'); + $this->_autograph = $this->request->header('autograph'); + $this->_uniacid = intval( $this->request->param('i') ) ; + $this->_uniacid = $this->_uniacid ? $this->_uniacid : intval( $this->request->param('uniacid') ); + + //兼容微擎新版本 + if(empty($this->_uniacid)&&longbingIsWeiqin()){ + + global $_GPC, $_W; + $this->_uniacid = $_W[ 'uniacid' ]; + + } + + //独立版拿不到uniacid + if(empty($this->_uniacid)){ + + $user_info = getUserForToken($this->_token); + + $this->_uniacid = $user_info['uniacid']; + + } + } + + /** + * 获取用户ID + * + * @return int + * @author shuixian + * @DataTime: 2019/12/24 12:45 + */ + protected function getUserId() + { + $value = getCache($this->_autograph, $this->_uniacid); + + if ($value === false) { + return 0; + } + return $value['id']; + } +} diff --git a/app/BaseModel.php b/app/BaseModel.php new file mode 100644 index 0000000..493a1c6 --- /dev/null +++ b/app/BaseModel.php @@ -0,0 +1,121 @@ + 'int', + 'update_time' => 'int', + 'delete_time' => 'int', + 'deleted' => 'int' + ]; + //设置操作时间 +// public $time; +// function __construct() { +// parent::__construct(); +// $this->time = time(); +// } +// //获取详情 +// public function getRow($filter) { +// $filter['deleted'] = 0; +// return $this->where($filter)->find(); +// } +// //获取列表 +// public function listRow($filter ,$field = []) { +// $filter['deleted'] = 0; +// return $this->where($filter) +// ->order('create_time', 'asc') +// ->field($field) +// ->select(); +// } +// //创建 +// public function createRow($data) { +// $data['create_time'] = time(); +// return $this->save($data); +// } +// //批量创建 +// public function createRows($datas) { +// return $this->saveAll($datas); +// } +// +// //更新 +// public function updateRow($filter ,$data) { +// $filter['deleted'] = 0; +// $data['update_time'] = time(); +// $result = $this->where($filter)->update($data); +// return $result; +// } +// //删除 +// public function deleteRow($filter) { +// $filter['deleted'] = 0; +// return $this->updateRow($filter ,['delete_time' => time() ,'deleted' => 1]); +// } + + //获取详情 + public function getRow($filter) + { + $filter['deleted'] = 0; + $result = $this + ->where($filter) + ->find(); + if(!empty($result)) $result = $result->toArray(); + return $result; + } + //获取列表 + public function listRow($filter) + { + $filter['deleted'] = 0; + $result = $this + ->where($filter) + ->select(); + if(!empty($result)) $result = $result->toArray(); + return $result; + } + //创建 + public function createRow($data) + { + if(!empty($data['create_time'])){ + $data['create_time'] = time(); + } + return $this->save($data); + } + //批量创建 + public function createRows($datas) + { + return $this->saveAll($datas); + } + public function upsave($filter ,$data) + { + $data['update_time'] = time(); + $result = $this->where($filter)->update($data); + if(empty($result)) return false; + return true; + } + //更新 + public function updateRow($filter ,$data) + { + $filter['deleted'] = 0; + $data['update_time'] = time(); + $result = $this->where($filter)->update($data); + if(empty($result)) return false; + return true; + } + //删除 + public function deleteRow($filter) + { + $filter['deleted'] = 0; + $result = $this->updateRow($filter ,['delete_time' => time() ,'deleted' => 1]); + if(empty($result)) return false; + return true; + } + + //真删除 + public function destroyRow($filter) + { + $result = $this->where($filter)->delete(); + if(empty($result)) return false; + return true; + } +} \ No newline at end of file diff --git a/app/Common/ArticleFromUrl.php b/app/Common/ArticleFromUrl.php new file mode 100644 index 0000000..6d65efb --- /dev/null +++ b/app/Common/ArticleFromUrl.php @@ -0,0 +1,152 @@ +html = file_get_contents( $url ); + } + + /** + * @Purpose: 获取文章内容 + * + * @Author: zzf + * + * @Return: mixed 查询返回值(结果集对象) + */ + public function getArticle () + { + $file = $this->html; + + $file = str_replace( "data-src", "src", $file ); + $file = str_replace( "data-croporisrc", "src", $file ); + $file = str_replace( "preview.html", "player.html", $file ); + $file = str_replace( "display: inline-block;", "display: block;", $file ); + + $html = ''; + + $title = $this->get_between( $file, '

', "

" ); + + + if(strpos($file,'