diff --git a/niucloud/extend/driver/file/FileDriver.php b/niucloud/extend/driver/file/FileDriver.php deleted file mode 100644 index b5c4a7d8c..000000000 --- a/niucloud/extend/driver/file/FileDriver.php +++ /dev/null @@ -1,106 +0,0 @@ -driver = $this->getDriverClass($storage_type); - } - - /** - * 获取启用的存储引擎 - */ - public function getDriverClass(string $storage_type){ - $class = __NAMESPACE__ . '\\storage\\' . ucfirst(strtolower($storage_type)); - return new $class($this->config); - } - - /** - * 上传附件 - * @param string $path - * @return mixed - */ - public function upload(string $dir){ - $this->driver->concatFullPath($dir); - return $this->driver->upload($dir); - } - - /** - * 远程拉取附件 - * @param $url - * @param $key - * @return mixed - */ - public function fetch(string $url, ?string $key){ - return $this->driver->fetch($url, $key); - } - - /** - * 读取文件 - * @param $name - */ - public function read(string $name, bool $is_rename = true){ - return $this->driver->read($name, $is_rename); - } - public function setUpload(){ - - } - - /** - * 动态调用 - * @param $method - * @param $arguments - * @return mixed - */ - public function __call($method, $arguments) - { - return $this->driver->{$method}(...$arguments); - } -// /** -// * 获取存储的文件名 -// */ -// public function getFileName(){ -// return $this->driver->getFileName(); -// } -// -// /** -// * 获取存储的文件信息 -// * @return mixed -// */ -// public function getFileInfo(){ -// return $this->driver->getFileInfo(); -// } -// -// /** -// * 获取上传后的完整路径 -// * @return mixed -// */ -// public function getFullPath(){ -// return $this->driver->getFullPath(); -// } -} \ No newline at end of file diff --git a/niucloud/extend/driver/file/Storage.php b/niucloud/extend/driver/file/Storage.php deleted file mode 100644 index 3d3ce16b7..000000000 --- a/niucloud/extend/driver/file/Storage.php +++ /dev/null @@ -1,46 +0,0 @@ -file = request()->file($name); - if(!empty($file)) - throw new UploadFileException(100012); - - $this->file_info = [ - 'name' => $this->file->getOriginalName(),//文件原始名称 - 'mime' => $this->file->getOriginalMime(),//上传文件类型信息 - 'real_path' => $this->file->getRealPath(),//上传文件真实路径 - 'ext' => $this->file->getOriginalExtension(),//上传文件后缀 - 'size' => $this->file->getSize(),//上传文件大小 - ]; - if($is_rename){ - $this->file_name = $this->createFileName(); - }else{ - $this->file_name = $this->file_info['name']; - } - - } - - /** - * 校验文件是否合法 - */ - public function check(){ - - } - - /** - * 生成新的文件名 - * @return string - */ - public function createFileName(string $key = '', string $ext = ''){ - //DIRECTORY_SEPARATOR 常量 - if(empty($key)){ - return time().md5($this->file_info['real_path']).'.'.$this->file_info['ext']; - }else{ - return time().md5($key).'.'.$ext; - } - - } - - /** - * 获取原始附件信息 - * @return mixed - */ - public function getFileInfo(){ - return $this->file_info; - } - - /** - * 获取上传文件的真实完整路径 - * @return mixed - */ - public function getRealPath(){ - return $this->file_info['real_path']; - } - /** - * 获取生成的文件完整地址 - * @return mixed - */ - public function getFullPath(){ - return $this->full_path; - } - - /** - * 合并路径和文件名 - */ - public function concatFullPath(string $dir = ''){ - $this->full_path = implode('/', array_filter([$dir, $this->getFileName()])); - } - - /** - * 获取文件名 - * @return mixed - */ - public function getFileName() - { - return $this->file_name; - } - public function getUrl(string $path = ''){ - $path = !empty($path) ? $path : $this->getFullPath(); - $domain = $this->config['domain'] ?? ''; - $domain = empty($domain) ? '' : $domain.'/'; - return $domain.$path; - } -} \ No newline at end of file diff --git a/niucloud/extend/driver/file/storage/Aliyun.php b/niucloud/extend/driver/file/storage/Aliyun.php deleted file mode 100644 index 1d177e3ff..000000000 --- a/niucloud/extend/driver/file/storage/Aliyun.php +++ /dev/null @@ -1,99 +0,0 @@ -config['access_key']; - $access_key_secret = $this->config['secret_key']; - - $endpoint = $this->config['endpoint'];// yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。 - $oss_client = new OssClient($access_key_id, $access_key_secret, $endpoint, $is_cname); - return $oss_client; - } - - /** - * 执行上传 - * @param $save_dir (保存路径) - * @return bool|mixed - */ - public function upload(string $dir) - { - $bucket = $this->config['bucket']; - try { - $this->client()->uploadFile( - $bucket, - $this->getFullPath(), - $this->getRealPath() - ); - return true; - } catch (OssException $e) { - throw new UploadFileException($e->getMessage()); - } - - } - - /** - * Notes: 抓取远程资源 - * @param $url - * @param null $key - * @return mixed|void - */ - public function fetch(string $url, ?string $key = null) - { - $bucket = $this->config['bucket']; - try { - $content = file_get_contents($url); - $this->client()->putObject( - $bucket, - $key, - $content - ); - return true; - } catch (OssException $e) { - throw new UploadFileException($e->getMessage()); - } - - } - - /** - * 删除文件 - * @param $file_name - * @return bool|mixed - */ - public function delete(string $file_name) - { - $bucket = $this->config['bucket']; - try { - $this->client()->deleteObject($bucket, $file_name); - return true; - } catch (OssException $e) { - throw new UploadFileException($e->getMessage()); - } - - } - - -} diff --git a/niucloud/extend/driver/file/storage/Local.php b/niucloud/extend/driver/file/storage/Local.php deleted file mode 100644 index d20d5722a..000000000 --- a/niucloud/extend/driver/file/storage/Local.php +++ /dev/null @@ -1,88 +0,0 @@ -file->move($dir, $this->file_name); - //错误一般是已经被抛出了 - return true; - } - - - /** - * 远程获取图片 - * @param $url - * @param $key - * @return true - */ - public function fetch(string $url, ?string $key) - { - try { - mkdirs($key); - $content = @file_get_contents($url); - if (!empty($content)) { - file_put_contents($key, $content); -// $fp = fopen($key, "w"); -// fwrite($fp, $content); -// fclose($fp); - }else{ - throw new UploadFileException(203006); - } - return true; - } catch ( Exception $e ) { - throw new UploadFileException($e->getMessage()); - } - } - - /** - * base64转图片 - * @param string $content - * @param string|null $key - * @return void - */ - public function base64(string $content, ?string $key){ - - mkdirs($key); - file_put_contents(url_to_path($key), base64_decode($content)); - return true; - } - - /** - * 删除本地附件 - * @param $file_name - * @return bool|mixed - */ - public function delete(string $file_name) - { - $file_path = url_to_path($file_name); - if (!file_exists($file_path)) { - return true; -// throw new UploadFileException(100013); - } - return unlink($file_path); - } -} \ No newline at end of file diff --git a/niucloud/extend/driver/file/storage/Qcloud.php b/niucloud/extend/driver/file/storage/Qcloud.php deleted file mode 100644 index 23dc9243e..000000000 --- a/niucloud/extend/driver/file/storage/Qcloud.php +++ /dev/null @@ -1,119 +0,0 @@ -config['access_key']; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.tencentcloud.com/cam/capi - $secret_key = $this->config['secret_key']; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.tencentcloud.com/cam/capi - $region = $this->config['region']; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.tencentcloud.com/cos5/bucket - - return new Client( - array( - 'region' => $region, -// 'schema' => 'https', //协议头部,默认为http - 'credentials' => array( - 'secretId' => $secret_id, - 'secretKey' => $secret_key) - ) - ); - } - - - /** - * 执行上传 - * @param $save_dir (保存路径) - * @return bool|mixed - */ - public function upload(string $dir) - { - $bucket = $this->config['bucket']; - try { - $result = $this->app()->putObject(array( - 'Bucket' => $bucket, //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket - 'Key' => $this->getFullPath(), - 'Body' => fopen($this->getRealPath(), 'rb'), - )); - // 请求成功 - return true; - } catch ( Exception $e ) { - throw new UploadFileException($e->getMessage()); - } - } - - /** - * notes: 抓取远程资源(最大支持上传5G文件) - * @param $url - * @param null $key - * @return mixed|void - */ - public function fetch(string $url, ?string $key = null) - { - - $bucket = $this->config['bucket']; - try { - $result = $this->app()->putObject(array( - 'Bucket' => $bucket, //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket - 'Key' => $key, - 'Body' => fopen($url, 'rb'), - )); - // 请求成功 - return true; - } catch ( Exception $e ) { - throw new UploadFileException($e->getMessage()); - } - } - - /** - * 删除一个简单对象 - * @param $file_name - * @return bool|mixed - */ - public function delete(string $file_name) - { - $bucket = $this->config['bucket']; - try { - $this->app()->deleteObject(array( - 'Bucket' => $bucket, - 'Key' => $file_name - )); - return true; - } catch ( Exception $e ) { - throw new UploadFileException($e->getMessage()); - } - } - -} diff --git a/niucloud/extend/driver/file/storage/Qiniu.php b/niucloud/extend/driver/file/storage/Qiniu.php deleted file mode 100644 index dd0828e11..000000000 --- a/niucloud/extend/driver/file/storage/Qiniu.php +++ /dev/null @@ -1,100 +0,0 @@ -config['access_key']; - $secret_key = $this->config['secret_key']; - return new Auth($access_key, $secret_key); - } - public function upload(string $dir) - { - $bucket = $this->config['bucket']; - - - //todo 这儿可以定义凭证的过期时间 - $up_token = $this->auth()->uploadToken($bucket); - - // 初始化 UploadManager 对象并进行文件的上传。 - $upload_mgr = new UploadManager(); - list($ret, $err) = $upload_mgr->putFile($up_token, $this->getFullPath(), $this->getRealPath()); - if ($err !== null) - throw new UploadFileException($err->message()); - return true; - } - - /** - * 抓取网络资源到空间 - * @param $url - * @param $key - * @return true - * @throws Exception - */ - public function fetch(string $url, ?string $key = null) - { - $bucket = $this->config['bucket']; - $auth = $this->auth(); - if(!str_contains($url, 'http://') && !str_contains($url, 'https://')){ - $token = $auth->uploadToken($bucket); - $upload_mgr = new UploadManager(); - list($ret, $err) = $upload_mgr->putFile($token, $key, $url); - }else{ - //抓取网络资源到空间 - $bucket_manager = new BucketManager($auth); - list($ret, $err) = $bucket_manager->fetch($url, $bucket, $key);//不指定key时,以文件内容的hash作为文件名 - } - - if ($err !== null) - throw new UploadFileException($err->message()); - return true; - } - - /** - * 删除空间中的文件 - * @param $file_name - * @return bool|mixed - */ - public function delete(string $file_name) - { - $bucket = $this->config['bucket']; - $auth = $this->auth(); - $config = new Config(); - $bucket_manager = new BucketManager($auth, $config); - $err = $bucket_manager->delete($bucket, $file_name); - if ($err !== null) - throw new UploadFileException($err->message()); - return true; - } -} \ No newline at end of file diff --git a/niucloud/extend/driver/pay/BasePay.php b/niucloud/extend/driver/pay/BasePay.php deleted file mode 100644 index 7b7005050..000000000 --- a/niucloud/extend/driver/pay/BasePay.php +++ /dev/null @@ -1,130 +0,0 @@ - [ - 'enable' => true, - 'file' => runtime_path() . 'paylog'.DIRECTORY_SEPARATOR.date('Ym').DIRECTORY_SEPARATOR.date('d').'.log', - 'level' => env('app_debug') ? 'debug' : 'info', // 建议生产环境等级调整为 info,开发环境为 debug - 'type' => 'single', // optional, 可选 daily. - 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天 - ], - 'http' => [ // optional - 'timeout' => 5.0, - ] - ], - [ - $type => [ - 'default' => $config - ] - ] - - - ); - } - - public function returnFormat($param){ - if($param instanceof \Psr\Http\Message\MessageInterface){ - return $param->getBody()->getContents(); - }else if($param instanceof \Yansongda\Supports\Collection){ - return $param->all(); - }else{ - return $param; - } - } - - - - -} \ No newline at end of file diff --git a/niucloud/extend/driver/pay/PayDriver.php b/niucloud/extend/driver/pay/PayDriver.php deleted file mode 100644 index 28dc01766..000000000 --- a/niucloud/extend/driver/pay/PayDriver.php +++ /dev/null @@ -1,58 +0,0 @@ -config = $config; - - $this->driver = $this->getDriverClass($type); - } - - /** - * 获取启用的存储引擎 - */ - public function getDriverClass(string $type){ - - $class = __NAMESPACE__ . '\\driver\\' . ucfirst(strtolower($type)); - return new $class($this->config); - } - - - - /** - * 动态调用 - * @param $method - * @param $arguments - * @return mixed - */ - public function __call($method, $arguments) - { - return $this->driver->{$method}(...$arguments); - } -} \ No newline at end of file diff --git a/niucloud/extend/driver/pay/driver/Alipay.php b/niucloud/extend/driver/pay/driver/Alipay.php deleted file mode 100644 index 9e2ad147d..000000000 --- a/niucloud/extend/driver/pay/driver/Alipay.php +++ /dev/null @@ -1,290 +0,0 @@ -config = $this->payConfig($config, 'alipay'); - Pay::config($this->config); - - } - - /** - * 网页支付 - * @param array $params - * @return ResponseInterface - */ - public function web(array $params) - { - return $this->retutnUrl(Pay::alipay()->web([ - 'out_trade_no' => $params['out_trade_no'], - 'total_amount' => $params['money'], - 'subject' => $params['boby'], - ])); - } - - /** - * 手机网页支付 - * @param array $params - * @return ResponseInterface - */ - public function wap(array $params) - { - return $this->retutnUrl(Pay::alipay()->wap([ - 'out_trade_no' => $params['out_trade_no'], - 'total_amount' => $params['money'], - 'subject' => $params['boby'], - 'quit_url' => $params['quit_url'] ?? '',//用户付款中途退出返回商户网站的地址, 一般是商品详情页或购物车页 - '_method' => 'get', - ])); - } - - /** - * app支付 - * @param $params - * @return mixed|ResponseInterface - */ - public function app(array $params) - { - return $this->retutnUrl(Pay::alipay()->app([ - 'out_trade_no' => $params['out_trade_no'], - 'total_amount' => $params['money'], - 'subject' => $params['boby'],//用户付款中途退出返回商户网站的地址, 一般是商品详情页或购物车页 - ])); - } - - /** - * 小程序支付 - * @param $params - * @return mixed|ResponseInterface - */ - public function mini(array $params) - { - return Pay::alipay()->mini([ - 'out_trade_no' => $params['out_trade_no'], - 'total_amount' => $params['money'], - 'subject' => $params['boby'], - 'buyer_id' => $params['buyer_id'],//买家支付宝用户ID 注:交易的买家与卖家不能相同。 - ]); - } - - /** - * 付款码支付 - * @param $params - * @return mixed|Collection - */ - public function pos(array $params) - { - return Pay::alipay()->pos([ - 'out_trade_no' => $params['out_trade_no'], - 'auth_code' => $params['auth_code'],//付授权码。 当面付场景传买家的付款码(25~30开头的长度为16~24位的数字,实际字符串长度以开发者获取的付款码长度为准)或者刷脸标识串(fp开头的35位字符串)。 - 'total_amount' => $params['money'], - 'subject' => $params['boby'], - ]); - } - - /** - * 扫码支付 - * @param $params - * @return mixed|Collection - */ - public function scan(array $params) - { - return Pay::alipay()->scan([ - 'out_trade_no' => $params['out_trade_no'], - 'total_amount' => $params['money'], - 'subject' => $params['boby'], - ]); - } - - /** - * 转账 - * @param $params - * @return mixed|Collection - */ - public function transfer(array $params) - { - - $result = $this->returnFormat(Pay::alipay()->transfer([ - 'out_biz_no' => $params['transfer_no'], - 'trans_amount' => $params['money'], - 'product_code' => $params['product_code'] ?: 'TRANS_ACCOUNT_NO_PWD',//业务产品码,单笔无密转账到支付宝账户固定为 : TRANS_ACCOUNT_NO_PWD; 收发现金红包固定为 : STD_RED_PACKET; - 'biz_scene' => $params['scene'] ?: 'DIRECT_TRANSFER',//描述特定的业务场景,可传的参数如下:DIRECT_TRANSFER:单笔无密转账到支付宝,B2C现金红包;PERSONAL_COLLECTION:C2C现金红包-领红包 - 'payee_info' => [//收款方信息 - 'identity' => $params['to_no'],//参与方的唯一标识 - 'identity_type' => $params['to_type'] ?: 'ALIPAY_LOGON_ID',//参与方的标识类型,目前支持如下类型:1、ALIPAY_USER_ID 支付宝的会员ID2、ALIPAY_LOGON_ID:支付宝登录号,支持邮箱和手机号格式3、ALIPAY_OPEN_ID:支付宝openid - 'name' => $params['to_name'],//参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。当identity_type=ALIPAY_LOGON_ID时,本字段必填。 - ], - ])); - if(!empty($result['msg']) && $result['msg'] != 'Success'){ - throw new PayException($result['sub_msg']); - - }else{ - if($result['status'] == 'SUCCESS'){ - $result = array( - 'batch_id' => $result['pay_fund_order_id'] - ); - }else if($result['status'] == 'FAIL' && !empty($result['fail_reason'])){ - throw new PayException($result['fail_reason']); - } - } - return $result; - } - - /** - * 支付关闭 - * @param $out_trade_no - * @return void - */ - public function close(string|int $out_trade_no){ - $result = $this->returnFormat(Pay::alipay()->close([ - 'out_trade_no' => $out_trade_no, - ])); - //todo 支付宝关闭异步回调 - if(!empty($result['msg']) && $result['msg'] == 'Success'){ - return true; - }else{ - return false; - } - } - - /** - * 退款 - * @param $out_trade_no - * @param $money - * @return array|MessageInterface|Collection|null - * @throws ContainerException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - public function refund(string|int $out_trade_no, float $money){ - $result = Pay::alipay()->refund([ - 'out_trade_no' => $out_trade_no, - 'refund_amount' => $money, - ]); - return $result; - } - - - /** - * 支部异步回调 - * @param $out_trade_no - * @return void - */ - public function notify(Callable $callback){ - try{ - $result = Pay::alipay()->callback(); - //通过返回的值 - if(!empty($result)){//成功 - //todo 这儿需要具体设计 - $temp_data = array( - 'mchid' => $result['seller_id'], - 'trade_no' => $result['trade_no'], - 'result' => $result - ); - $callback_result = $callback($result['out_trade_no'], $temp_data); - if(is_bool($callback_result) && $callback_result){ - return Pay::alipay()->success(); - } - } - return $this->fail(); - } catch (\Throwable $e) { - return $this->fail(); - } - - - } - - /** - * 查询普通支付订单 - * @param $out_trade_no - * @return void - */ - public function getOrder(string $out_trade_no){ - $order = [ - 'out_trade_no' => $out_trade_no, - ]; - $result = $this->returnFormat(Pay::alipay()->find($order)); - if(!empty($result['msg']) && $result['msg'] == 'Success'){ - return [ - 'status' => OnlinePayEnum::getAliPayStatus($result['trade_status']) - ]; - }else{ - if(!empty($result['sub_code']) && $result['sub_code'] == 'ACQ.ACQ.SYSTEM_ERROR'){ - throw new PayException($result['msg']); - }else{ - return []; - } - } - } - - /** - * 查询退款单据 - * @param $out_trade_no - * @param $refund_no - * @return void - */ - public function getRefund(string $out_trade_no, ?string $refund_no){ - $order = [ - 'out_trade_no' => $out_trade_no, - 'out_request_no' => $refund_no, - '_type' => 'refund', - ]; - - $result = $this->returnFormat(Pay::alipay()->find($order)); - return $result; - } - - /** - * 获取转账订单 - * @param $transfer_no - * @return void - */ - public function getTransfer(string $transfer_no){ - $order = [ - 'out_biz_no' => $transfer_no, - '_type' => 'transfer' - ]; - $result = $this->returnFormat(Pay::alipay()->find($order)); - return $result; - } - - public function fail(){ - return 'fail'; - } - - public function retutnUrl($params){ - return ['url' => $params->getHeader('Location')[0]]; - } -} \ No newline at end of file diff --git a/niucloud/extend/driver/pay/driver/Wechatpay.php b/niucloud/extend/driver/pay/driver/Wechatpay.php deleted file mode 100644 index 94bd36cdd..000000000 --- a/niucloud/extend/driver/pay/driver/Wechatpay.php +++ /dev/null @@ -1,367 +0,0 @@ -config = $config; - $config['mch_secret_cert'] = url_to_path($config['mch_secret_cert']); - $config['mch_public_cert_path'] = url_to_path($config['mch_public_cert_path']); -// $config['notify_url'] = ''; -// $config['wechat_public_cert_path'] = url_to_path('upload/pay'); - Pay::config($this->payConfig($config, 'wechat')); - } - - /** - * 公众号支付 - * @param array $params - * @return mixed|Collection - */ - public function mp(array $params){ - return $this->returnFormat(Pay::wechat()->mp([ - 'out_trade_no' => $params['out_trade_no'], - 'description' => $params['boby'], - 'amount' => [ - 'total' => $params['money'], - ], - 'payer' => [ - 'openid' => $params['openid'], - ], - ])); - } - - - /** - * 手机网页支付 - * @param $params - * @return mixed - */ - public function wap(array $params) - { - $order = [ - 'out_trade_no' => $params['out_trade_no'], - 'description' => $params['boby'], - 'amount' => [ - 'total' => $params['money'], - ], - 'scene_info' => [ - 'payer_client_ip' => request()->ip(), - 'h5_info' => [ - 'type' => 'Wap', - ] - ], - ]; - //这儿有些特殊, 默认情况下,H5 支付所使用的 appid 是微信公众号的 appid,即配置文件中的 mp_app_id 参数,如果想使用关联的小程序的 appid,则只需要在调用参数中增加 ['_type' => 'mini'] 即可 - if(!empty($order['type'])){ - $order['_type'] = 'mini'; // 注意这一行 - } - return $this->returnFormat(Pay::wechat()->wap($order)); - } - - /** - * app支付 - * @param $params - * @return mixed|ResponseInterface - */ - public function app(array $params) - { - return $this->returnFormat(Pay::wechat()->app([ - 'out_trade_no' => $params['out_trade_no'], - 'description' => $params['boby'], - 'amount' => [ - 'total' => $params['money'], - ], - ])); - } - - /** - * 小程序支付 - * @param $params - * @return mixed|ResponseInterface - */ - public function mini(array $params) - { - return $this->returnFormat(Pay::wechat()->mini([ - 'out_trade_no' => $params['out_trade_no'], - 'description' => $params['boby'], - 'amount' => [ - 'total' => $params['money'], - 'currency' => 'CNY',//一般是人民币 - ], - 'payer' => [ - 'openid' => $params['openid'], - ] - ])); - } - - /** - * 付款码支付 - * @param $params - * @return mixed|Collection - */ - public function pos(array $params) - { - //todo 需要自定义通过plugin来侧载开发 - $app = Factory::payment([ - 'app_id' => $this->config['appid'], //应用id - 'mch_id' => $this->config["mch_id"] ?? '', //商户号 - 'key' => $this->config["pay_v2_signkey"] ?? '', // API 密钥 todo 注意: 是v2密钥 是v2密钥 是v2密钥 - 'response_type' => 'array', - 'log' => [ - 'level' => 'debug', - 'permission' => 0777, - 'file' => 'runtime/log/wechat/easywechat.logs', - ], - 'sandbox' => false, // 设置为 false 或注释则关闭沙箱模式 - ]); - $data = [ - 'body' => $params['boby'], - 'out_trade_no' => $params['out_trade_no'], - 'total_fee' => $params['money'], - 'auth_code' => $params["auth_code"],//传入的付款码 - ]; - $result = $app->base->pay($data);//没有注释路由,调用没有问题 - return $this->returnFormat($result); - } - - /** - * 扫码支付 - * @param $params - * @return mixed|Collection - */ - public function scan(array $params) - { - return $this->returnFormat(Pay::wechat()->scan([ - 'out_trade_no' => $params['out_trade_no'], - 'description' => $params['boby'], - 'amount' => [ - 'total' => $params['money'], - ], - ])); - } - - /** - * 转账(微信的转账是很多笔的) - * @param $params - * @return mixed|Collection - */ - public function transfer(array $params) - { - //这儿的批次信息可能是这儿生成的,但依然需要记录 - $order = [ - 'out_batch_no' => time().'',// - 'batch_name' => $params['remark'], - 'batch_remark' => $params['remark'], - ]; - $transfer_list = $params['transfer_list']; - //单笔转账 - if(empty($transfer_list)){ - $transfer_list = array( - [ - 'transfer_no' => $params['transfer_no'].'1', - 'money' => (int)$params['money'], - 'remark' => $params['remark'], - 'openid' => $params['to_no'] - ] - ); - } - $total_amount = 0; - $total_num = 0; - - foreach($transfer_list as $v){ - $item_transfer = [ - 'out_detail_no' => time().'1', - 'transfer_amount' => (int)$v['money'], - 'transfer_remark' => $v['remark'], - 'openid' => $v['openid'], - ]; - $total_amount += (int)$v['money']; - $total_num++; - if(!empty($v['user_name'])){ - $item_transfer['user_name'] = $v['user_name'];// 明文传参即可,sdk 会自动加密 - } - $order['transfer_detail_list'][] = $item_transfer; - } - $order['total_amount'] = (int)$total_amount; - $order['total_num'] = (int)$total_num; - $result = $this->returnFormat(Pay::wechat()->transfer($order)); - - if(!empty($result['code'])){ -// if($result['code'] == 'PARAM_ERROR'){ -// throw new PayException(); -// }else if($result['code'] == 'INVALID_REQUEST'){ -// throw new PayException(); -// } - if($result['code'] == 'INVALID_REQUEST'){ - throw new PayException(700010); - } - throw new PayException($result['message']); - } - return ['batch_id' => $result['batch_id'], 'out_batch_no' => $result['out_batch_no']]; - } - - /** - * 支付关闭 - * @param $out_trade_no - * @return void - */ - public function close(string|int $out_trade_no){ - $result = Pay::wechat()->close([ - 'out_trade_no' => $out_trade_no, - ]); - return $this->returnFormat($result); - } - - /** - * 退款 - * @param $out_trade_no - * @param $money - * @return array|MessageInterface|Collection|null - * @throws ContainerException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - public function refund(string|int $out_trade_no, float $money, $refund_no, float $total){ - $result = Pay::wechat()->refund([ - 'out_trade_no' => $out_trade_no, - 'out_refund_no' => $refund_no, - 'amount' => [ - 'refund' => $money, - 'total' => $total, - 'currency' => 'CNY', - ], - ]); - return $this->returnFormat($result); - } - - - /** - * 支部异步回调 - * @param $out_trade_no - * @return void - */ - public function notify(Callable $callback){ - try{ - $result = $this->returnFormat(Pay::wechat()->callback()); - if($result['event_type'] == 'TRANSACTION.SUCCESS'){ - $pay_trade_data = $result['resource']['ciphertext']; - $temp_params = [ - 'trade_no' => $pay_trade_data['transaction_id'], - 'mch_id' => $pay_trade_data['mchid'] - ]; - $callback_result = $callback($pay_trade_data['out_trade_no'], $temp_params); - if(is_bool($callback_result) && $callback_result){ - return Pay::wechat()->success(); - } - } - return $this->fail(); - - } catch (\Throwable $e) { -// throw new PayException($e->getMessage()); - return $this->fail($e->getMessage()); - } - } - - /** - * 查询普通支付订单 - * @param string $out_trade_no - * @param string $transaction_id - * @return array|MessageInterface|Collection|null - * @throws ContainerException - * @throws InvalidParamsException - * @throws ServiceNotFoundException - */ - public function getOrder(string $out_trade_no = '', string $transaction_id = ''){ - $order = [ - - ]; - if(!empty($out_trade_no)){ - $order['out_trade_no'] = $out_trade_no; - } - if(!empty($transaction_id)){ - $order['transaction_id'] = $transaction_id; - } - $result = Pay::wechat()->find($order); - if(empty($result)) - return $result; - $result = $this->returnFormat($result); - return [ - 'status' => OnlinePayEnum::getWechatPayStatus($result['trade_state']), - ]; - } - - /** - * 查询退款单据 - * @param $out_trade_no - * @param $refund_no - * @return void - */ - public function getRefund(?string $out_trade_no, ?string $refund_no = ''){ - $order = [ - '_type' => 'refund', - 'out_refund_no' => $refund_no - ]; - $result = Pay::wechat()->find($order); - return $this->returnFormat($result); - } - - /** - * 获取转账订单(todo 切勿调用) - * @param $transfer_no - * @return void - */ - public function getTransfer(string $transfer_no){ - - - $params = [ - 'out_batch_no' => $transfer_no, - ]; - - $allPlugins = Pay::wechat()->mergeCommonPlugins([QueryOutBatchNoPlugin::class]); - - $result = Pay::wechat()->pay($allPlugins, $params); - return $this->returnFormat($result); - } - - - public function fail($message = ''){ - $response = [ - 'code' => 'FAIL', - 'message' => $message ?: '失败', - ]; - return response($response, 400, [], 'json'); - } -} \ No newline at end of file diff --git a/niucloud/extend/driver/sms/SmsDriver.php b/niucloud/extend/driver/sms/SmsDriver.php deleted file mode 100644 index f730eae91..000000000 --- a/niucloud/extend/driver/sms/SmsDriver.php +++ /dev/null @@ -1,101 +0,0 @@ -initialize($config); - } - - - public function initialize($config) - { - try { - - $classSpace = __NAMESPACE__ . '\\driver\\' . ucfirst(strtolower($config['sms_type'])) . 'Sms'; - if (!class_exists($classSpace)) { - throw new CommonException(204003); - } - $this->driver = new $classSpace($config); - if(!is_null($this->driver->getError())) { - throw new CommonException($this->driver->getError()); - } - return true; - } catch ( Exception $e) { - $this->error = $e->getMessage(); - return false; - } - } - - /** - * 获取短信错误 - * @return null - */ - public function getError() - { - return $this->error; - } - - /** - * 发送短信 - * @param $mobile - * @param $data - * @return bool - */ - public function send($mobile, $data) - { - try { - // 开始发送 - $result = $this->driver - ->setMobile($mobile) - ->setTemplateId($data['template_id']) - ->setTemplateParams($data['params']) - ->send(); - if(false === $result) { - throw new MessageException($this->driver->getError()); - } - return $result; - } catch( Exception $e) { - $this->error = $e->getMessage(); - return false; - } - } -} \ No newline at end of file diff --git a/niucloud/extend/driver/sms/driver/AliSms.php b/niucloud/extend/driver/sms/driver/AliSms.php deleted file mode 100644 index ae75cd424..000000000 --- a/niucloud/extend/driver/sms/driver/AliSms.php +++ /dev/null @@ -1,107 +0,0 @@ -config = $config; - } - - /** - * 获取错误 - * @return null - */ - public function getError() - { - return $this->error; - } - - /** - * 设置发送手机 - * @param $mobile - * @return $this - */ - public function setMobile($mobile) - { - $this->mobile = $mobile; - return $this; - } - - - /** - * 设置发送模板 - * @param $templateId - * @return $this - */ - public function setTemplateId($templateId) - { - $this->templateId = $templateId; - return $this; - } - - - /** - * 设置模板参数 - * @param $templateParams - * @return $this - */ - public function setTemplateParams($templateParams) - { - $this->templateParams = json_encode($templateParams, JSON_UNESCAPED_UNICODE); - return $this; - } - - /** - * 发送短信 - * @return array|bool - */ - public function send() - { - try { - AlibabaCloud::accessKeyClient($this->config['app_key'], $this->config['secret_key']) - ->regionId('cn-hangzhou') - ->asDefaultClient(); - - $result = AlibabaCloud::rpcRequest() - ->product('Dysmsapi') - ->host('dysmsapi.aliyuncs.com') - ->version('2017-05-25') - ->action('SendSms') - ->method('POST') - ->debug(false) - ->options([ - 'query' => [ - 'PhoneNumbers' => $this->mobile, - 'SignName' => $this->config['sign'], - 'TemplateCode' => $this->templateId, - 'TemplateParam' => $this->templateParams, - ], - ]) - ->request(); - - $res = $result->toArray(); - if (isset($res['Code']) && $res['Code'] == 'OK') { - return $res; - } - $message = $res['Message'] ?? $res; - throw new MessageException($message); - } catch( Exception $e) { - $this->error = $e->getMessage(); - return false; - } - } -} \ No newline at end of file diff --git a/niucloud/extend/driver/sms/driver/TencentSms.php b/niucloud/extend/driver/sms/driver/TencentSms.php deleted file mode 100644 index 7d06a1e44..000000000 --- a/niucloud/extend/driver/sms/driver/TencentSms.php +++ /dev/null @@ -1,109 +0,0 @@ -config = $config; - } - - /** - * 获取错误 - * @return null - */ - public function getError() - { - return $this->error; - } - - /** - * 设置发送的手机号 - * @param $mobile - * @return $this - */ - public function setMobile($mobile) - { - $this->mobile = $mobile; - return $this; - } - - /** - * 设置模板ID - * @param $templateId - * @return $this - */ - public function setTemplateId($templateId) - { - $this->templateId = $templateId; - return $this; - } - - /** - * 设置短信对应参数 - * @param $templateParams - * @return $this - */ - public function setTemplateParams($templateParams) - { - $this->templateParams = $templateParams; - return $this; - } - - /** - * 发送短信 - * @return bool|mixed - */ - public function send() - { - try { - $cred = new Credential($this->config['secret_id'], $this->config['secret_key']); - $httpProfile = new HttpProfile(); - $httpProfile->setEndpoint("sms.tencentcloudapi.com"); - - $clientProfile = new ClientProfile(); - $clientProfile->setHttpProfile($httpProfile); - - $client = new SmsClient($cred, 'ap-guangzhou', $clientProfile); - $params = [ - 'PhoneNumberSet' => ['+86' . $this->mobile], - 'TemplateID' => $this->templateId, - 'Sign' => $this->config['sign'], - 'TemplateParamSet' => $this->templateParams, - 'SmsSdkAppid' => $this->config['app_id'], - ]; - $req = new SendSmsRequest(); - $req->fromJsonString(json_encode($params)); - $resp = json_decode($client->SendSms($req)->toJsonString(), true); - if (isset($resp['SendStatusSet']) && $resp['SendStatusSet'][0]['Code'] == 'Ok') { - return $resp; - } else { - $message = $res['SendStatusSet'][0]['Message'] ?? json_encode($resp); - throw new CommonException( $message); - } - } catch( Exception $e) { - $this->error = $e->getMessage(); - return false; - } - } -} \ No newline at end of file diff --git a/niucloud/extend/exception/AdminException.php b/niucloud/extend/exception/AdminException.php deleted file mode 100644 index c72a1c3f3..000000000 --- a/niucloud/extend/exception/AdminException.php +++ /dev/null @@ -1,19 +0,0 @@ -path = $path; - $this->config = $init; - $this->unique_key = $unique_key; - } - - /** - * 加载配置文件(多种格式) - * @access public - * @param string $file 配置文件名 - * @param string $name 一级配置名 - * @return array - */ - public function loadConfig(): array - { - $this->praseFiles($this->path); - - if(!empty($this->files)) - { - foreach ($this->files as $file) - { - $config = include $file; - - if(empty($this->config)) - { - $this->config = $config; - }else{ - if(!empty($config)) - { - if($this->unique_key) - { - $this->config = $this->config + $config; - }else - $this->config = array_merge($this->config, $config); - - } - } - } - } - - return $this->config; - } - - /** - * 加载返回所有文件 - */ - public function loadFiles() - { - $this->praseFiles($this->path); - return $this->files; - } - - /** - * 整理所有文件 - * @param string $path - */ - protected function praseFiles(string $path) - { - $files = scandir($path); - foreach ($files as $file) { - if ($file != '.' && $file != '..') { - if (is_dir($path . DIRECTORY_SEPARATOR . $file)) { - $this->praseFiles($path . DIRECTORY_SEPARATOR . $file); - } else { - $this->files[] = $path . DIRECTORY_SEPARATOR . $file; - } - } - } - } - - -} diff --git a/niucloud/extend/util/TokenUtil.php b/niucloud/extend/util/TokenUtil.php deleted file mode 100644 index 5e39d90ab..000000000 --- a/niucloud/extend/util/TokenUtil.php +++ /dev/null @@ -1,107 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace extend\util; - -use Firebase\JWT\JWT; -use think\facade\Cache; -use think\facade\Env; - - -/** - * token工具类 - * Class TokenUtil - * @package extend\util - */ -class TokenUtil -{ - private $token; - - /** - *创建token - * @param int $id 编码 一般传入用户id - * @param string $type 类型(admin,site,home) - * @param array $params 参数 传入id, name - * @param int $expire_time 有效期 - * @return array - */ - public static function createToken(int $id, string $type, array $params = [], int $expire_time = 0): array - { - $host = app()->request->host(); - $time = time(); - $params += [ - 'iss' => $host, - 'aud' => $host, - 'iat' => $time, - 'nbf' => $time, - 'exp' => $time + $expire_time, - ]; - - $params['jti'] = $id . "_" . $type; - $token = JWT::encode($params, Env::get('app.app_key', 'niushop456$%^')); - $cache_token = Cache::get("token_" . $params['jti']); - $cache_token_arr = $cache_token ?: []; -// if(!empty($cache_token)) -// { -// -// $cache_token_arr[] = $token; -// } - $cache_token_arr[] = $token; - Cache::tag("token")->set("token_" . $params['jti'], $cache_token_arr); - return compact('token', 'params'); - } - - /** - * 解析token - * @param string $token - * @param string $type - * @return array - */ - public static function parseToken(string $token, string $type): array - { - $payload = JWT::decode($token, Env::get('app.app_key', 'niushop456$%^'), ['HS256']); - if (!empty($payload)) { - $token_info = json_decode(json_encode($payload), true); - - if (explode("_", $token_info['jti'])[1] != $type) { - return []; - } - if (!empty($token_info) && !in_array($token, Cache::get('token_' . $token_info['jti'], []))) { - return []; - } - return $token_info; - } else { - return []; - } - } - - /** - * 清理token - * @param int $id - * @param string $type - */ - public static function clearToken(int $id, string $type, ?string $token = '') - { - if (!empty($token)) { - $token_cache = Cache::get("token_" . $id . "_" . $type, []); - //todo 也可以通过修改过期时间来实现 - if (!empty($token_cache)) { - if (($key = array_search($token, $token_cache)) !== false) { - array_splice($token_cache, $key, 1); - } - Cache::set("token_" . $id . "_" . $type, $token_cache); - } - } else { - Cache::set("token_" . $id . "_" . $type, []); - } - return success(); - } -} diff --git a/niucloud/route/app.php b/niucloud/route/app.php index 8bcc537a8..6dd67690f 100644 --- a/niucloud/route/app.php +++ b/niucloud/route/app.php @@ -24,6 +24,14 @@ Route::rule('/', function () { Route::rule('admin/:any', function () { return view(app()->getRootPath() . 'public/admin/index.html'); })->pattern(['any' => '\w+']); +// 站点端 +Route::rule('site/:any', function () { + return view(app()->getRootPath() . 'public/admin/index.html'); +})->pattern(['any' => '\w+']); +// 装修端 +Route::rule('decorate/:any', function () { + return view(app()->getRootPath() . 'public/admin/index.html'); +})->pattern(['any' => '\w+']); // 手机端 Route::rule('wap/:any', function () { return view(app()->getRootPath() . 'public/wap/index.html');