mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-02-05 21:25:36 +00:00
格式化服务类
This commit is contained in:
parent
d236a9da93
commit
5fead1d61a
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace crmeb\services;
|
namespace crmeb\services;
|
||||||
|
|
||||||
use app\models\store\StoreBargain;
|
use app\models\store\StoreBargain;
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class ExpressService
|
|||||||
|
|
||||||
public static function query($no, $type = '')
|
public static function query($no, $type = '')
|
||||||
{
|
{
|
||||||
$appCode = SystemConfigService::config('system_express_app_code');
|
$appCode = sysConfig('system_express_app_code');
|
||||||
if (!$appCode) return false;
|
if (!$appCode) return false;
|
||||||
$res = HttpService::getRequest(self::$api['query'], compact('no', 'type'), ['Authorization:APPCODE ' . $appCode]);
|
$res = HttpService::getRequest(self::$api['query'], compact('no', 'type'), ['Authorization:APPCODE ' . $appCode]);
|
||||||
$result = json_decode($res, true) ?: false;
|
$result = json_decode($res, true) ?: false;
|
||||||
|
|||||||
@ -506,6 +506,8 @@ class FileService
|
|||||||
{
|
{
|
||||||
$handle = @opendir($dir);//打开指定目录
|
$handle = @opendir($dir);//打开指定目录
|
||||||
$directory_count = 0;
|
$directory_count = 0;
|
||||||
|
$total_size = 0;
|
||||||
|
$file_cout = 0;
|
||||||
while (FALSE !== ($file_path = readdir($handle)))
|
while (FALSE !== ($file_path = readdir($handle)))
|
||||||
{
|
{
|
||||||
if($file_path != "." && $file_path != "..")
|
if($file_path != "." && $file_path != "..")
|
||||||
|
|||||||
@ -27,7 +27,8 @@ class FormBuilder extends Form
|
|||||||
* str 自定义
|
* str 自定义
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public static function make_post_form($title,array $field,$url,$jscallback = 2){
|
public static function make_post_form($title, array $field, $url, $jscallback = 2)
|
||||||
|
{
|
||||||
$form = Form::create($url);//提交地址
|
$form = Form::create($url);//提交地址
|
||||||
$form->setMethod('POST');//提交方式
|
$form->setMethod('POST');//提交方式
|
||||||
$form->components($field);//表单字段
|
$form->components($field);//表单字段
|
||||||
|
|||||||
@ -93,7 +93,7 @@ class GroupDataService
|
|||||||
if ($isCaChe)
|
if ($isCaChe)
|
||||||
return $callable();
|
return $callable();
|
||||||
|
|
||||||
return CacheService::get($cacheName,$cacheName);
|
return CacheService::get($cacheName, $callable);
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
* @author: xaboy<365615158@qq.com>
|
* @author: xaboy<365615158@qq.com>
|
||||||
* @day: 2017/11/23
|
* @day: 2017/11/23
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace crmeb\services;
|
namespace crmeb\services;
|
||||||
|
|
||||||
class HttpService
|
class HttpService
|
||||||
|
|||||||
@ -17,6 +17,7 @@ class JsonService
|
|||||||
{
|
{
|
||||||
exit(json_encode(compact('code', 'msg', 'data', 'count')));
|
exit(json_encode(compact('code', 'msg', 'data', 'count')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function successlayui($count = 0, $data = [], $msg = '')
|
public static function successlayui($count = 0, $data = [], $msg = '')
|
||||||
{
|
{
|
||||||
if (is_array($count)) {
|
if (is_array($count)) {
|
||||||
@ -29,6 +30,7 @@ class JsonService
|
|||||||
}
|
}
|
||||||
return self::result(0, $msg, $data, $count);
|
return self::result(0, $msg, $data, $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function successful($msg = 'ok', $data = [], $status = 200)
|
public static function successful($msg = 'ok', $data = [], $status = 200)
|
||||||
{
|
{
|
||||||
if (false == is_string($msg)) {
|
if (false == is_string($msg)) {
|
||||||
|
|||||||
@ -11,8 +11,6 @@ use crmeb\repositories\PaymentRepositories;
|
|||||||
use EasyWeChat\Foundation\Application;
|
use EasyWeChat\Foundation\Application;
|
||||||
use EasyWeChat\Payment\Order;
|
use EasyWeChat\Payment\Order;
|
||||||
use think\facade\Route as Url;
|
use think\facade\Route as Url;
|
||||||
use crmeb\services\HookService;
|
|
||||||
use crmeb\interfaces\ProviderInterface;
|
|
||||||
use app\models\store\StoreOrder as StoreOrderRoutineModel;
|
use app\models\store\StoreOrder as StoreOrderRoutineModel;
|
||||||
use app\models\user\UserRecharge;
|
use app\models\user\UserRecharge;
|
||||||
|
|
||||||
@ -20,15 +18,10 @@ use app\models\user\UserRecharge;
|
|||||||
* Class WechatMinService
|
* Class WechatMinService
|
||||||
* @package service
|
* @package service
|
||||||
*/
|
*/
|
||||||
class MiniProgramService implements ProviderInterface
|
class MiniProgramService
|
||||||
{
|
{
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
|
||||||
public function register($config)
|
|
||||||
{
|
|
||||||
return ['mini_program',new self()];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function options()
|
public static function options()
|
||||||
{
|
{
|
||||||
$wechat = SystemConfigService::more(['site_url', 'routine_appId', 'routine_appsecret']);
|
$wechat = SystemConfigService::more(['site_url', 'routine_appId', 'routine_appsecret']);
|
||||||
@ -50,11 +43,13 @@ class MiniProgramService implements ProviderInterface
|
|||||||
];
|
];
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function application($cache = false)
|
public static function application($cache = false)
|
||||||
{
|
{
|
||||||
(self::$instance === null || $cache === true) && (self::$instance = new Application(self::options()));
|
(self::$instance === null || $cache === true) && (self::$instance = new Application(self::options()));
|
||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序接口
|
* 小程序接口
|
||||||
* @return \EasyWeChat\MiniProgram\MiniProgram
|
* @return \EasyWeChat\MiniProgram\MiniProgram
|
||||||
@ -82,7 +77,8 @@ class MiniProgramService implements ProviderInterface
|
|||||||
* @param $encryptData
|
* @param $encryptData
|
||||||
* @return $userInfo
|
* @return $userInfo
|
||||||
*/
|
*/
|
||||||
public static function encryptor($sessionKey, $iv, $encryptData){
|
public static function encryptor($sessionKey, $iv, $encryptData)
|
||||||
|
{
|
||||||
return self::miniprogram()->encryptor->decryptData($sessionKey, $iv, $encryptData);
|
return self::miniprogram()->encryptor->decryptData($sessionKey, $iv, $encryptData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +199,8 @@ class MiniProgramService implements ProviderInterface
|
|||||||
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
|
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
|
||||||
try {
|
try {
|
||||||
PaymentRepositories::wechatPaymentPrepareProgram($order, $result->prepay_id);
|
PaymentRepositories::wechatPaymentPrepareProgram($order, $result->prepay_id);
|
||||||
}catch (\Exception $e){}
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
return $result->prepay_id;
|
return $result->prepay_id;
|
||||||
} else {
|
} else {
|
||||||
if ($result->return_code == 'FAIL') {
|
if ($result->return_code == 'FAIL') {
|
||||||
@ -324,11 +321,8 @@ class MiniProgramService implements ProviderInterface
|
|||||||
$staff = self::staffService();
|
$staff = self::staffService();
|
||||||
$staff = is_callable($message) ? $staff->message($message()) : $staff->message($message);
|
$staff = is_callable($message) ? $staff->message($message()) : $staff->message($message);
|
||||||
$res = $staff->to($to)->send();
|
$res = $staff->to($to)->send();
|
||||||
HookService::afterListen('wechat_staff_to',compact('to','message'),$res);
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace crmeb\services;
|
namespace crmeb\services;
|
||||||
|
|
||||||
use crmeb\services\JsonService as Json;
|
use crmeb\services\JsonService as Json;
|
||||||
@ -51,13 +52,15 @@ class PHPExcelService
|
|||||||
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER
|
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*初始化PHPExcel类
|
*初始化PHPExcel类
|
||||||
* @param $data array()
|
* @param $data array()
|
||||||
* @param $fun function()
|
* @param $fun function()
|
||||||
* return
|
* return
|
||||||
*/
|
*/
|
||||||
private static function initialize($data,$fun){
|
private static function initialize($data, $fun)
|
||||||
|
{
|
||||||
self::$PHPExcel = new \PHPExcel();
|
self::$PHPExcel = new \PHPExcel();
|
||||||
if ($fun !== null && is_callable($fun)) {
|
if ($fun !== null && is_callable($fun)) {
|
||||||
self::$styleArray = $fun();
|
self::$styleArray = $fun();
|
||||||
@ -65,14 +68,17 @@ class PHPExcelService
|
|||||||
if (!is_array($data)) exit(Json::fail('data 为数组'));
|
if (!is_array($data)) exit(Json::fail('data 为数组'));
|
||||||
self::$data = $data;
|
self::$data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*设置字体格式
|
*设置字体格式
|
||||||
* @param $title string 必选
|
* @param $title string 必选
|
||||||
* return string
|
* return string
|
||||||
*/
|
*/
|
||||||
public static function setUtf8($title){
|
public static function setUtf8($title)
|
||||||
|
{
|
||||||
return iconv('utf-8', 'gb2312', $title);
|
return iconv('utf-8', 'gb2312', $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* execl数据导出
|
* execl数据导出
|
||||||
@ -115,12 +121,14 @@ class PHPExcelService
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存表格数据,并下载
|
* 保存表格数据,并下载
|
||||||
* @param
|
* @param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public function ExcelSave(){
|
public function ExcelSave()
|
||||||
|
{
|
||||||
$objWriter = \PHPExcel_IOFactory::createWriter(self::$PHPExcel, 'Excel2007');
|
$objWriter = \PHPExcel_IOFactory::createWriter(self::$PHPExcel, 'Excel2007');
|
||||||
$filename = self::$title . '--' . time() . '.xlsx';
|
$filename = self::$title . '--' . time() . '.xlsx';
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
@ -152,6 +160,7 @@ class PHPExcelService
|
|||||||
}
|
}
|
||||||
return new self;
|
return new self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置标题
|
* 设置标题
|
||||||
* @param $title string || array ['title'=>'','name'=>'','info'=>[]]
|
* @param $title string || array ['title'=>'','name'=>'','info'=>[]]
|
||||||
@ -160,7 +169,8 @@ class PHPExcelService
|
|||||||
* @param $funName function($style,$A,$A2) 自定义设置头部样式
|
* @param $funName function($style,$A,$A2) 自定义设置头部样式
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setExcelTile($title='',$Name='',$info=[],$funName=null){
|
public function setExcelTile($title = '', $Name = '', $info = [], $funName = null)
|
||||||
|
{
|
||||||
//设置参数
|
//设置参数
|
||||||
if (is_array($title)) {
|
if (is_array($title)) {
|
||||||
if (isset($title['title'])) $title = $title['title'];
|
if (isset($title['title'])) $title = $title['title'];
|
||||||
@ -211,12 +221,14 @@ class PHPExcelService
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置第二行标题内容
|
* 设置第二行标题内容
|
||||||
* @param $info array (['name'=>'','site'=>'','phone'=>123] || ['我是表名','我是地址','我是手机号码'] ) || string 自定义
|
* @param $info array (['name'=>'','site'=>'','phone'=>123] || ['我是表名','我是地址','我是手机号码'] ) || string 自定义
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private static function setCellInfo($info){
|
private static function setCellInfo($info)
|
||||||
|
{
|
||||||
$content = ['操作者:', '导出日期:' . date('Y-m-d', time()), '地址:', '电话:'];
|
$content = ['操作者:', '导出日期:' . date('Y-m-d', time()), '地址:', '电话:'];
|
||||||
if (is_array($info) && !empty($info)) {
|
if (is_array($info) && !empty($info)) {
|
||||||
if (isset($info['name'])) {
|
if (isset($info['name'])) {
|
||||||
|
|||||||
@ -10,8 +10,8 @@ namespace crmeb\services;
|
|||||||
* @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
* @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
* @updated 2015-08-26
|
* @updated 2015-08-26
|
||||||
*/
|
*/
|
||||||
class PHPTreeService{
|
class PHPTreeService
|
||||||
|
{
|
||||||
protected static $config = array(
|
protected static $config = array(
|
||||||
/* 主键 */
|
/* 主键 */
|
||||||
'primary_key' => 'id',
|
'primary_key' => 'id',
|
||||||
@ -32,19 +32,22 @@ class PHPTreeService{
|
|||||||
|
|
||||||
/* 层次暂存 */
|
/* 层次暂存 */
|
||||||
protected static $level = array();
|
protected static $level = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name 生成树形结构
|
* @name 生成树形结构
|
||||||
* @param array 二维数组
|
* @param array 二维数组
|
||||||
* @return mixed 多维数组
|
* @return mixed 多维数组
|
||||||
*/
|
*/
|
||||||
public static function makeTree($data,$options=array() ){
|
public static function makeTree($data, $options = array())
|
||||||
|
{
|
||||||
$dataset = self::buildData($data, $options);
|
$dataset = self::buildData($data, $options);
|
||||||
$r = self::makeTreeCore(0, $dataset, 'normal');
|
$r = self::makeTreeCore(0, $dataset, 'normal');
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 生成线性结构, 便于HTML输出, 参数同上 */
|
/* 生成线性结构, 便于HTML输出, 参数同上 */
|
||||||
public static function makeTreeForHtml($data,$options=array()){
|
public static function makeTreeForHtml($data, $options = array())
|
||||||
|
{
|
||||||
|
|
||||||
$dataset = self::buildData($data, $options);
|
$dataset = self::buildData($data, $options);
|
||||||
$r = self::makeTreeCore(0, $dataset, 'linear');
|
$r = self::makeTreeCore(0, $dataset, 'linear');
|
||||||
@ -52,7 +55,8 @@ class PHPTreeService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 格式化数据, 私有方法 */
|
/* 格式化数据, 私有方法 */
|
||||||
private static function buildData($data,$options){
|
private static function buildData($data, $options)
|
||||||
|
{
|
||||||
$config = array_merge(self::$config, $options);
|
$config = array_merge(self::$config, $options);
|
||||||
self::$config = $config;
|
self::$config = $config;
|
||||||
extract($config);
|
extract($config);
|
||||||
@ -71,16 +75,12 @@ class PHPTreeService{
|
|||||||
private static function makeTreeCore($index, $data, $type = 'linear')
|
private static function makeTreeCore($index, $data, $type = 'linear')
|
||||||
{
|
{
|
||||||
extract(self::$config);
|
extract(self::$config);
|
||||||
foreach($data[$index] as $id=>$item)
|
foreach ($data[$index] as $id => $item) {
|
||||||
{
|
|
||||||
if ($type == 'normal') {
|
if ($type == 'normal') {
|
||||||
if(isset($data[$id]))
|
if (isset($data[$id])) {
|
||||||
{
|
|
||||||
$item[$expanded_key] = self::$config['expanded'];
|
$item[$expanded_key] = self::$config['expanded'];
|
||||||
$item[$children_key] = self::makeTreeCore($id, $data, $type);
|
$item[$children_key] = self::makeTreeCore($id, $data, $type);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$item[$leaf_key] = true;
|
$item[$leaf_key] = true;
|
||||||
}
|
}
|
||||||
$r[] = $item;
|
$r[] = $item;
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
namespace crmeb\services;
|
namespace crmeb\services;
|
||||||
|
|
||||||
|
|
||||||
|
use app\admin\model\system\SystemAttachment;
|
||||||
use app\admin\model\wechat\WechatQrcode as QrcodeModel;
|
use app\admin\model\wechat\WechatQrcode as QrcodeModel;
|
||||||
|
|
||||||
class QrcodeService
|
class QrcodeService
|
||||||
@ -15,12 +16,16 @@ class QrcodeService
|
|||||||
/**
|
/**
|
||||||
* 获取临时二维码 单个
|
* 获取临时二维码 单个
|
||||||
* */
|
* */
|
||||||
public static function getTemporaryQrcode($type,$id){
|
public static function getTemporaryQrcode($type, $id)
|
||||||
|
{
|
||||||
return QrcodeModel::getTemporaryQrcode($type, $id)->toArray();
|
return QrcodeModel::getTemporaryQrcode($type, $id)->toArray();
|
||||||
}/**
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* 获取永久二维码 单个
|
* 获取永久二维码 单个
|
||||||
* */
|
* */
|
||||||
public static function getForeverQrcode($type,$id){
|
public static function getForeverQrcode($type, $id)
|
||||||
|
{
|
||||||
return QrcodeModel::getForeverQrcode($type, $id)->toArray();
|
return QrcodeModel::getForeverQrcode($type, $id)->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,4 +38,41 @@ class QrcodeService
|
|||||||
{
|
{
|
||||||
return QrcodeModel::scanQrcode($id, $type);
|
return QrcodeModel::scanQrcode($id, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取二维码完整路径,不存在则自动生成
|
||||||
|
* @param string $name 路径名
|
||||||
|
* @param string $link 需要生成二维码的跳转路径
|
||||||
|
* @param int $type https 1 = http , 0 = https
|
||||||
|
* @param bool $force 是否返回false
|
||||||
|
* @return bool|mixed|string
|
||||||
|
*/
|
||||||
|
public static function getWechatQrcodePath(string $name, string $link, int $type = 1, bool $force = false)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$imageInfo = SystemAttachment::getInfo($name, 'name');
|
||||||
|
$siteUrl = sysConfig('site_url');
|
||||||
|
if (!$imageInfo) {
|
||||||
|
$codeUrl = UtilService::setHttpType($siteUrl . $link, $type);//二维码链接
|
||||||
|
$imageInfo = UtilService::getQRCodePath($codeUrl, $name);
|
||||||
|
if (is_string($imageInfo) && $force)
|
||||||
|
return false;
|
||||||
|
if (is_array($imageInfo)) {
|
||||||
|
SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
|
||||||
|
$url = $imageInfo['dir'];
|
||||||
|
} else {
|
||||||
|
$url = '';
|
||||||
|
$imageInfo = ['image_type' => 0];
|
||||||
|
}
|
||||||
|
} else $url = $imageInfo['att_dir'];
|
||||||
|
if ($imageInfo['image_type'] == 1) $url = $siteUrl . $url;
|
||||||
|
return $url;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
if ($force)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace crmeb\services;
|
namespace crmeb\services;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -20,13 +20,6 @@ class SystemConfigService
|
|||||||
|
|
||||||
const CACHE_SYSTEM = 'system_config';
|
const CACHE_SYSTEM = 'system_config';
|
||||||
|
|
||||||
public static $ProtectedKey = [
|
|
||||||
'wechat_appid', 'wechat_appsecret', 'wechat_token', 'wechat_encodingaeskey', 'wechat_encode',
|
|
||||||
'pay_weixin_mchid', 'pay_weixin_client_cert', 'pay_weixin_client_key', 'pay_weixin_key', 'pay_weixin_open',
|
|
||||||
'routine_appId', 'routine_appsecret',
|
|
||||||
'pay_routine_mchid', 'pay_routine_key', 'pay_routine_client_cert', 'pay_routine_client_key', 'pay_weixin_open'
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化
|
* 初始化
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace crmeb\services;
|
namespace crmeb\services;
|
||||||
|
|
||||||
class UpgradeService extends FileService
|
class UpgradeService extends FileService
|
||||||
@ -25,35 +26,45 @@ class UpgradeService extends FileService
|
|||||||
protected static $Isauth = 'index.php/admin/server.upgrade_api/isauth.html';
|
protected static $Isauth = 'index.php/admin/server.upgrade_api/isauth.html';
|
||||||
//相隔付
|
//相隔付
|
||||||
private static $seperater = "{&&}";
|
private static $seperater = "{&&}";
|
||||||
|
|
||||||
//更新网址信息
|
//更新网址信息
|
||||||
public function snyweninfo($serverweb){
|
public function snyweninfo($serverweb)
|
||||||
|
{
|
||||||
return self::request_post(self::$UpdateWeBinfo, $serverweb);
|
return self::request_post(self::$UpdateWeBinfo, $serverweb);
|
||||||
}
|
}
|
||||||
|
|
||||||
//判断是否有权限 返回1有权限,0无权限
|
//判断是否有权限 返回1有权限,0无权限
|
||||||
public function isauth(){
|
public function isauth()
|
||||||
|
{
|
||||||
return self::request_post(self::$Isauth);
|
return self::request_post(self::$Isauth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*获取ip token 生成当前时间和过期时间
|
*获取ip token 生成当前时间和过期时间
|
||||||
* @param string ip
|
* @param string ip
|
||||||
* @param int $valid_peroid 过期周期 15天
|
* @param int $valid_peroid 过期周期 15天
|
||||||
*/
|
*/
|
||||||
public static function get_token($ip='',$valid_peroid=1296000){
|
public static function get_token($ip = '', $valid_peroid = 1296000)
|
||||||
|
{
|
||||||
$request = app('request');
|
$request = app('request');
|
||||||
if (empty($ip)) $ip = $request->ip();
|
if (empty($ip)) $ip = $request->ip();
|
||||||
$to_ken = $request->domain() . self::$seperater . $ip . self::$seperater . time() . self::$seperater . (time() + $valid_peroid) . self::$seperater;
|
$to_ken = $request->domain() . self::$seperater . $ip . self::$seperater . time() . self::$seperater . (time() + $valid_peroid) . self::$seperater;
|
||||||
$token = self::enCode($to_ken);
|
$token = self::enCode($to_ken);
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
private static function getRet($msg,$code=400){
|
|
||||||
|
private static function getRet($msg, $code = 400)
|
||||||
|
{
|
||||||
return ['msg' => $msg, 'code' => $code];
|
return ['msg' => $msg, 'code' => $code];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $post_data
|
* @param array $post_data
|
||||||
*/
|
*/
|
||||||
public static function start(){
|
public static function start()
|
||||||
|
{
|
||||||
$pach = app()->getRootPath() . 'version';
|
$pach = app()->getRootPath() . 'version';
|
||||||
$request = app('request');
|
$request = app('request');
|
||||||
if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员');
|
if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员');
|
||||||
@ -73,7 +84,9 @@ class UpgradeService extends FileService
|
|||||||
}
|
}
|
||||||
return self::getRet('获取失败');
|
return self::getRet('获取失败');
|
||||||
}
|
}
|
||||||
public static function getVersion(){
|
|
||||||
|
public static function getVersion()
|
||||||
|
{
|
||||||
$pach = app()->getRootPath() . '.version';
|
$pach = app()->getRootPath() . '.version';
|
||||||
if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员');
|
if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员');
|
||||||
$version = @file($pach);
|
$version = @file($pach);
|
||||||
@ -85,20 +98,21 @@ class UpgradeService extends FileService
|
|||||||
}
|
}
|
||||||
return self::getRet($arr, 200);
|
return self::getRet($arr, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模拟post进行url请求
|
* 模拟post进行url请求
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $post_data
|
* @param array $post_data
|
||||||
*/
|
*/
|
||||||
public static function request_post($url = '', $post_data = array()) {
|
public static function request_post($url = '', $post_data = array())
|
||||||
|
{
|
||||||
if (strstr($url, 'http') === false) $url = self::$domain . $url;
|
if (strstr($url, 'http') === false) $url = self::$domain . $url;
|
||||||
if (empty($url)) {
|
if (empty($url)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!isset($post_data['token'])) $post_data['token'] = self::get_token();
|
if (!isset($post_data['token'])) $post_data['token'] = self::get_token();
|
||||||
$o = "";
|
$o = "";
|
||||||
foreach ( $post_data as $k => $v )
|
foreach ($post_data as $k => $v) {
|
||||||
{
|
|
||||||
$o .= "$k=" . urlencode($v) . "&";
|
$o .= "$k=" . urlencode($v) . "&";
|
||||||
}
|
}
|
||||||
$post_data = substr($o, 0, -1);
|
$post_data = substr($o, 0, -1);
|
||||||
@ -118,6 +132,7 @@ class UpgradeService extends FileService
|
|||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证远程文件是否存在 以及下载
|
* 验证远程文件是否存在 以及下载
|
||||||
* @param string $url 文件路径
|
* @param string $url 文件路径
|
||||||
@ -134,12 +149,10 @@ class UpgradeService extends FileService
|
|||||||
$result = curl_exec($curl);
|
$result = curl_exec($curl);
|
||||||
$found = false;
|
$found = false;
|
||||||
// 如果请求没有发送失败
|
// 如果请求没有发送失败
|
||||||
if ($result !== false)
|
if ($result !== false) {
|
||||||
{
|
|
||||||
// 再检查http响应码是否为200
|
// 再检查http响应码是否为200
|
||||||
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
if ($statusCode == 200)
|
if ($statusCode == 200) {
|
||||||
{
|
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
$fileservice = new self;
|
$fileservice = new self;
|
||||||
@ -154,13 +167,15 @@ class UpgradeService extends FileService
|
|||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
return $found;
|
return $found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用加密
|
* 通用加密
|
||||||
* @param String $string 需要加密的字串
|
* @param String $string 需要加密的字串
|
||||||
* @param String $skey 加密EKY
|
* @param String $skey 加密EKY
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
private static function enCode($string = '', $skey = 'fb') {
|
private static function enCode($string = '', $skey = 'fb')
|
||||||
|
{
|
||||||
$skey = array_reverse(str_split($skey));
|
$skey = array_reverse(str_split($skey));
|
||||||
$strArr = str_split(base64_encode($string));
|
$strArr = str_split(base64_encode($string));
|
||||||
$strCount = count($strArr);
|
$strCount = count($strArr);
|
||||||
@ -169,12 +184,14 @@ class UpgradeService extends FileService
|
|||||||
}
|
}
|
||||||
return str_replace('=', 'O0O0O', join('', $strArr));
|
return str_replace('=', 'O0O0O', join('', $strArr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 去除回车,去取空格,去除换行,去除tab
|
* 去除回车,去取空格,去除换行,去除tab
|
||||||
* @param String $str 需要去除的字串
|
* @param String $str 需要去除的字串
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public static function replace($str){
|
public static function replace($str)
|
||||||
|
{
|
||||||
return trim(str_replace(array("\r", "\n", "\t"), '', $str));
|
return trim(str_replace(array("\r", "\n", "\t"), '', $str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10,13 +10,23 @@ namespace crmeb\services;
|
|||||||
use crmeb\services\storage\COS;
|
use crmeb\services\storage\COS;
|
||||||
use crmeb\services\storage\OSS;
|
use crmeb\services\storage\OSS;
|
||||||
use crmeb\services\storage\Qiniu;
|
use crmeb\services\storage\Qiniu;
|
||||||
use crmeb\services\SystemConfigService;
|
use crmeb\traits\LogicTrait;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
use think\facade\Filesystem;
|
use think\facade\Filesystem;
|
||||||
use think\File;
|
use think\File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class UploadService
|
||||||
|
* @package crmeb\services
|
||||||
|
* @method $this setReturnErr(bool $returnErr) 设置发生错误时是否返回错误信息
|
||||||
|
* @method $this setAutoValidate(bool $autoValidate) 设置是否校验上传文件
|
||||||
|
* @method $this setUploadType(int $uploadType) 设置上传类型
|
||||||
|
* @method $this setImageValidate(string $imageValidate) 设置上传图片大小等验证信息
|
||||||
|
* @method $this setUploadPath(string $uploadPath) 设置文件上传路径
|
||||||
|
*/
|
||||||
class UploadService
|
class UploadService
|
||||||
{
|
{
|
||||||
|
use LogicTrait;
|
||||||
/**
|
/**
|
||||||
* 文件校验
|
* 文件校验
|
||||||
* @var bool
|
* @var bool
|
||||||
@ -61,87 +71,24 @@ class UploadService
|
|||||||
*/
|
*/
|
||||||
private static $uploadStatus;
|
private static $uploadStatus;
|
||||||
|
|
||||||
/**
|
|
||||||
* 本类实例化
|
|
||||||
* @var
|
|
||||||
*/
|
|
||||||
protected static $instance;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传图片的大小 2MB 单位字节
|
* 上传图片的大小 2MB 单位字节
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $imageValidate = 'filesize:2097152|fileExt:jpg,jpeg,png,gif,pem|fileMime:image/jpeg,image/gif,image/png,text/plain';
|
protected $imageValidate = 'filesize:2097152|fileExt:jpg,jpeg,png,gif,pem|fileMime:image/jpeg,image/gif,image/png,text/plain';
|
||||||
|
|
||||||
|
protected $propsRule = [
|
||||||
|
'returnErr' => false,
|
||||||
|
'autoValidate' => false,
|
||||||
|
'uploadPath' => null,
|
||||||
|
'uploadType' => null,
|
||||||
|
];
|
||||||
|
|
||||||
protected function __construct()
|
protected function __construct()
|
||||||
{
|
{
|
||||||
self::init();
|
self::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return UploadService
|
|
||||||
*/
|
|
||||||
public static function getInstance()
|
|
||||||
{
|
|
||||||
if(is_null(self::$instance)) self::$instance = new self();
|
|
||||||
return self::$instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置上传图片大小等验证信息
|
|
||||||
* @param string $imageValidate
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setImageValidate(string $imageValidate)
|
|
||||||
{
|
|
||||||
$this->imageValidate = $imageValidate;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置是否校验上传文件
|
|
||||||
* @param bool $autoValidate
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setAutoValidate(bool $autoValidate)
|
|
||||||
{
|
|
||||||
$this->autoValidate = $autoValidate;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置上传路径
|
|
||||||
* @param string $uploadPath
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setUploadPath(string $uploadPath)
|
|
||||||
{
|
|
||||||
$this->uploadPath = $uploadPath;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置上传类型
|
|
||||||
* @param int $uploadType
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setUploadType(int $uploadType)
|
|
||||||
{
|
|
||||||
$this->uploadType = $uploadType;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置发生错误时是否返回错误信息
|
|
||||||
* @param bool $returnErr
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function serReturnErr(bool $returnErr)
|
|
||||||
{
|
|
||||||
$this->returnErr = $returnErr;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化
|
* 初始化
|
||||||
*/
|
*/
|
||||||
@ -207,7 +154,10 @@ class UploadService
|
|||||||
try {
|
try {
|
||||||
$uploadType = $this->uploadType ?: sysConfig('upload_type');
|
$uploadType = $this->uploadType ?: sysConfig('upload_type');
|
||||||
//TODO 没有选择默认使用本地上传
|
//TODO 没有选择默认使用本地上传
|
||||||
if (!$uploadType) $uploadType = 1;
|
if (!$uploadType)
|
||||||
|
$uploadType = 1;
|
||||||
|
if (!is_int($uploadType))
|
||||||
|
$uploadType = (int)$uploadType;
|
||||||
switch ($uploadType) {
|
switch ($uploadType) {
|
||||||
case 1 :
|
case 1 :
|
||||||
$info = $this->uploadLocaFile($fileName);
|
$info = $this->uploadLocaFile($fileName);
|
||||||
@ -239,8 +189,6 @@ class UploadService
|
|||||||
if (is_string($info)) return $info;
|
if (is_string($info)) return $info;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->uploadPath = '';
|
|
||||||
$this->autoValidate = true;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
@ -254,7 +202,8 @@ class UploadService
|
|||||||
* @param bool $isData 是否真实获取图片信息
|
* @param bool $isData 是否真实获取图片信息
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getImageHeaders(string $url,$type = 1,$isData = true){
|
public static function getImageHeaders(string $url, $type = 1, $isData = true)
|
||||||
|
{
|
||||||
stream_context_set_default([
|
stream_context_set_default([
|
||||||
'ssl' => [
|
'ssl' => [
|
||||||
'verify_peer' => false,
|
'verify_peer' => false,
|
||||||
@ -284,8 +233,7 @@ class UploadService
|
|||||||
{
|
{
|
||||||
$file = request()->file($fileName);
|
$file = request()->file($fileName);
|
||||||
if (!$file) return '上传文件不存在!';
|
if (!$file) return '上传文件不存在!';
|
||||||
if ($this->autoValidate)
|
if ($this->autoValidate) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
validate([$fileName => $this->imageValidate])->check([$fileName => $file]);
|
validate([$fileName => $this->imageValidate])->check([$fileName => $file]);
|
||||||
} catch (ValidateException $e) {
|
} catch (ValidateException $e) {
|
||||||
@ -297,6 +245,8 @@ class UploadService
|
|||||||
$filePath = Filesystem::path($fileName);
|
$filePath = Filesystem::path($fileName);
|
||||||
$fileInfo = new File($filePath);
|
$fileInfo = new File($filePath);
|
||||||
$url = '/uploads/' . $fileName;
|
$url = '/uploads/' . $fileName;
|
||||||
|
$this->uploadPath = '';
|
||||||
|
$this->autoValidate = false;
|
||||||
return $this->setUploadInfo($url, 1, $fileInfo->getFilename(), self::thumb('.' . $url), [
|
return $this->setUploadInfo($url, 1, $fileInfo->getFilename(), self::thumb('.' . $url), [
|
||||||
'Content-Length' => $fileInfo->getSize(),
|
'Content-Length' => $fileInfo->getSize(),
|
||||||
'Content-Type' => $fileInfo->getMime()
|
'Content-Type' => $fileInfo->getMime()
|
||||||
@ -421,8 +371,7 @@ class UploadService
|
|||||||
if (strtolower($extension) == 'php' || !$extension)
|
if (strtolower($extension) == 'php' || !$extension)
|
||||||
return self::setError('上传文件非法!');
|
return self::setError('上传文件非法!');
|
||||||
$file = request()->file($fileName);
|
$file = request()->file($fileName);
|
||||||
if ($this->autoValidate)
|
if ($this->autoValidate) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
validate([$fileName => $this->imageValidate])->check([$fileName => $file]);
|
validate([$fileName => $this->imageValidate])->check([$fileName => $file]);
|
||||||
} catch (ValidateException $e) {
|
} catch (ValidateException $e) {
|
||||||
@ -466,8 +415,8 @@ class UploadService
|
|||||||
return DS . $savePath;
|
return DS . $savePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function __clone()
|
protected function __destruct()
|
||||||
{
|
{
|
||||||
// TODO: Implement __clone() method.
|
// TODO: Implement __destruct() method.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,7 +67,8 @@ class UtilService
|
|||||||
return $p;
|
return $p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function encrypt($string, $operation = false, $key = '', $expiry = 0) {
|
public static function encrypt($string, $operation = false, $key = '', $expiry = 0)
|
||||||
|
{
|
||||||
// 动态密匙长度,相同的明文会生成不同密文就是依靠动态密匙
|
// 动态密匙长度,相同的明文会生成不同密文就是依靠动态密匙
|
||||||
$ckey_length = 6;
|
$ckey_length = 6;
|
||||||
|
|
||||||
@ -202,6 +203,7 @@ class UtilService
|
|||||||
}
|
}
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分级返回多维数组
|
* 分级返回多维数组
|
||||||
* @param $data
|
* @param $data
|
||||||
@ -227,6 +229,7 @@ class UtilService
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**分级返回下级所有分类ID
|
/**分级返回下级所有分类ID
|
||||||
* @param $data
|
* @param $data
|
||||||
* @param string $children
|
* @param string $children
|
||||||
@ -293,7 +296,8 @@ class UtilService
|
|||||||
* @param $card
|
* @param $card
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function setCard($card){
|
public static function setCard($card)
|
||||||
|
{
|
||||||
$city = [11 => "北京", 12 => "天津", 13 => "河北", 14 => "山西", 15 => "内蒙古", 21 => "辽宁", 22 => "吉林", 23 => "黑龙江 ", 31 => "上海", 32 => "江苏", 33 => "浙江", 34 => "安徽", 35 => "福建", 36 => "江西", 37 => "山东", 41 => "河南", 42 => "湖北 ", 43 => "湖南", 44 => "广东", 45 => "广西", 46 => "海南", 50 => "重庆", 51 => "四川", 52 => "贵州", 53 => "云南", 54 => "西藏 ", 61 => "陕西", 62 => "甘肃", 63 => "青海", 64 => "宁夏", 65 => "新疆", 71 => "台湾", 81 => "香港", 82 => "澳门", 91 => "国外 "];
|
$city = [11 => "北京", 12 => "天津", 13 => "河北", 14 => "山西", 15 => "内蒙古", 21 => "辽宁", 22 => "吉林", 23 => "黑龙江 ", 31 => "上海", 32 => "江苏", 33 => "浙江", 34 => "安徽", 35 => "福建", 36 => "江西", 37 => "山东", 41 => "河南", 42 => "湖北 ", 43 => "湖南", 44 => "广东", 45 => "广西", 46 => "海南", 50 => "重庆", 51 => "四川", 52 => "贵州", 53 => "云南", 54 => "西藏 ", 61 => "陕西", 62 => "甘肃", 63 => "青海", 64 => "宁夏", 65 => "新疆", 71 => "台湾", 81 => "香港", 82 => "澳门", 91 => "国外 "];
|
||||||
$tip = "";
|
$tip = "";
|
||||||
$match = "/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/";
|
$match = "/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/";
|
||||||
@ -316,8 +320,7 @@ class UtilService
|
|||||||
$sum = 0;
|
$sum = 0;
|
||||||
$ai = 0;
|
$ai = 0;
|
||||||
$wi = 0;
|
$wi = 0;
|
||||||
for ($i = 0; $i < 17; $i++)
|
for ($i = 0; $i < 17; $i++) {
|
||||||
{
|
|
||||||
$ai = $card[$i];
|
$ai = $card[$i];
|
||||||
$wi = $factor[$i];
|
$wi = $factor[$i];
|
||||||
$sum += $ai * $wi;
|
$sum += $ai * $wi;
|
||||||
@ -342,7 +345,8 @@ class UtilService
|
|||||||
* @return array|bool|string
|
* @return array|bool|string
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function setShareMarketingPoster($data = array(), $path){
|
public static function setShareMarketingPoster($data = array(), $path)
|
||||||
|
{
|
||||||
$config = array(
|
$config = array(
|
||||||
'text' => array(
|
'text' => array(
|
||||||
array(
|
array(
|
||||||
@ -443,7 +447,8 @@ class UtilService
|
|||||||
* @return array|bool|string
|
* @return array|bool|string
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function setSharePoster($config = array(), $path){
|
public static function setSharePoster($config = array(), $path)
|
||||||
|
{
|
||||||
$imageDefault = array(
|
$imageDefault = array(
|
||||||
'left' => 0,
|
'left' => 0,
|
||||||
'top' => 0,
|
'top' => 0,
|
||||||
@ -506,7 +511,7 @@ class UtilService
|
|||||||
$res = ob_get_contents();
|
$res = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
$key = substr(md5(rand(0, 9999)), 0, 5) . date('YmdHis') . rand(0, 999999) . '.jpg';
|
$key = substr(md5(rand(0, 9999)), 0, 5) . date('YmdHis') . rand(0, 999999) . '.jpg';
|
||||||
return UploadService::getInstance()->setUploadPath($path)->imageStream($key,$res);
|
return UploadService::instance()->setUploadPath($path)->imageStream($key, $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -544,8 +549,11 @@ class UtilService
|
|||||||
public static function setHttpType($url, $type = 0)
|
public static function setHttpType($url, $type = 0)
|
||||||
{
|
{
|
||||||
$domainTop = substr($url, 0, 5);
|
$domainTop = substr($url, 0, 5);
|
||||||
if($type){ if($domainTop == 'https') $url = 'http'.substr($url,5,strlen($url)); }
|
if ($type) {
|
||||||
else{ if($domainTop != 'https') $url = 'https:'.substr($url,5,strlen($url)); }
|
if ($domainTop == 'https') $url = 'http' . substr($url, 5, strlen($url));
|
||||||
|
} else {
|
||||||
|
if ($domainTop != 'https') $url = 'https:' . substr($url, 5, strlen($url));
|
||||||
|
}
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,7 +681,8 @@ class UtilService
|
|||||||
* @param string $avatar
|
* @param string $avatar
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public static function setImageBase64($avatar = '',$timeout=9){
|
public static function setImageBase64($avatar = '', $timeout = 9)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$url = parse_url($avatar);
|
$url = parse_url($avatar);
|
||||||
$url = $url['host'];
|
$url = $url['host'];
|
||||||
|
|||||||
@ -593,7 +593,6 @@ class WechatService
|
|||||||
$staff = self::staffService();
|
$staff = self::staffService();
|
||||||
$staff = is_callable($message) ? $staff->message($message()) : $staff->message($message);
|
$staff = is_callable($message) ? $staff->message($message()) : $staff->message($message);
|
||||||
$res = $staff->to($to)->send();
|
$res = $staff->to($to)->send();
|
||||||
HookService::afterListen('wechat_staff_to',compact('to','message'),$res);
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,8 @@ class WechatTemplateService implements ProviderInterface
|
|||||||
//砍价成功
|
//砍价成功
|
||||||
const BARGAIN_SUCCESS = 'OPENTM410292733';
|
const BARGAIN_SUCCESS = 'OPENTM410292733';
|
||||||
|
|
||||||
public static function getConstants($code='') {
|
public static function getConstants($code = '')
|
||||||
|
{
|
||||||
$oClass = new \ReflectionClass(__CLASS__);
|
$oClass = new \ReflectionClass(__CLASS__);
|
||||||
$stants = $oClass->getConstants();
|
$stants = $oClass->getConstants();
|
||||||
if ($code) return isset($stants[$code]) ? $stants[$code] : '';
|
if ($code) return isset($stants[$code]) ? $stants[$code] : '';
|
||||||
@ -86,7 +87,6 @@ class WechatTemplateService implements ProviderInterface
|
|||||||
try {
|
try {
|
||||||
return WechatService::sendTemplate($openid, $tempid, $data, $url, $defaultColor);
|
return WechatService::sendTemplate($openid, $tempid, $data, $url, $defaultColor);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
dump($e->getMessage());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,13 +3,17 @@
|
|||||||
namespace crmeb\services;
|
namespace crmeb\services;
|
||||||
|
|
||||||
use app\models\system\Cache as CacheModel;
|
use app\models\system\Cache as CacheModel;
|
||||||
|
use crmeb\interfaces\ProviderInterface;
|
||||||
|
use crmeb\traits\LogicTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class YLYService
|
* Class YLYService
|
||||||
* @package crmeb\services
|
* @package crmeb\services
|
||||||
*/
|
*/
|
||||||
class YLYService extends HttpService
|
class YLYService extends HttpService implements ProviderInterface
|
||||||
{
|
{
|
||||||
|
use LogicTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开发者创建的应用的应用ID
|
* 开发者创建的应用的应用ID
|
||||||
* @var string
|
* @var string
|
||||||
@ -58,11 +62,11 @@ class YLYService extends HttpService
|
|||||||
*/
|
*/
|
||||||
protected $apiUrl = 'https://open-api.10ss.net/';
|
protected $apiUrl = 'https://open-api.10ss.net/';
|
||||||
|
|
||||||
/**
|
|
||||||
* 本类实例化句柄
|
public function register($congig = [])
|
||||||
* @var
|
{
|
||||||
*/
|
|
||||||
protected static $instance;
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YLYService constructor.
|
* YLYService constructor.
|
||||||
@ -77,20 +81,11 @@ class YLYService extends HttpService
|
|||||||
$this->getAccessToken();
|
$this->getAccessToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 实例化本类
|
|
||||||
* @return YLYService
|
|
||||||
*/
|
|
||||||
public static function getInstance()
|
|
||||||
{
|
|
||||||
if(is_null(self::$instance)) self::$instance = new self();
|
|
||||||
return self::$instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取AccessToken
|
* 获取AccessToken
|
||||||
* */
|
* */
|
||||||
protected function getAccessToken(){
|
protected function getAccessToken()
|
||||||
|
{
|
||||||
$token = CacheModel::getDbCache('YLY_access_token');
|
$token = CacheModel::getDbCache('YLY_access_token');
|
||||||
if (!$token) {
|
if (!$token) {
|
||||||
$request = self::postRequest($this->apiUrl . 'oauth/oauth', [
|
$request = self::postRequest($this->apiUrl . 'oauth/oauth', [
|
||||||
@ -116,7 +111,8 @@ class YLYService extends HttpService
|
|||||||
* 生成UUID4
|
* 生成UUID4
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function createUuid() {
|
protected function createUuid()
|
||||||
|
{
|
||||||
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||||
mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
|
mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
|
||||||
}
|
}
|
||||||
@ -169,7 +165,8 @@ class YLYService extends HttpService
|
|||||||
* @param array $product 订单详情
|
* @param array $product 订单详情
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setContent(string $name,array $orderInfo,array $product){
|
public function setContent(string $name, array $orderInfo, array $product)
|
||||||
|
{
|
||||||
$timeYmd = date('Y-m-d', time());
|
$timeYmd = date('Y-m-d', time());
|
||||||
$timeHis = date('H:i:s', time());
|
$timeHis = date('H:i:s', time());
|
||||||
$goodsStr = '<table><tr><td>商品名称</td><td>数量</td><td>单价</td><td>金额</td></tr>';
|
$goodsStr = '<table><tr><td>商品名称</td><td>数量</td><td>单价</td><td>金额</td></tr>';
|
||||||
@ -212,8 +209,8 @@ CONTENT;
|
|||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function __clone()
|
protected function __destruct()
|
||||||
{
|
{
|
||||||
// TODO: Implement __clone() method.
|
// TODO: Implement __destruct() method.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace crmeb\services\storage;
|
namespace crmeb\services\storage;
|
||||||
|
|
||||||
use crmeb\services\SystemConfigService;
|
use crmeb\services\SystemConfigService;
|
||||||
@ -32,7 +33,8 @@ class COS
|
|||||||
* @return null|Client
|
* @return null|Client
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
protected static function autoInfo(){
|
protected static function autoInfo()
|
||||||
|
{
|
||||||
if (($storageRegion = Cache::get('storageRegion')) && ($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) {
|
if (($storageRegion = Cache::get('storageRegion')) && ($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) {
|
||||||
self::$accessKey = $accessKey;
|
self::$accessKey = $accessKey;
|
||||||
self::$secretKey = $secretKey;
|
self::$secretKey = $secretKey;
|
||||||
@ -71,7 +73,8 @@ class COS
|
|||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function uploadImage($filename = 'image'){
|
public static function uploadImage($filename = 'image')
|
||||||
|
{
|
||||||
$request = app('request');
|
$request = app('request');
|
||||||
$file = $request->file($filename);
|
$file = $request->file($filename);
|
||||||
$filePath = $file->getRealPath();
|
$filePath = $file->getRealPath();
|
||||||
@ -95,7 +98,8 @@ class COS
|
|||||||
* @param $content
|
* @param $content
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function uploadImageStream($key, $content){
|
public static function uploadImageStream($key, $content)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
self::autoInfo();
|
self::autoInfo();
|
||||||
return [self::$uploadUrl . $key, self::$auth->putObject([
|
return [self::$uploadUrl . $key, self::$auth->putObject([
|
||||||
@ -113,7 +117,8 @@ class COS
|
|||||||
* @param $key
|
* @param $key
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function delete($key){
|
public static function delete($key)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
self::autoInfo();
|
self::autoInfo();
|
||||||
return self::$auth->deleteObject([
|
return self::$auth->deleteObject([
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace crmeb\services\storage;
|
namespace crmeb\services\storage;
|
||||||
|
|
||||||
use crmeb\services\SystemConfigService;
|
use crmeb\services\SystemConfigService;
|
||||||
@ -30,7 +31,8 @@ class OSS
|
|||||||
* @return null|OssClient
|
* @return null|OssClient
|
||||||
* @throws \OSS\Core\OssException
|
* @throws \OSS\Core\OssException
|
||||||
*/
|
*/
|
||||||
protected static function autoInfo(){
|
protected static function autoInfo()
|
||||||
|
{
|
||||||
if (($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) {
|
if (($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) {
|
||||||
self::$accessKey = $accessKey;
|
self::$accessKey = $accessKey;
|
||||||
self::$secretKey = $secretKey;
|
self::$secretKey = $secretKey;
|
||||||
@ -61,7 +63,8 @@ class OSS
|
|||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function uploadImage($filename = 'image'){
|
public static function uploadImage($filename = 'image')
|
||||||
|
{
|
||||||
$request = app('request');
|
$request = app('request');
|
||||||
$file = $request->file($filename);
|
$file = $request->file($filename);
|
||||||
$filePath = $file->getRealPath();
|
$filePath = $file->getRealPath();
|
||||||
@ -81,7 +84,8 @@ class OSS
|
|||||||
* @param $content
|
* @param $content
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function uploadImageStream($key, $content){
|
public static function uploadImageStream($key, $content)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
self::autoInfo();
|
self::autoInfo();
|
||||||
return self::$auth->putObject(self::$storageName, $key, $content);
|
return self::$auth->putObject(self::$storageName, $key, $content);
|
||||||
@ -95,7 +99,8 @@ class OSS
|
|||||||
* @param $key
|
* @param $key
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function delete($key){
|
public static function delete($key)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
self::autoInfo();
|
self::autoInfo();
|
||||||
return self::$auth->deleteObject(self::$storageName, $key);
|
return self::$auth->deleteObject(self::$storageName, $key);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace crmeb\services\storage;
|
namespace crmeb\services\storage;
|
||||||
|
|
||||||
use crmeb\services\SystemConfigService;
|
use crmeb\services\SystemConfigService;
|
||||||
@ -28,13 +29,13 @@ class Qiniu
|
|||||||
protected static $storageName;
|
protected static $storageName;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO 初始化
|
* TODO 初始化
|
||||||
* @return null|Auth
|
* @return null|Auth
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
protected static function autoInfo(){
|
protected static function autoInfo()
|
||||||
|
{
|
||||||
if (($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) {
|
if (($storageName = Cache::get('storageName')) && ($uploadUrl = Cache::get('uploadUrl')) && ($accessKey = Cache::get('accessKey')) && ($secretKey = Cache::get('secretKey'))) {
|
||||||
self::$accessKey = $accessKey;
|
self::$accessKey = $accessKey;
|
||||||
self::$secretKey = $secretKey;
|
self::$secretKey = $secretKey;
|
||||||
@ -61,7 +62,8 @@ class Qiniu
|
|||||||
* TODO 获取上传图片视频token和domain
|
* TODO 获取上传图片视频token和domain
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getToKenAndDomainI(){
|
public static function getToKenAndDomainI()
|
||||||
|
{
|
||||||
$token = self::autoInfo()->uploadToken(self::$storageName);
|
$token = self::autoInfo()->uploadToken(self::$storageName);
|
||||||
$domain = self::$uploadUrl;
|
$domain = self::$uploadUrl;
|
||||||
$fileName = md5(rand(1000, 9999) . date('YmdHis') . rand(0, 9999));
|
$fileName = md5(rand(1000, 9999) . date('YmdHis') . rand(0, 9999));
|
||||||
@ -74,7 +76,8 @@ class Qiniu
|
|||||||
* @return array
|
* @return array
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function uploadImage($filename = 'image'){
|
public static function uploadImage($filename = 'image')
|
||||||
|
{
|
||||||
$request = app('request');
|
$request = app('request');
|
||||||
$file = $request->file($filename);
|
$file = $request->file($filename);
|
||||||
$filePath = $file->getRealPath();
|
$filePath = $file->getRealPath();
|
||||||
@ -96,7 +99,8 @@ class Qiniu
|
|||||||
* @return array|string
|
* @return array|string
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function uploadImageStream($key, $content){
|
public static function uploadImageStream($key, $content)
|
||||||
|
{
|
||||||
$token = self::autoInfo()->uploadToken(self::$storageName, $key);
|
$token = self::autoInfo()->uploadToken(self::$storageName, $key);
|
||||||
try {
|
try {
|
||||||
$uploadMgr = new UploadManager();
|
$uploadMgr = new UploadManager();
|
||||||
@ -114,7 +118,8 @@ class Qiniu
|
|||||||
* @param int $time 图片链接最后的访问时间
|
* @param int $time 图片链接最后的访问时间
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function imageUrl($key, $type = '', $imageUrl = '', $time = 0){
|
public static function imageUrl($key, $type = '', $imageUrl = '', $time = 0)
|
||||||
|
{
|
||||||
return ['code' => 200, 'name' => $key, 'dir' => self::$uploadUrl . $key, 'thumb_path' => self::$uploadUrl . $key, 'time' => time()];
|
return ['code' => 200, 'name' => $key, 'dir' => self::$uploadUrl . $key, 'thumb_path' => self::$uploadUrl . $key, 'time' => time()];
|
||||||
// $imageValue = !strlen(trim($type)) ? self::$uploadUrl.$key : self::$uploadUrl.$key.self::getType($type);
|
// $imageValue = !strlen(trim($type)) ? self::$uploadUrl.$key : self::$uploadUrl.$key.self::getType($type);
|
||||||
// if($time > time() && !strlen(trim($imageUrl))) return ['code'=>100,'dir'=>$imageUrl,'thumb_path'=>$imageUrl,'time'=>$time];
|
// if($time > time() && !strlen(trim($imageUrl))) return ['code'=>100,'dir'=>$imageUrl,'thumb_path'=>$imageUrl,'time'=>$time];
|
||||||
@ -127,7 +132,8 @@ class Qiniu
|
|||||||
* @param $imageType
|
* @param $imageType
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getType($imageType){
|
public static function getType($imageType)
|
||||||
|
{
|
||||||
$type = '';
|
$type = '';
|
||||||
switch ($imageType) {
|
switch ($imageType) {
|
||||||
case "8x6":
|
case "8x6":
|
||||||
@ -143,7 +149,8 @@ class Qiniu
|
|||||||
* @param $bucket
|
* @param $bucket
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function delete($key){
|
public static function delete($key)
|
||||||
|
{
|
||||||
$bucketManager = new BucketManager(self::autoInfo(), new Config());
|
$bucketManager = new BucketManager(self::autoInfo(), new Config());
|
||||||
return $bucketManager->delete(self::$storageName, $key);
|
return $bucketManager->delete(self::$storageName, $key);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user