初始化代码
This commit is contained in:
34
longbingcore/diy/BaseSubscribe.php
Normal file
34
longbingcore/diy/BaseSubscribe.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\diy;
|
||||
|
||||
use app\BaseControllerV2;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/11 17:04
|
||||
* Class BaseSubscribe
|
||||
* @package longbingcore\diy
|
||||
*/
|
||||
class BaseSubscribe extends BaseControllerV2
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
}
|
||||
|
||||
}
|
||||
235
longbingcore/permissions/AdminMenu.php
Normal file
235
longbingcore/permissions/AdminMenu.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\permissions;
|
||||
|
||||
|
||||
|
||||
use app\admin\info\PermissionAdmin;
|
||||
|
||||
/**
|
||||
* c端后台菜单
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:56
|
||||
* Class AdminMenu
|
||||
* @package longbingcore\permissions
|
||||
*/
|
||||
class AdminMenu {
|
||||
|
||||
/**
|
||||
* 根据权限来返回有权限的菜单
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @return array
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 19:01
|
||||
*/
|
||||
static public function all (int $uniacid) : array {
|
||||
|
||||
$menu_data = longbing_init_info_data('AdminMenu' , 'model');
|
||||
|
||||
|
||||
// dump($menu_data);exit;
|
||||
$denyAdminMenuKeys = self::getAuthList($uniacid);
|
||||
|
||||
|
||||
|
||||
|
||||
//获取权限接口 2019年12月20日09:51:18 By.jingshuixian
|
||||
/*
|
||||
foreach ($saas_auth_admin_model_list as $key=>$item){
|
||||
|
||||
|
||||
if($item['auth_is_saas_check'] || $item['auth_platform'] ){
|
||||
$permissionPath = APP_PATH . $key . '/info/Permission.php' ;
|
||||
if(file_exists($permissionPath) && require_once($permissionPath)){
|
||||
|
||||
$permissionClassName = 'app\\' . $key .'\\info\\Permission' ;
|
||||
$permissionClass = new $permissionClassName($uniacid);
|
||||
|
||||
if($item['auth_is_saas_check'] && $permissionClass->sAuth() && $item['auth_platform'] && $permissionClass->pAuth() ){
|
||||
$denyAdminMenuKeys[] = $key;
|
||||
}else if ( !$item['auth_is_saas_check'] && $item['auth_platform'] && $permissionClass->pAuth() ) {
|
||||
$denyAdminMenuKeys[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
$denyAdminMenuKeys[] = $key;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//从查找没有权限的adminMenuKey
|
||||
/*$denyAdminMenuKeys = [];
|
||||
$permissions = config('permissions');
|
||||
foreach ($permissions as $permissionClass) {
|
||||
|
||||
//判断一个对象是否为一个类的子类
|
||||
if (!is_subclass_of($permissionClass, PermissionAbstract::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$permission = new $permissionClass($uniacid, 0);
|
||||
if (!$permission->pAuth() && !empty($permission->adminMenuKey)) {
|
||||
$denyAdminMenuKeys[] = $permission->adminMenuKey;
|
||||
}
|
||||
}*/
|
||||
|
||||
//返回有权限的菜单
|
||||
$rst = [];
|
||||
|
||||
|
||||
foreach ($menu_data as $k => $menu) {
|
||||
|
||||
|
||||
if (array_key_exists($k, $denyAdminMenuKeys) ) {
|
||||
//装载插件权限 By.jingshuixian
|
||||
if($k == 'appstore'){
|
||||
//后去插件所有菜单 需要过滤权限
|
||||
$appMenudataList = longbing_init_info_data('AdminMenu','app');
|
||||
$app = json_decode($menu, true);
|
||||
$children = $app['children'] ;
|
||||
|
||||
foreach ($appMenudataList as $appKey => $appMenu) {
|
||||
|
||||
//过滤插件全选,需要验证是否正确
|
||||
if (array_key_exists($appKey, $denyAdminMenuKeys)){
|
||||
|
||||
|
||||
$m = json_decode($appMenu, true);
|
||||
|
||||
if(!empty($m)){
|
||||
foreach ($m as $item ){
|
||||
$children[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//应用中心主菜单
|
||||
|
||||
$app['children'] = $children ;
|
||||
|
||||
$rst[] = $app ;
|
||||
}else if($k == 'admin'){
|
||||
|
||||
$adminMenu = json_decode($menu, true) ;
|
||||
$permission = new PermissionAdmin($uniacid);
|
||||
$pAuthConfig = $permission->getPAuthConfig();
|
||||
if($pAuthConfig && $pAuthConfig['copyright_id'] != 0 ){
|
||||
$children = $adminMenu['children'];
|
||||
foreach ($children as $k => $child) {
|
||||
if ($child['path'] == 'copyright') {
|
||||
unset($children[$k]);
|
||||
}
|
||||
}
|
||||
$adminMenu['children'] = array_values($children);
|
||||
|
||||
$url = $adminMenu['meta']['subNavName'][1]['url'];
|
||||
unset($url[0]);
|
||||
$adminMenu['meta']['subNavName'][1]['url'] = array_values($url);
|
||||
}
|
||||
|
||||
$rst[] = $adminMenu ;
|
||||
|
||||
}else{
|
||||
$rst[] = json_decode($menu, true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return $rst;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有应用列表权限
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @return array
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/20 13:51
|
||||
*/
|
||||
static public function getAppstoreInfoList (int $uniacid) : array {
|
||||
|
||||
$dataList = longbing_init_info_data('Info','app');
|
||||
|
||||
$denyAdminMenuKeys = self::getAuthList($uniacid);
|
||||
|
||||
$returnList = [] ;
|
||||
|
||||
foreach ($dataList as $key => $item ){
|
||||
|
||||
if(array_key_exists($item['name'], $denyAdminMenuKeys) ){
|
||||
$returnList[] = $item ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $returnList ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得拥有模块/app权限列表
|
||||
*
|
||||
* @param $uniacid
|
||||
* @return array
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/20 13:39
|
||||
*/
|
||||
static public function getAuthList($uniacid){
|
||||
$denyAdminMenuKeys = [] ;
|
||||
|
||||
|
||||
if(empty($uniacid)){
|
||||
return $denyAdminMenuKeys ;
|
||||
}
|
||||
|
||||
$adminModelListInfo = config('app.AdminModelList') ;
|
||||
$saas_auth_admin_model_list = $adminModelListInfo['saas_auth_admin_model_list'];
|
||||
|
||||
|
||||
foreach ($saas_auth_admin_model_list as $key=>$item) {
|
||||
|
||||
$className = 'Permission' . ucfirst($key);
|
||||
$permissionPath = APP_PATH . $key . '/info/' . $className . '.php';
|
||||
if (file_exists($permissionPath) && require_once($permissionPath)) {
|
||||
|
||||
$permissionClassName = 'app\\' . $key . '\\info\\'. $className;
|
||||
$permission = new $permissionClassName($uniacid , $item);
|
||||
if ( $permission->pAuth() && !empty($permission->adminMenuKey)) {
|
||||
|
||||
$denyAdminMenuKeys[$key] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $denyAdminMenuKeys ;
|
||||
}
|
||||
|
||||
}
|
||||
274
longbingcore/permissions/PermissionAbstract.php
Normal file
274
longbingcore/permissions/PermissionAbstract.php
Normal file
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\permissions;
|
||||
|
||||
|
||||
use app\Common\Rsa2Sign;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 权限的抽象类
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:56
|
||||
* Class PermissionAbstract
|
||||
* @package longbingcore\permissions
|
||||
*/
|
||||
abstract class PermissionAbstract
|
||||
{
|
||||
/**
|
||||
* @var int|null 小程序底部菜单的key
|
||||
*/
|
||||
public $tabbarKey;
|
||||
|
||||
/**
|
||||
* @var string|null 后台菜单的key
|
||||
*/
|
||||
public $adminMenuKey;
|
||||
|
||||
/**
|
||||
* @var array 权限关联的apiPaths
|
||||
*/
|
||||
public $apiPaths;
|
||||
|
||||
/**
|
||||
* @var string|null saas端授权的key
|
||||
*/
|
||||
public $saasKey;
|
||||
|
||||
|
||||
/**
|
||||
* @var int|null sass端授权的值
|
||||
*/
|
||||
protected $sassValue;
|
||||
|
||||
/**
|
||||
* @var int 小程序id
|
||||
*/
|
||||
protected $uniacid;
|
||||
|
||||
/**
|
||||
* @var array info控制配置信息
|
||||
*/
|
||||
public $infoConfig = [
|
||||
'auth_platform' => true ,
|
||||
'auth_is_platform_check' =>true ,
|
||||
'auth_is_saas_check' => true ,
|
||||
];
|
||||
|
||||
public $info = [];
|
||||
|
||||
static public $pAuthConfig;
|
||||
|
||||
|
||||
public function __construct(int $uniacid, ?int $tabbarKey, ?string $adminMenuKey, ?string $saasKey, ?array $apiPaths , $infoConfigOptions = [])
|
||||
{
|
||||
$this->tabbarKey = $tabbarKey;
|
||||
$this->adminMenuKey = $adminMenuKey;
|
||||
$this->saasKey = $saasKey;
|
||||
$this->apiPaths = $apiPaths;
|
||||
$this->uniacid = $uniacid;
|
||||
|
||||
if(!empty($infoConfigOptions)){
|
||||
$this->infoConfig = array_merge($this->infoConfig , $infoConfigOptions);
|
||||
}else{
|
||||
//自动从全局Info里获取
|
||||
$adminModelListInfo = config('app.AdminModelList') ;
|
||||
$saas_auth_admin_model_list = $adminModelListInfo['saas_auth_admin_model_list'];
|
||||
if(array_key_exists($this->adminMenuKey , $saas_auth_admin_model_list)){
|
||||
$this->infoConfig = array_merge($this->infoConfig , $saas_auth_admin_model_list[$this->adminMenuKey]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->info = $this->getModelInfo($this->adminMenuKey);
|
||||
|
||||
$this->sassValue = $this->getAuthVaule($this->saasKey );
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前模块/app配置的info信息
|
||||
*
|
||||
* @param $model_name
|
||||
* @return array|mixed
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/27 17:47
|
||||
*/
|
||||
public function getModelInfo($model_name){
|
||||
|
||||
//导入info信息查看
|
||||
$infoDataPath = APP_PATH . $model_name . '/info/Info.php' ;
|
||||
$infoData = [] ;
|
||||
if(file_exists($infoDataPath)){
|
||||
$infoData = include $infoDataPath ;
|
||||
}
|
||||
return $infoData ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回saas端授权结果
|
||||
*
|
||||
* @return bool
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:57
|
||||
*/
|
||||
abstract public function sAuth(): bool;
|
||||
|
||||
/**
|
||||
* 返回p端授权结果
|
||||
*
|
||||
* @return bool
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:57
|
||||
*/
|
||||
abstract public function pAuth(): bool;
|
||||
|
||||
/**
|
||||
* 返回c端授权结果
|
||||
*
|
||||
* @param int $user_id
|
||||
* @return bool
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 17:13
|
||||
*/
|
||||
abstract public function cAuth(int $user_id): bool;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 返回saasValue
|
||||
*
|
||||
* @return int
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:58
|
||||
*/
|
||||
public function getSaasValue(): int
|
||||
{
|
||||
return $this->sassValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回当前实例
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @return PermissionAbstract
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 10:59
|
||||
*/
|
||||
static function this (int $uniacid) : self {
|
||||
return new static($uniacid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取p端的权限配置
|
||||
*
|
||||
* @return array|null
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 14:22
|
||||
*/
|
||||
public function getPAuthConfig(): ?array
|
||||
{
|
||||
if (isset(self::$pAuthConfig[$this->uniacid])) {
|
||||
return self::$pAuthConfig[$this->uniacid];
|
||||
}
|
||||
|
||||
try {
|
||||
$cardauth2_config_exist = Db::query('show tables like "%longbing_cardauth2_config%"');
|
||||
if (empty($cardauth2_config_exist)) {
|
||||
return null;
|
||||
}
|
||||
$pAuthConfig = Db::name('longbing_cardauth2_config')->where([['modular_id', '=', $this->uniacid]])->find();
|
||||
} catch (DataNotFoundException $notFoundException) {
|
||||
return null;
|
||||
} catch (ModelNotFoundException $modelNotFoundException) {
|
||||
return null;
|
||||
} catch (DbException $exception) {
|
||||
return null;
|
||||
}
|
||||
|
||||
self::$pAuthConfig[$this->uniacid] = $pAuthConfig;
|
||||
return $pAuthConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据saasAuthKey获得值
|
||||
*
|
||||
* @param $saasAuthKey
|
||||
* @return int|null
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/19 19:07
|
||||
*/
|
||||
public function getAuthVaule($saasAuthKey , $defaultAuthNumber = -1){
|
||||
$returnNumber = 0 ;
|
||||
$auth = SaasAuthConfig::getSAuthConfig($this->uniacid);
|
||||
if($auth){
|
||||
$authkey = array_column($auth,1 , 0) ;
|
||||
}else{
|
||||
$authkey = [];
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists($saasAuthKey , $authkey)){
|
||||
|
||||
$returnNumber = intval( $authkey[$saasAuthKey] ) ;
|
||||
//0 代表无限制数量, 默认给 99999999
|
||||
$returnNumber = $returnNumber == 0 ? 0 : $returnNumber ;
|
||||
|
||||
}else{
|
||||
$returnNumber = $defaultAuthNumber ;
|
||||
}
|
||||
|
||||
/* if($saasAuthKey == 'LONGBING_BAIDU'){
|
||||
|
||||
longbing_dd($auth);
|
||||
|
||||
longbing_dd($saasAuthKey . '=========='.$defaultAuthNumber .'===========' . $this->uniacid);
|
||||
}*/
|
||||
|
||||
|
||||
return $returnNumber ;
|
||||
}
|
||||
|
||||
|
||||
public function getAuthPlatform(){
|
||||
return $this->infoConfig['auth_platform'] ;
|
||||
}
|
||||
|
||||
public function getAuthIsPlatformCheck(){
|
||||
return $this->infoConfig['auth_is_platform_check'] ;
|
||||
}
|
||||
|
||||
public function getAuthIsSaasCheck(){
|
||||
return $this->infoConfig['auth_is_saas_check'] ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取授权数量
|
||||
*
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/19 19:02
|
||||
*/
|
||||
public function getAuthNumber(){
|
||||
|
||||
return $this->getAuthVaule( $this->saasKey);
|
||||
}
|
||||
|
||||
}
|
||||
143
longbingcore/permissions/SaasAuthConfig.php
Normal file
143
longbingcore/permissions/SaasAuthConfig.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace longbingcore\permissions;
|
||||
|
||||
include_once LONGBING_EXTEND_PATH . 'LongbingUpgrade.php';
|
||||
|
||||
use app\Common\Rsa2Sign;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
use LongbingUpgrade;
|
||||
|
||||
/**
|
||||
* saas端请求到的权限数据(k-v格式)
|
||||
*
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 14:23
|
||||
* Class SaasAuthConfig
|
||||
* @package longbingcore\permissions
|
||||
*/
|
||||
Class SaasAuthConfig {
|
||||
|
||||
|
||||
static public $sAuthConfig = [];
|
||||
|
||||
|
||||
/**
|
||||
* 获取s端的权限配置
|
||||
*
|
||||
* @return array|null
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 11:26
|
||||
*/
|
||||
public static function getSAuthConfig (int $uniacid): ?array
|
||||
{
|
||||
if (isset(self::$sAuthConfig[$uniacid])) {
|
||||
return self::$sAuthConfig[$uniacid];
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$sAuthConfig = self::_getsAuthConfig($uniacid);
|
||||
if(empty($sAuthConfig)) {
|
||||
$sAuthConfig = [] ;
|
||||
}
|
||||
|
||||
self::$sAuthConfig[$uniacid] = $sAuthConfig;
|
||||
|
||||
return $sAuthConfig;
|
||||
} catch (\Exception $exception) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取saas端的值
|
||||
* @param string $server_url
|
||||
* @return array|bool|mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 19:01
|
||||
*
|
||||
*/
|
||||
private static function _getsAuthConfig($uniacid, $server_url = 'http://api.longbing.org')
|
||||
{
|
||||
|
||||
$app_model_name = config('app.AdminModelList')['app_model_name'];
|
||||
//By.jingshuixian 2019年12月20日16:48:41 优化代码逻辑
|
||||
//代理管理端是固定小程
|
||||
$uniacid = $uniacid ? $uniacid : 8888 ;
|
||||
|
||||
$domain_name = $_SERVER['HTTP_HOST'];
|
||||
|
||||
$auth_data = getCache('single_checked_auth_'. $app_model_name . $domain_name, $uniacid );
|
||||
//dump($auth_data);exit;
|
||||
if (!empty($auth_data)&&!empty($auth_data[0][0])) {
|
||||
|
||||
return $auth_data;
|
||||
|
||||
}
|
||||
//By.jingshuixian 2019年12月20日16:48:41 优化代码逻辑 end
|
||||
|
||||
$goods_name = config('app.AdminModelList')['app_model_name'];
|
||||
|
||||
$auth_uniacid = config('app.AdminModelList')['auth_uniacid'];
|
||||
|
||||
$upgrade = new LongbingUpgrade($auth_uniacid , $goods_name , Env::get('j2hACuPrlohF9BvFsgatvaNFQxCBCc' , false));
|
||||
|
||||
$param_list = $upgrade->getsAuthConfig();
|
||||
|
||||
if (!empty($param_list)) {
|
||||
|
||||
$data = $param_list;
|
||||
|
||||
$auth_data = [];
|
||||
//解密
|
||||
foreach ($data as $k => $item) {
|
||||
|
||||
$a = explode(':', $item);
|
||||
//存入缓存 一天的有效期
|
||||
if ($a[0] == 'LONGBING_AUTH_GOODS_SINGLE') {
|
||||
|
||||
$a[0] = 'LONGBING_AUTH_GOODS';
|
||||
|
||||
}
|
||||
$auth_data[] = $a;
|
||||
}
|
||||
setCache('single_checked_auth_' . $app_model_name . $domain_name, $auth_data, 3600, $uniacid);
|
||||
|
||||
return $auth_data;
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
226
longbingcore/permissions/Tabbar.php
Normal file
226
longbingcore/permissions/Tabbar.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\permissions;
|
||||
|
||||
use app\diy\model\DiyModel;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 小程序底部菜单
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:56
|
||||
* Class Tabbar
|
||||
* @package longbingcore\permissions
|
||||
*/
|
||||
class Tabbar {
|
||||
|
||||
/**
|
||||
* 根据权限来返回有权限的小程序底部菜单
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @param int $user_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/10 15:56
|
||||
*/
|
||||
static public function all (int $uniacid, int $user_id) : array {
|
||||
$diy = DiyModel::where([['uniacid', '=', $uniacid], ['status', '=', 1]])->find();
|
||||
if (empty($diy)) {
|
||||
return [];
|
||||
}
|
||||
$diy_tabbar = json_decode($diy['tabbar'], true);
|
||||
|
||||
|
||||
//从查找没有权限的tabbarKey
|
||||
$denyTabbarKeys = [];
|
||||
$permissions = config('permissions');
|
||||
foreach ($permissions as $permissionClass) {
|
||||
if (!is_subclass_of($permissionClass, PermissionAbstract::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var PermissionAbstract $permission
|
||||
*/
|
||||
$permission = new $permissionClass($uniacid, $user_id);
|
||||
if (!$permission->cAuth($user_id) && !empty($permission->tabbarKey)) {
|
||||
$denyTabbarKeys[] = $permission->tabbarKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//返回有权限的菜单
|
||||
foreach ($diy_tabbar['list'] as $k => $tabbar) {
|
||||
if (in_array($tabbar['key'], $denyTabbarKeys)) {
|
||||
unset($diy_tabbar['list'][$k]);
|
||||
}
|
||||
}
|
||||
|
||||
return $diy_tabbar;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* diy时,返回有diy权限的小程序菜单
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/10 15:56
|
||||
*/
|
||||
static public function allForDiySelect (int $uniacid) : array {
|
||||
$diy_tabbar = [] ;
|
||||
|
||||
|
||||
$adminModelListInfo = config('app.AdminModelList') ;
|
||||
$saas_auth_admin_model_list = $adminModelListInfo['saas_auth_admin_model_list'];
|
||||
|
||||
|
||||
foreach ($saas_auth_admin_model_list as $key=>$item) {
|
||||
|
||||
$className = 'Permission' . ucfirst($key);
|
||||
$permissionPath = APP_PATH . $key . '/info/' . $className . '.php';
|
||||
if (file_exists($permissionPath) && require_once($permissionPath)) {
|
||||
|
||||
$permissionClassName = 'app\\' . $key . '\\info\\'. $className;
|
||||
$permission = new $permissionClassName($uniacid , $item);
|
||||
|
||||
if ( $permission->pAuth() && !empty($permission->adminMenuKey)) {
|
||||
|
||||
$diyTabbarPath = APP_PATH . $key . '/info/DiyTabbar.php';
|
||||
if (file_exists($diyTabbarPath)) {
|
||||
|
||||
$tabbar = include_once ($diyTabbarPath) ;
|
||||
|
||||
$diy_tabbar = array_merge($diy_tabbar , $tabbar) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['list'] = $diy_tabbar;
|
||||
//默认设置
|
||||
$data['color'] = '#5d6268';
|
||||
$data['selectedColor'] = '#19c865';
|
||||
$data['backgroundColor'] = '#fff';
|
||||
$data['borderStyle'] = 'white';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $uniacid
|
||||
* @功能说明:获取有权限的默认数据
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-05-15 17:28
|
||||
*/
|
||||
static public function getAuthDefultTabbar($data){
|
||||
|
||||
$url = config('app.AdminModelList')['diy_default_data']['tabbar'];
|
||||
//默认配置
|
||||
//$url = '{"id":1,"uniacid":4,"status":1,"create_time":1578106749,"update_time":1578106749,"list":[{"is_show":1,"key":1,"iconPath":"icon-mingpian","selectedIconPath":"icon-mingpian1","pageComponents":"cardHome","name":"\u540d\u7247","url":"\/pages\/user\/home","url_out":"","jump_way":0},{"key":2,"is_show":1,"iconPath":"icon-shangcheng1","selectedIconPath":"icon-shangcheng","pageComponents":"shopHome","name":"\u5546\u57ce","url":"","url_jump_way":"0","url_out":"","is_delete":false,"bind_compoents":[],"bind_links":[],"page":[]},{"key":3,"is_show":1,"iconPath":"icon-dongtai1","selectedIconPath":"icon-dongtai","pageComponents":"infoHome","name":"\u52a8\u6001","url":"","url_jump_way":"0","url_out":"","is_delete":false,"bind_compoents":[],"bind_links":[],"page":[]},{"key":4,"is_show":1,"iconPath":"icon-guanwang","selectedIconPath":"icon-guanwang1","pageComponents":"websiteHome","name":"\u5b98\u7f51","url":"","url_jump_way":"0","url_out":"","is_delete":false,"bind_compoents":[],"bind_links":[],"page":[]},{"key":20001,"is_show":1,"iconPath":"iconyonghuduangerenzhongxin","selectedIconPath":"iconyonghuduangerenzhongxin1","pageComponents":"","name":"\u4e2a\u4eba\u4e2d\u5fc3","url":"","url_jump_way":"0","url_out":"","is_delete":false,"bind_compoents":["ucenterCompoent"],"bind_links":["case"],"page":[]}],"color":"#5d6268","selectedColor":"#19c865","backgroundColor":"#fff","borderStyle":"white"}';
|
||||
|
||||
$url = json_decode($url,true);
|
||||
|
||||
foreach ($url['list'] as $k=>$v){
|
||||
|
||||
if(!in_array($v['key'],$data)){
|
||||
|
||||
unset($url['list'][$k]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$url['list'] = array_values($url['list']);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $uniacid
|
||||
* @功能说明:获取有权限的
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-05-15 17:50
|
||||
*/
|
||||
static public function getAuthDefultPage($data){
|
||||
|
||||
$url = config('app.AdminModelList')['diy_default_data']['page'];
|
||||
//默认配置
|
||||
//$url = '{"1":{"list":[]},"2":{"list":[]},"3":{"list":[]},"4":{"list":[]},"20001":{"list":[{"title":"\u7528\u6237\u4fe1\u606f","type":"userInfo","icon":"iconyonghuxinxi","isDelete":false,"addNumber":1,"attr":[{"title":"\u5b57\u4f53\u989c\u8272","type":"ColorPicker","name":"fontColor"},{"title":"\u80cc\u666f\u56fe\u7247","type":"UploadImage","desc":"750*440","name":"bgImage"}],"data":{"nickName":"\u7528\u6237\u6635\u79f0","avatarUrl":"https:\/\/retail.xiaochengxucms.com\/defaultAvatar.png","nickText":"\u66f4\u65b0\u6211\u7684\u4e2a\u4eba\u8d44\u6599","fontColor":"#F9DEAF","bgImage":[{"url":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/user_bg.jpg"}]},"id":1578137234868,"compontents":"ucenterCompoent"},{"title":"\u521b\u5efa\u540d\u7247","type":"createCard","icon":"iconchuangjianmingpian","isDelete":false,"addNumber":1,"data":{"createText":"\u521b\u5efa\u6211\u7684\u540d\u7247","createBtn":"\u521b\u5efa\u540d\u7247"},"id":1578137237049,"compontents":"ucenterCompoent"},{"title":"\u8ba2\u5355\u7ba1\u7406","type":"moduleMenuShopOrder","icon":"iconshoporder","isDelete":true,"addNumber":1,"attr":[{"title":"\u6a21\u677f\u540d\u79f0","type":"Switch","name":"isShowTitle"},{"title":"\u9009\u62e9\u6a21\u677f","type":"ChooseModule","name":"module","data":[{"title":"\u4e00\u884c\u591a\u5217","name":"module-menu-row","img":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/module-menu-col.jpg"},{"title":"\u4e00\u884c\u4e00\u5217","name":"module-menu-col","img":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/module-menu-row.jpg"}]},{"title":"\u4e00\u884c\u591a\u5c11\u5217","type":"InputNumber","name":"row"}],"data":{"isShowTitle":false,"module":"module-menu-row","row":{"number":4,"min":2,"max":5,"label":"\u8bf7\u8f93\u5165"},"list":[{"title":"\u5168\u90e8","icon":"iconwodedingdan","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=0"}},{"title":"\u5f85\u4ed8\u6b3e","icon":"icondingdandaifukuan","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=1"}},{"title":"\u5f85\u53d1\u8d27","icon":"icondingdandaifahuo","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=2"}},{"title":"\u5f85\u6536\u8d27","icon":"icondingdandaishouhuo","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=3"}},{"title":"\u5df2\u5b8c\u6210","icon":"icondingdanyiwancheng","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=4"}}]},"id":1578137248488,"compontents":"ucenterCompoent"},{"title":"\u5fc5\u5907\u5de5\u5177","type":"moduleMenuShop","icon":"iconshop","isDelete":true,"addNumber":1,"attr":[{"title":"\u6a21\u677f\u540d\u79f0","type":"Switch","name":"isShowTitle"},{"title":"\u9009\u62e9\u6a21\u677f","type":"ChooseModule","name":"module","data":[{"title":"\u4e00\u884c\u591a\u5217","name":"module-menu-row","img":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/module-menu-col.jpg"},{"title":"\u4e00\u884c\u4e00\u5217","name":"module-menu-col","img":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/module-menu-row.jpg"}]},{"title":"\u4e00\u884c\u591a\u5c11\u5217","type":"InputNumber","name":"row"}],"data":{"isShowTitle":false,"module":"module-menu-row","row":{"number":4,"min":2,"max":5,"label":"\u8bf7\u8f93\u5165"},"list":[{"title":"\u6211\u7684\u552e\u540e","icon":"iconwodeshouhou","link":{"type":2,"url":"\/shop\/pages\/refund\/list"}},{"title":"\u6211\u7684\u6536\u5165","icon":"icontixianguanli","link":{"type":2,"url":"\/shop\/pages\/partner\/income"}},{"title":"\u6211\u7684\u4f18\u60e0\u5238","icon":"iconwodekaquan","link":{"type":2,"url":"\/shop\/pages\/coupon\/list"}},{"title":"\u5206\u9500\u5546\u54c1","icon":"iconquanmianfenxiao","link":{"type":2,"needStaffId":true,"url":"\/shop\/pages\/partner\/distribution?staff_id="}},{"title":"\u6211\u7684\u5730\u5740","icon":"icondizhi2","link":{"type":2,"url":"\/shop\/pages\/address\/list"}}]},"id":1578137252032,"compontents":"ucenterCompoent"},{"title":"\u5207\u6362\u9500\u552e","type":"changeStaff","icon":"iconqiehuanmingpian-copy","isDelete":false,"addNumber":1,"attr":[{"title":"\u6a21\u677f\u540d\u79f0","type":"Input","name":"title"},{"title":"\u662f\u5426\u663e\u793a\u66f4\u591a","type":"Switch","name":"isShowMore"}],"data":{"title":"\u5207\u6362\u9500\u552e","isShowMore":true},"dataList":[],"id":1578137250013,"compontents":"ucenterCompoent"}]}}';
|
||||
|
||||
$url = json_decode($url,true);
|
||||
|
||||
foreach ($url as $k=>$v){
|
||||
|
||||
if(!in_array($k,$data)){
|
||||
|
||||
unset($url[$k]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得拥有模块/app权限列表
|
||||
*
|
||||
* @param $uniacid
|
||||
* @return array
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/20 13:39
|
||||
*/
|
||||
public function getAuthList($uniacid){
|
||||
$denyAdminMenuKeys = [] ;
|
||||
|
||||
|
||||
if(empty($uniacid)){
|
||||
return $denyAdminMenuKeys ;
|
||||
}
|
||||
|
||||
$adminModelListInfo = config('app.AdminModelList') ;
|
||||
$saas_auth_admin_model_list = $adminModelListInfo['saas_auth_admin_model_list'];
|
||||
|
||||
foreach ($saas_auth_admin_model_list as $key=>$item) {
|
||||
|
||||
$className = 'Permission' . ucfirst($key);
|
||||
$permissionPath = APP_PATH . $key . '/info/' . $className . '.php';
|
||||
if (file_exists($permissionPath) && require_once($permissionPath)) {
|
||||
|
||||
$permissionClassName = 'app\\' . $key . '\\info\\'. $className;
|
||||
$permission = new $permissionClassName($uniacid , $item);
|
||||
|
||||
if ( $permission->pAuth() && !empty($permission->adminMenuKey)) {
|
||||
$denyAdminMenuKeys[$key] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $denyAdminMenuKeys ;
|
||||
}
|
||||
|
||||
}
|
||||
263
longbingcore/printer/API_PHP_DEMO.php
Normal file
263
longbingcore/printer/API_PHP_DEMO.php
Normal file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
namespace longbingcore\printer;
|
||||
|
||||
use longbingcore\printer\HttpClient;
|
||||
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
define('USER', 'xxxxxxxxx'); //*必填*:飞鹅云后台注册账号
|
||||
define('UKEY', 'xxxxxxxxxxxx'); //*必填*: 飞鹅云注册账号后生成的UKEY
|
||||
define('SN', 'xxxxxxxxx'); //*必填*:打印机编号,必须要在管理后台里添加打印机或调用API接口添加之后,才能调用API
|
||||
|
||||
|
||||
//以下参数不需要修改
|
||||
define('IP','api.feieyun.cn'); //接口IP或域名
|
||||
define('PORT',80); //接口IP端口
|
||||
define('PATH','/Api/Open/'); //接口路径
|
||||
define('STIME', time()); //公共参数,请求时间
|
||||
define('SIG', sha1(USER.UKEY.STIME)); //公共参数,请求公钥
|
||||
|
||||
|
||||
|
||||
|
||||
//===========添加打印机接口(支持批量)=============
|
||||
//***接口返回值说明***
|
||||
//正确例子:{"msg":"ok","ret":0,"data":{"ok":["sn#key#remark#carnum","316500011#abcdefgh#快餐前台"],"no":["316500012#abcdefgh#快餐前台#13688889999 (错误:识别码不正确)"]},"serverExecutedTime":3}
|
||||
//错误:{"msg":"参数错误 : 该帐号未注册.","ret":-2,"data":null,"serverExecutedTime":37}
|
||||
|
||||
//打开注释可测试
|
||||
//提示:打印机编号(必填) # 打印机识别码(必填) # 备注名称(选填) # 流量卡号码(选填),多台打印机请换行(\n)添加新打印机信息,每次最多100行(台)。
|
||||
//$snlist = "sn1#key1#remark1#carnum1\nsn2#key2#remark2#carnum2";
|
||||
//addprinter($snlist);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================方法1.打印订单==================
|
||||
//***接口返回值说明***
|
||||
//正确例子:{"msg":"ok","ret":0,"data":"316500004_20160823165104_1853029628","serverExecutedTime":6}
|
||||
//错误:{"msg":"错误信息.","ret":非零错误码,"data":null,"serverExecutedTime":5}
|
||||
|
||||
|
||||
//标签说明:
|
||||
//单标签:
|
||||
//"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
|
||||
//"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
|
||||
//成对标签:
|
||||
//"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
|
||||
//<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,"<RIGHT></RIGHT>"为右对齐
|
||||
//拼凑订单内容时可参考如下格式
|
||||
//根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
|
||||
|
||||
$orderInfo = '<CB>测试打印</CB><BR>';
|
||||
$orderInfo .= '名称 单价 数量 金额<BR>';
|
||||
$orderInfo .= '--------------------------------<BR>';
|
||||
$orderInfo .= '饭 10.0 10 10.0<BR>';
|
||||
$orderInfo .= '炒饭 10.0 10 10.0<BR>';
|
||||
$orderInfo .= '蛋炒饭 10.0 100 100.0<BR>';
|
||||
$orderInfo .= '鸡蛋炒饭 100.0 100 100.0<BR>';
|
||||
$orderInfo .= '西红柿炒饭 1000.0 1 100.0<BR>';
|
||||
$orderInfo .= '西红柿蛋炒饭 100.0 100 100.0<BR>';
|
||||
$orderInfo .= '西红柿鸡蛋炒饭 15.0 1 15.0<BR>';
|
||||
$orderInfo .= '备注:加辣<BR>';
|
||||
$orderInfo .= '--------------------------------<BR>';
|
||||
$orderInfo .= '合计:xx.0元<BR>';
|
||||
$orderInfo .= '送货地点:广州市南沙区xx路xx号<BR>';
|
||||
$orderInfo .= '联系电话:13888888888888<BR>';
|
||||
$orderInfo .= '订餐时间:2014-08-08 08:08:08<BR>';
|
||||
$orderInfo .= '<QR>http://www.dzist.com</QR>';//把二维码字符串用标签套上即可自动生成二维码
|
||||
|
||||
|
||||
//打开注释可测试
|
||||
wp_print(SN,$orderInfo,2);
|
||||
|
||||
|
||||
|
||||
//===========方法2.查询某订单是否打印成功=============
|
||||
//***接口返回值说明***
|
||||
//正确例子:
|
||||
//已打印:{"msg":"ok","ret":0,"data":true,"serverExecutedTime":6}
|
||||
//未打印:{"msg":"ok","ret":0,"data":false,"serverExecutedTime":6}
|
||||
|
||||
//打开注释可测试
|
||||
//$orderid = "xxxxxxxx_xxxxxxxxxx_xxxxxxxx";//订单ID,从方法1返回值中获取
|
||||
//queryOrderState($orderid);
|
||||
|
||||
|
||||
|
||||
|
||||
//===========方法3.查询指定打印机某天的订单详情============
|
||||
//***接口返回值说明***
|
||||
//正确例子:{"msg":"ok","ret":0,"data":{"print":6,"waiting":1},"serverExecutedTime":9}
|
||||
|
||||
//打开注释可测试
|
||||
//$date = "2017-04-02";//注意时间格式为"yyyy-MM-dd",如2016-08-27
|
||||
//queryOrderInfoByDate(SN,$date);
|
||||
|
||||
|
||||
|
||||
|
||||
//===========方法4.查询打印机的状态==========================
|
||||
//***接口返回值说明***
|
||||
//正确例子:
|
||||
//{"msg":"ok","ret":0,"data":"离线","serverExecutedTime":9}
|
||||
//{"msg":"ok","ret":0,"data":"在线,工作状态正常","serverExecutedTime":9}
|
||||
//{"msg":"ok","ret":0,"data":"在线,工作状态不正常","serverExecutedTime":9}
|
||||
|
||||
//打开注释可测试
|
||||
//queryPrinterStatus(SN);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function addprinter($snlist){
|
||||
|
||||
$content = array(
|
||||
'user'=>USER,
|
||||
'stime'=>STIME,
|
||||
'sig'=>SIG,
|
||||
'apiname'=>'Open_printerAddlist',
|
||||
|
||||
'printerContent'=>$snlist
|
||||
);
|
||||
|
||||
$client = new HttpClient(IP,PORT);
|
||||
if(!$client->post(PATH,$content)){
|
||||
echo 'error';
|
||||
}
|
||||
else{
|
||||
echo $client->getContent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 方法1
|
||||
拼凑订单内容时可参考如下格式
|
||||
根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
|
||||
*/
|
||||
function wp_print($printer_sn,$orderInfo,$times){
|
||||
|
||||
$content = array(
|
||||
'user'=>USER,
|
||||
'stime'=>STIME,
|
||||
'sig'=>SIG,
|
||||
'apiname'=>'Open_printMsg',
|
||||
|
||||
'sn'=>$printer_sn,
|
||||
'content'=>$orderInfo,
|
||||
'times'=>$times//打印次数
|
||||
);
|
||||
|
||||
$client = new HttpClient(IP,PORT);
|
||||
if(!$client->post(PATH,$content)){
|
||||
echo 'error';
|
||||
}
|
||||
else{
|
||||
//服务器返回的JSON字符串,建议要当做日志记录起来
|
||||
echo $client->getContent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 方法2
|
||||
根据订单索引,去查询订单是否打印成功,订单索引由方法1返回
|
||||
*/
|
||||
function queryOrderState($index){
|
||||
$msgInfo = array(
|
||||
'user'=>USER,
|
||||
'stime'=>STIME,
|
||||
'sig'=>SIG,
|
||||
'apiname'=>'Open_queryOrderState',
|
||||
|
||||
'orderid'=>$index
|
||||
);
|
||||
|
||||
$client = new HttpClient(IP,PORT);
|
||||
if(!$client->post(PATH,$msgInfo)){
|
||||
echo 'error';
|
||||
}
|
||||
else{
|
||||
$result = $client->getContent();
|
||||
echo $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 方法3
|
||||
查询指定打印机某天的订单详情
|
||||
*/
|
||||
function queryOrderInfoByDate($printer_sn,$date){
|
||||
$msgInfo = array(
|
||||
'user'=>USER,
|
||||
'stime'=>STIME,
|
||||
'sig'=>SIG,
|
||||
'apiname'=>'Open_queryOrderInfoByDate',
|
||||
|
||||
'sn'=>$printer_sn,
|
||||
'date'=>$date
|
||||
);
|
||||
|
||||
$client = new HttpClient(IP,PORT);
|
||||
if(!$client->post(PATH,$msgInfo)){
|
||||
echo 'error';
|
||||
}
|
||||
else{
|
||||
$result = $client->getContent();
|
||||
echo $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 方法4
|
||||
查询打印机的状态
|
||||
*/
|
||||
function queryPrinterStatus($printer_sn){
|
||||
|
||||
$msgInfo = array(
|
||||
'user'=>USER,
|
||||
'stime'=>STIME,
|
||||
'sig'=>SIG,
|
||||
'apiname'=>'Open_queryPrinterStatus',
|
||||
|
||||
'sn'=>$printer_sn
|
||||
);
|
||||
|
||||
$client = new HttpClient(IP,PORT);
|
||||
if(!$client->post(PATH,$msgInfo)){
|
||||
echo 'error';
|
||||
}
|
||||
else{
|
||||
$result = $client->getContent();
|
||||
echo $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
309
longbingcore/printer/HttpClient.php
Normal file
309
longbingcore/printer/HttpClient.php
Normal file
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
namespace longbingcore\printer;
|
||||
|
||||
class HttpClient {
|
||||
// Request vars
|
||||
var $host;
|
||||
var $port;
|
||||
var $path;
|
||||
var $method;
|
||||
var $postdata = '';
|
||||
var $cookies = array();
|
||||
var $referer;
|
||||
var $accept = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,image/jpeg,image/gif,*/*';
|
||||
var $accept_encoding = 'gzip';
|
||||
var $accept_language = 'en-us';
|
||||
var $user_agent = 'Incutio HttpClient v0.9';
|
||||
var $timeout = 20;
|
||||
var $use_gzip = true;
|
||||
var $persist_cookies = true;
|
||||
var $persist_referers = true;
|
||||
var $debug = false;
|
||||
var $handle_redirects = true;
|
||||
var $max_redirects = 5;
|
||||
var $headers_only = false;
|
||||
var $username;
|
||||
var $password;
|
||||
var $status;
|
||||
var $headers = array();
|
||||
var $content = '';
|
||||
var $errormsg;
|
||||
var $redirect_count = 0;
|
||||
var $cookie_host = '';
|
||||
|
||||
function __construct($host, $port=80) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
}
|
||||
function get($path, $data = false) {
|
||||
$this->path = $path;
|
||||
$this->method = 'GET';
|
||||
if ($data) {
|
||||
$this->path .= '?'.$this->buildQueryString($data);
|
||||
}
|
||||
return $this->doRequest();
|
||||
}
|
||||
function post($path, $data) {
|
||||
$this->path = $path;
|
||||
$this->method = 'POST';
|
||||
$this->postdata = $this->buildQueryString($data);
|
||||
return $this->doRequest();
|
||||
}
|
||||
function buildQueryString($data) {
|
||||
$querystring = '';
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
foreach ($val as $val2) {
|
||||
$querystring .= urlencode($key).'='.urlencode($val2).'&';
|
||||
}
|
||||
} else {
|
||||
$querystring .= urlencode($key).'='.urlencode($val).'&';
|
||||
}
|
||||
}
|
||||
$querystring = substr($querystring, 0, -1); // Eliminate unnecessary &
|
||||
} else {
|
||||
$querystring = $data;
|
||||
}
|
||||
return $querystring;
|
||||
}
|
||||
function doRequest() {
|
||||
if (!$fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout)) {
|
||||
switch($errno) {
|
||||
case -3:
|
||||
$this->errormsg = 'Socket creation failed (-3)';
|
||||
case -4:
|
||||
$this->errormsg = 'DNS lookup failure (-4)';
|
||||
case -5:
|
||||
$this->errormsg = 'Connection refused or timed out (-5)';
|
||||
default:
|
||||
$this->errormsg = 'Connection failed ('.$errno.')';
|
||||
$this->errormsg .= ' '.$errstr;
|
||||
$this->debug($this->errormsg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
socket_set_timeout($fp, $this->timeout);
|
||||
$request = $this->buildRequest();
|
||||
$this->debug('Request', $request);
|
||||
fwrite($fp, $request);
|
||||
$this->headers = array();
|
||||
$this->content = '';
|
||||
$this->errormsg = '';
|
||||
$inHeaders = true;
|
||||
$atStart = true;
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
if ($atStart) {
|
||||
$atStart = false;
|
||||
if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
|
||||
$this->errormsg = "Status code line invalid: ".htmlentities($line);
|
||||
$this->debug($this->errormsg);
|
||||
return false;
|
||||
}
|
||||
$http_version = $m[1];
|
||||
$this->status = $m[2];
|
||||
$status_string = $m[3];
|
||||
$this->debug(trim($line));
|
||||
continue;
|
||||
}
|
||||
if ($inHeaders) {
|
||||
if (trim($line) == '') {
|
||||
$inHeaders = false;
|
||||
$this->debug('Received Headers', $this->headers);
|
||||
if ($this->headers_only) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) {
|
||||
continue;
|
||||
}
|
||||
$key = strtolower(trim($m[1]));
|
||||
$val = trim($m[2]);
|
||||
if (isset($this->headers[$key])) {
|
||||
if (is_array($this->headers[$key])) {
|
||||
$this->headers[$key][] = $val;
|
||||
} else {
|
||||
$this->headers[$key] = array($this->headers[$key], $val);
|
||||
}
|
||||
} else {
|
||||
$this->headers[$key] = $val;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$this->content .= $line;
|
||||
}
|
||||
fclose($fp);
|
||||
if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] == 'gzip') {
|
||||
$this->debug('Content is gzip encoded, unzipping it');
|
||||
$this->content = substr($this->content, 10);
|
||||
$this->content = gzinflate($this->content);
|
||||
}
|
||||
if ($this->persist_cookies && isset($this->headers['set-cookie']) && $this->host == $this->cookie_host) {
|
||||
$cookies = $this->headers['set-cookie'];
|
||||
if (!is_array($cookies)) {
|
||||
$cookies = array($cookies);
|
||||
}
|
||||
foreach ($cookies as $cookie) {
|
||||
if (preg_match('/([^=]+)=([^;]+);/', $cookie, $m)) {
|
||||
$this->cookies[$m[1]] = $m[2];
|
||||
}
|
||||
}
|
||||
$this->cookie_host = $this->host;
|
||||
}
|
||||
if ($this->persist_referers) {
|
||||
$this->debug('Persisting referer: '.$this->getRequestURL());
|
||||
$this->referer = $this->getRequestURL();
|
||||
}
|
||||
if ($this->handle_redirects) {
|
||||
if (++$this->redirect_count >= $this->max_redirects) {
|
||||
$this->errormsg = 'Number of redirects exceeded maximum ('.$this->max_redirects.')';
|
||||
$this->debug($this->errormsg);
|
||||
$this->redirect_count = 0;
|
||||
return false;
|
||||
}
|
||||
$location = isset($this->headers['location']) ? $this->headers['location'] : '';
|
||||
$uri = isset($this->headers['uri']) ? $this->headers['uri'] : '';
|
||||
if ($location || $uri) {
|
||||
$url = parse_url($location.$uri);
|
||||
return $this->get($url['path']);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function buildRequest() {
|
||||
$headers = array();
|
||||
$headers[] = "{$this->method} {$this->path} HTTP/1.0";
|
||||
$headers[] = "Host: {$this->host}";
|
||||
$headers[] = "User-Agent: {$this->user_agent}";
|
||||
$headers[] = "Accept: {$this->accept}";
|
||||
if ($this->use_gzip) {
|
||||
$headers[] = "Accept-encoding: {$this->accept_encoding}";
|
||||
}
|
||||
$headers[] = "Accept-language: {$this->accept_language}";
|
||||
if ($this->referer) {
|
||||
$headers[] = "Referer: {$this->referer}";
|
||||
}
|
||||
if ($this->cookies) {
|
||||
$cookie = 'Cookie: ';
|
||||
foreach ($this->cookies as $key => $value) {
|
||||
$cookie .= "$key=$value; ";
|
||||
}
|
||||
$headers[] = $cookie;
|
||||
}
|
||||
if ($this->username && $this->password) {
|
||||
$headers[] = 'Authorization: BASIC '.base64_encode($this->username.':'.$this->password);
|
||||
}
|
||||
if ($this->postdata) {
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
||||
$headers[] = 'Content-Length: '.strlen($this->postdata);
|
||||
}
|
||||
$request = implode("\r\n", $headers)."\r\n\r\n".$this->postdata;
|
||||
return $request;
|
||||
}
|
||||
function getStatus() {
|
||||
return $this->status;
|
||||
}
|
||||
function getContent() {
|
||||
return $this->content;
|
||||
}
|
||||
function getHeaders() {
|
||||
return $this->headers;
|
||||
}
|
||||
function getHeader($header) {
|
||||
$header = strtolower($header);
|
||||
if (isset($this->headers[$header])) {
|
||||
return $this->headers[$header];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function getError() {
|
||||
return $this->errormsg;
|
||||
}
|
||||
function getCookies() {
|
||||
return $this->cookies;
|
||||
}
|
||||
function getRequestURL() {
|
||||
$url = 'http://'.$this->host;
|
||||
if ($this->port != 80) {
|
||||
$url .= ':'.$this->port;
|
||||
}
|
||||
$url .= $this->path;
|
||||
return $url;
|
||||
}
|
||||
function setUserAgent($string) {
|
||||
$this->user_agent = $string;
|
||||
}
|
||||
function setAuthorization($username, $password) {
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
}
|
||||
function setCookies($array) {
|
||||
$this->cookies = $array;
|
||||
}
|
||||
function useGzip($boolean) {
|
||||
$this->use_gzip = $boolean;
|
||||
}
|
||||
function setPersistCookies($boolean) {
|
||||
$this->persist_cookies = $boolean;
|
||||
}
|
||||
function setPersistReferers($boolean) {
|
||||
$this->persist_referers = $boolean;
|
||||
}
|
||||
function setHandleRedirects($boolean) {
|
||||
$this->handle_redirects = $boolean;
|
||||
}
|
||||
function setMaxRedirects($num) {
|
||||
$this->max_redirects = $num;
|
||||
}
|
||||
function setHeadersOnly($boolean) {
|
||||
$this->headers_only = $boolean;
|
||||
}
|
||||
function setDebug($boolean) {
|
||||
$this->debug = $boolean;
|
||||
}
|
||||
function quickGet($url) {
|
||||
$bits = parse_url($url);
|
||||
$host = $bits['host'];
|
||||
$port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
if (isset($bits['query'])) {
|
||||
$path .= '?'.$bits['query'];
|
||||
}
|
||||
$client = new HttpClient($host, $port);
|
||||
if (!$client->get($path)) {
|
||||
return false;
|
||||
} else {
|
||||
return $client->getContent();
|
||||
}
|
||||
}
|
||||
function quickPost($url, $data) {
|
||||
$bits = parse_url($url);
|
||||
$host = $bits['host'];
|
||||
$port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
$client = new HttpClient($host, $port);
|
||||
if (!$client->post($path, $data)) {
|
||||
return false;
|
||||
} else {
|
||||
return $client->getContent();
|
||||
}
|
||||
}
|
||||
function debug($msg, $object = false) {
|
||||
if ($this->debug) {
|
||||
print '<div style="border: 1px solid red; padding: 0.5em; margin: 0.5em;"><strong>HttpClient Debug:</strong> '.$msg;
|
||||
if ($object) {
|
||||
ob_start();
|
||||
print_r($object);
|
||||
$content = htmlentities(ob_get_contents());
|
||||
ob_end_clean();
|
||||
print '<pre>'.$content.'</pre>';
|
||||
}
|
||||
print '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
167
longbingcore/printer/Printer.php
Normal file
167
longbingcore/printer/Printer.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2011 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: luofei614 <weibo.com/luofei614>
|
||||
// +----------------------------------------------------------------------
|
||||
// | 修改者: anuo (本权限类在原3.2.3的基础上修改过来的)
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace longbingcore\printer;
|
||||
|
||||
class Printer
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
* 飞鹅 打印/检查打印机状态
|
||||
* */
|
||||
public static function FeiePrintMsg($config , $orderInfo , $apiname = 'Open_printMsg',$time=1)
|
||||
{
|
||||
$content = array(
|
||||
'user' => $config['user'],
|
||||
'stime' => $_SERVER['REQUEST_TIME'],
|
||||
'sig' => sha1($config['user'] . $config['ukey'] . $_SERVER['REQUEST_TIME']),
|
||||
'apiname' => $apiname,
|
||||
|
||||
'sn' => $config['sn'],
|
||||
'content' => $orderInfo,
|
||||
'times' => $time
|
||||
);
|
||||
return self::getStream($content);
|
||||
|
||||
}
|
||||
/*
|
||||
* @param array $index 订单ID
|
||||
* 根据订单索引,去查询订单是否打印成功
|
||||
*
|
||||
* */
|
||||
public static function FeieQueryOrderState($config , $index){
|
||||
$msgInfo = array(
|
||||
'user' => $config['user'],
|
||||
'stime' => $_SERVER['REQUEST_TIME'],
|
||||
'sig' => sha1($config['user'] . $config['ukey'] . $_SERVER['REQUEST_TIME']),
|
||||
'apiname'=>'Open_queryOrderState',
|
||||
'orderid'=>$index
|
||||
);
|
||||
return self::getStream($msgInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request stream.
|
||||
* @param array $msgInfo
|
||||
* @return array
|
||||
*/
|
||||
protected static function getStream($msgInfo)
|
||||
{
|
||||
$client = new HttpClient('api.feieyun.cn',80);
|
||||
if(!$client->post('/Api/Open/',$msgInfo))
|
||||
return ['code' => false];
|
||||
else
|
||||
return json_decode($client->getContent(),true);
|
||||
}
|
||||
// 飞鹅 over
|
||||
|
||||
|
||||
|
||||
// 易联云
|
||||
|
||||
/**
|
||||
* 打印接口
|
||||
* @param int $partner 用户ID
|
||||
* @param string $machine_code 打印机终端号
|
||||
* @param string $content 打印内容
|
||||
* @param string $apiKey API密钥
|
||||
* @param string $msign 打印机密钥
|
||||
*/
|
||||
|
||||
public static function action_print($partner,$machine_code,$content,$apiKey,$msign)
|
||||
{
|
||||
$param = array(
|
||||
"partner"=>$partner,
|
||||
'machine_code'=>$machine_code,
|
||||
'time'=>time(),
|
||||
);
|
||||
|
||||
//获取签名
|
||||
$param['sign'] = self::generateSign($param,$apiKey,$msign);
|
||||
$param['content'] = $content;
|
||||
$str = self::getStr($param);
|
||||
return json_decode(self::sendCmd('http://open.10ss.net:8888',$str) , true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名sign
|
||||
* @param array $params 参数
|
||||
* @param string $apiKey API密钥
|
||||
* @param string $msign 打印机密钥
|
||||
* @return string sign
|
||||
*/
|
||||
|
||||
protected static function generateSign($params, $apiKey,$msign)
|
||||
{
|
||||
//所有请求参数按照字母先后顺序排
|
||||
ksort($params);
|
||||
//定义字符串开始所包括的字符串
|
||||
$stringToBeSigned = $apiKey;
|
||||
//把所有参数名和参数值串在一起
|
||||
foreach ($params as $k => $v)
|
||||
{
|
||||
$stringToBeSigned .= urldecode($k.$v);
|
||||
}
|
||||
unset($k, $v);
|
||||
//定义字符串结尾所包括的字符串
|
||||
$stringToBeSigned .= $msign;
|
||||
//使用MD5进行加密,再转化成大写
|
||||
return strtoupper(md5($stringToBeSigned));
|
||||
}
|
||||
/**
|
||||
* 生成字符串参数
|
||||
* @param array $param 参数
|
||||
* @return string 参数字符串
|
||||
*/
|
||||
protected static function getStr($param)
|
||||
{
|
||||
$str = '';
|
||||
foreach ($param as $key => $value) {
|
||||
$str=$str.$key.'='.$value.'&';
|
||||
}
|
||||
$str = rtrim($str,'&');
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起请求
|
||||
* @param string $url 请求地址
|
||||
* @param string $data 请求数据包
|
||||
* @return string 请求返回数据
|
||||
*/
|
||||
|
||||
protected static function sendCmd($url,$data)
|
||||
{
|
||||
$curl = curl_init(); // 启动一个CURL会话
|
||||
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:')); //解决数据包大不能提交
|
||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
|
||||
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
|
||||
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
|
||||
|
||||
$tmpInfo = curl_exec($curl); // 执行操作
|
||||
if (curl_errno($curl)) {
|
||||
echo 'Errno'.curl_error($curl);
|
||||
}
|
||||
curl_close($curl); // 关键CURL会话
|
||||
return $tmpInfo; // 返回数据
|
||||
}
|
||||
}
|
||||
112
longbingcore/tools/LongbingArr.php
Normal file
112
longbingcore/tools/LongbingArr.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\tools;
|
||||
|
||||
|
||||
class LongbingArr
|
||||
{
|
||||
/**
|
||||
* 根据Key删除素组值
|
||||
*
|
||||
* @param $arr
|
||||
* @param $key str\array
|
||||
* @return mixed
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/25 17:32
|
||||
*/
|
||||
public static function delBykey($arr , $key)
|
||||
{
|
||||
|
||||
|
||||
if(is_array($key)){
|
||||
foreach ($key as $k => $v){
|
||||
$arr = self::delBykey($arr , $v);
|
||||
}
|
||||
return $arr ;
|
||||
}
|
||||
|
||||
if(!array_key_exists($key, $arr)){
|
||||
return $arr;
|
||||
}
|
||||
$keys = array_keys($arr);
|
||||
$index = array_search($key, $keys);
|
||||
if($index !== FALSE){
|
||||
array_splice($arr, $index, 1);
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除多维数组,根据
|
||||
*
|
||||
* @param $array
|
||||
* @param $key
|
||||
* @return array
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/25 22:37
|
||||
*
|
||||
* demo
|
||||
* $details = array(
|
||||
* 0 => array("id"=>"1", "name"=>"Mike", "num"=>"9876543210"),
|
||||
* 1 => array("id"=>"2", "name"=>"Carissa", "num"=>"08548596258"),
|
||||
* 2 => array("id"=>"1", "name"=>"Mathew", "num"=>"784581254"),
|
||||
* );
|
||||
* $details = unique_multidim_array($details,'id');
|
||||
* Output will be like this :
|
||||
* $details = array(
|
||||
* 0 => array("id"=>"1","name"=>"Mike","num"=>"9876543210"),
|
||||
* 1 => array("id"=>"2","name"=>"Carissa","num"=>"08548596258"),
|
||||
* );
|
||||
*/
|
||||
public static function unique_multidim_array($array, $key) {
|
||||
$temp_array = array();
|
||||
$i = 0;
|
||||
$key_array = array();
|
||||
|
||||
foreach($array as $val) {
|
||||
if (!in_array($val[$key], $key_array)) {
|
||||
$key_array[$i] = $val[$key];
|
||||
$temp_array[$i] = $val;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return $temp_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 把所有的一级数组进行合并,主要用于 event 返回数据进行合并
|
||||
*
|
||||
* @param $array
|
||||
* @return mixed
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/26 11:04
|
||||
*
|
||||
* demo
|
||||
*
|
||||
* $array = [ [0,1,2] , [3,4] ]] ;
|
||||
* LongbingArr::array_merge($array);
|
||||
* $returnArray = [0,1,2,3,4] ;
|
||||
*/
|
||||
public static function array_merge($array){
|
||||
$returnArr = [];
|
||||
foreach ($array as $item){
|
||||
if(!empty($item)) $returnArr = array_merge($returnArr,$item);
|
||||
}
|
||||
return $returnArr;
|
||||
}
|
||||
|
||||
}
|
||||
53
longbingcore/tools/LongbingDefault.php
Normal file
53
longbingcore/tools/LongbingDefault.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\tools;
|
||||
|
||||
|
||||
class LongbingDefault
|
||||
{
|
||||
public static $avatarImgUrl = 'https://retail.xiaochengxucms.com/defaultAvatar.png' ;
|
||||
public static $notImgUrl = 'https://retail.xiaochengxucms.com/lbCardDefaultImage.png' ;
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $target
|
||||
* @param $default
|
||||
* @param $defaultArr
|
||||
* @功能说明: 格式换默认图片
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020/1/17 11:32
|
||||
*/
|
||||
public static function formatDefaultImage ( $data, $target, $default, $defaultArr )
|
||||
{
|
||||
|
||||
foreach ( $data as $index => $item )
|
||||
{
|
||||
if ( is_array( $item ) )
|
||||
{
|
||||
$data[ $index ] = formatDefaultImage( $item, $target, $default, $defaultArr );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($index == $target && $item == '' && isset($defaultArr[$default]))
|
||||
{
|
||||
$data[$index] = $defaultArr[$default];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
47
longbingcore/tools/LongbingImg.php
Normal file
47
longbingcore/tools/LongbingImg.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\tools;
|
||||
|
||||
|
||||
class LongbingImg
|
||||
{
|
||||
/**
|
||||
* 检查远程图片是否存在
|
||||
*
|
||||
* @param $imgUrl
|
||||
* @return bool
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/28 10:17
|
||||
*/
|
||||
public static function exits($imgUrl) {
|
||||
|
||||
if(empty($imgUrl)){
|
||||
return false ;
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL,$imgUrl);
|
||||
curl_setopt($ch, CURLOPT_NOBODY, 1); // 不下载
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
if(curl_exec($ch)!==false)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
37
longbingcore/tools/LongbingStr.php
Normal file
37
longbingcore/tools/LongbingStr.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\tools;
|
||||
|
||||
|
||||
class LongbingStr
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @功能说明:转utf 8
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-01-03 19:23
|
||||
*/
|
||||
|
||||
static public function strToUtf8($str){
|
||||
$encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
|
||||
if($encode == 'UTF-8'){
|
||||
return $str;
|
||||
}else{
|
||||
return mb_convert_encoding($str, 'UTF-8', $encode);
|
||||
}
|
||||
}
|
||||
}
|
||||
76
longbingcore/tools/LongbingTime.php
Normal file
76
longbingcore/tools/LongbingTime.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace longbingcore\tools;
|
||||
|
||||
|
||||
class LongbingTime
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @功能说明:转utf 8
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-01-03 19:23
|
||||
*/
|
||||
|
||||
public static function getChinaNowTime(){
|
||||
return date('Y-m-d H:i:s', time() ) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param string $field
|
||||
* @功能说明:格式化友好时间
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020/1/17 10:26
|
||||
*/
|
||||
public static function frendlyTime ( $data, $field = 'create_time' )
|
||||
{
|
||||
// 今天的时间戳
|
||||
$time = time();
|
||||
// 昨天的时间戳
|
||||
$Yesterday = $time - (24 * 60 * 60);
|
||||
|
||||
$today = mktime(0, 0, 0, date("m", $time), date("d", $time), date("Y", $time));
|
||||
$Yesterday = mktime(0, 0, 0, date("m", $Yesterday), date("d", $Yesterday), date("Y", $Yesterday));
|
||||
|
||||
foreach ($data as $index => $item) {
|
||||
$tmpTime = $item[$field];
|
||||
if ($tmpTime > $today) {
|
||||
// $data[ $index ][ 'radar_time' ] = '今天 ';
|
||||
$data[$index]['radar_group'] = '今天';
|
||||
$data[$index]['radar_time'] = date('H:i', $item[$field]);
|
||||
} else if ($tmpTime > $Yesterday) {
|
||||
// $data[ $index ][ 'radar_time' ] = '昨天 ';
|
||||
$data[$index]['radar_group'] = '昨天';
|
||||
$data[$index]['radar_time'] = date('H:i', $item[$field]);
|
||||
} else {
|
||||
$thisYear = date('Y');
|
||||
$itemYear = date('Y', $item[$field]);
|
||||
if ($thisYear == $itemYear) {
|
||||
$data[$index]['radar_group'] = date('m-d', $item[$field]);
|
||||
$data[$index]['radar_time'] = date(' H:i', $item[$field]);
|
||||
} else {
|
||||
$data[$index]['radar_group'] = date('Y-m-d', $item[$field]);
|
||||
$data[$index]['radar_time'] = date(' H:i', $item[$field]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
529
longbingcore/wxcore/DadaApi.php
Normal file
529
longbingcore/wxcore/DadaApi.php
Normal file
@@ -0,0 +1,529 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 达达开放平台sdk
|
||||
* User: 仝帅
|
||||
* Date: 2016-12-19
|
||||
* Time: 16:48
|
||||
*/
|
||||
class DadaApi
|
||||
{
|
||||
//private $URL = 'http://newopen.qa.imdada.cn';
|
||||
private $URL = 'http://newopen.imdada.cn';
|
||||
private $APP_KEY = '';
|
||||
private $VERSION = '1.0';
|
||||
private $APP_SECRET = '';
|
||||
private $API_ADDORDER = '/api/order/addOrder';
|
||||
private $API_FETCHORDER = '/api/order/fetch';
|
||||
private $API_CITY_LIST = "/api/cityCode/list";
|
||||
private $API_FINISHORDER = '/api/order/finish';
|
||||
private $API_CANCELORDER = '/api/order/cancel';
|
||||
private $API_EXPIREORDER = '/api/order/expire';
|
||||
private $API_FORMALCANCEL = '/api/order/formalCancel';
|
||||
private $API_CANCELREASONS = '/api/order/cancel/reasons';
|
||||
private $API_ACCEPTORDER = '/api/order/accept';
|
||||
private $API_ADDTIP = '/api/order/addTip';
|
||||
private $API_READDORDER = '/api/order/reAddOrder';
|
||||
|
||||
private $API_QUERYDELIVERFEE = '/api/order/queryDeliverFee';
|
||||
private $API_ADDAFTERQUERY = '/api/order/addAfterQuery';
|
||||
private $API_ADDSHOP = '/api/shop/add';
|
||||
private $API_ADDMERCHANT = '/merchantApi/merchant/add';
|
||||
|
||||
private $API_ORDERINFO = '/api/order/status/query';
|
||||
|
||||
|
||||
private $SOURCE_ID = '73753'; //商户编号
|
||||
private $SHOP_NO = '11047059'; //门店编号
|
||||
private $SUCCESS = "success";
|
||||
private $FAIL = "fail";
|
||||
|
||||
private $call_back;
|
||||
|
||||
public function __construct($appkey,$appsec,$source_id,$shop_no)
|
||||
{
|
||||
$this->APP_KEY = $appkey;
|
||||
|
||||
$this->APP_SECRET = $appsec;
|
||||
|
||||
$this->SHOP_NO = $shop_no;
|
||||
|
||||
$this->SOURCE_ID = $source_id;
|
||||
|
||||
$this->incon = '?';
|
||||
|
||||
// dump($this->APP_KEY , $this->APP_SECRET, $this->SHOP_NO , $this->SOURCE_ID);exit;
|
||||
|
||||
if(longbingIsWeiqin()){
|
||||
|
||||
// $url = substr($this->request->url(),0,strpos($this->request->url(), '&s='));
|
||||
|
||||
$params = $_GET;
|
||||
|
||||
$i=$params['i'];
|
||||
|
||||
$t=$params['t'];
|
||||
|
||||
$v=$params['v'];
|
||||
|
||||
$n=$params['m'];
|
||||
|
||||
$this->call_back = "https://".$_SERVER['HTTP_HOST']."/app/index.php?i=$i&t=".$t."&v=".$v."&from=wxapp&c=entry&a=wxapp&do=api&core=core2&m=".$n."&s=restaurant/SendResult/dadaSend";
|
||||
|
||||
// $this->call_back = 'http://'. $_SERVER['HTTP_HOST'].$url.'&s=/restaurant/SendResult/dadaSend';
|
||||
|
||||
$this->incon = '&';
|
||||
}else{
|
||||
|
||||
$this->call_back = 'http://'. $_SERVER['HTTP_HOST'].'/restaurant/SendResult/dadaSend';
|
||||
|
||||
$this->incon = '?';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 新增订单
|
||||
* @return bool
|
||||
*/
|
||||
public function addOrder($data)
|
||||
{
|
||||
|
||||
$city_code = $this->cityCode($data['city']);
|
||||
|
||||
if(!empty($city_code['code'])&&$city_code['code']==500){
|
||||
|
||||
return $city_code;
|
||||
|
||||
}
|
||||
|
||||
$arr = [
|
||||
|
||||
'shop_no' => $this->SHOP_NO,
|
||||
|
||||
'origin_id' => $data['order_code'],
|
||||
|
||||
'city_code' => $city_code,
|
||||
|
||||
'is_prepay' => 0,
|
||||
|
||||
'cargo_price' => $data['pay_price'],
|
||||
|
||||
'receiver_name' => $data['address']['name'],
|
||||
|
||||
'receiver_address' => $data['address']['address'].$data['address']['info'],
|
||||
|
||||
'receiver_phone' => $data['address']['phone'],
|
||||
|
||||
'receiver_lat' => $data['address']['lat'],
|
||||
|
||||
'receiver_lng' => $data['address']['long'],
|
||||
|
||||
'callback' => $this->call_back.$this->incon.'id='.$data['id'],
|
||||
|
||||
'cargo_weight' => $data['weight']
|
||||
|
||||
];
|
||||
|
||||
$res = self::getResult($this->API_ADDORDER,$arr);
|
||||
|
||||
|
||||
// dump($this->SHOP_NO,$res);exit;
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新发布订单
|
||||
* 在调用新增订单后,订单被取消、过期或者投递异常的情况下,调用此接口,可以在达达平台重新发布订单。
|
||||
* @return bool
|
||||
*/
|
||||
public function reAddOrder($data)
|
||||
{
|
||||
|
||||
$arr = [
|
||||
|
||||
'shop_no' => $this->SHOP_NO,
|
||||
|
||||
'origin_id' => $data['order_code'],
|
||||
|
||||
'city_code' => $this->cityCode($data['city']),
|
||||
|
||||
'is_prepay' => 0,
|
||||
|
||||
'cargo_price' => $data['pay_price'],
|
||||
|
||||
'receiver_name' => $data['address']['name'],
|
||||
|
||||
'receiver_address' => $data['address']['address'].$data['address']['info'],
|
||||
|
||||
'receiver_phone' => $data['address']['phone'],
|
||||
|
||||
'receiver_lat' => $data['address']['lat'],
|
||||
|
||||
'receiver_lng' => $data['address']['long'],
|
||||
|
||||
'callback' => $this->call_back.$this->incon.'id='.$data['id'],
|
||||
|
||||
'cargo_weight' => $data['weight']
|
||||
|
||||
];
|
||||
return self::getResult($this->API_READDORDER,$arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单运费接口
|
||||
* @return bool
|
||||
*/
|
||||
public function queryDeliverFee($data)
|
||||
{
|
||||
$data['shop_no'] = $this->SHOP_NO;
|
||||
|
||||
$arr = [
|
||||
|
||||
'shop_no' => $this->SHOP_NO,
|
||||
|
||||
'origin_id' => $data['id'],
|
||||
|
||||
'city_code' => $this->cityCode($data['city']),
|
||||
|
||||
'is_prepay' => 0,
|
||||
|
||||
'receiver_name' => $data['address']['name'],
|
||||
|
||||
'receiver_address' => $data['address']['address'].$data['address']['info'],
|
||||
|
||||
'receiver_phone' => $data['address']['phone'],
|
||||
|
||||
'receiver_lat' => $data['address']['lat'],
|
||||
|
||||
'receiver_lng' => $data['address']['long'],
|
||||
|
||||
'callback' => $this->call_back.$this->incon.'id='.$data['id'],
|
||||
|
||||
'cargo_weight' => $data['weight']
|
||||
|
||||
];
|
||||
|
||||
// dump($this->call_back.'/id/'.$data['id']);exit;
|
||||
return self::getResult($this->API_QUERYDELIVERFEE,$arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询运费后发单接口
|
||||
*/
|
||||
public function addAfterQuery($data)
|
||||
{
|
||||
|
||||
|
||||
return self::getResult($this->API_ADDAFTERQUERY,$data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询运费后发单接口
|
||||
*/
|
||||
public function orderInfo($data)
|
||||
{
|
||||
|
||||
$arr['order_id'] = $data['order_code'];
|
||||
// dump($data);exit;
|
||||
// $data['deliveryNo'] = '';
|
||||
return self::getResult($this->API_ORDERINFO,$arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单(线上环境)
|
||||
* 在订单待接单或待取货情况下,调用此接口可取消订单。注意:订单接单后1-15分钟取消订单,会扣除相应费用补贴给接单达达
|
||||
* @return bool
|
||||
*/
|
||||
public function formalCancel($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
// $data['cancel_reason_id'] = '1';
|
||||
// $data['cancel_reason'] = "";
|
||||
return self::getResult($this->API_FORMALCANCEL,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function cancelOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_CANCELORDER,$data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加小费
|
||||
* 可以对待接单状态的订单增加小费。需要注意:订单的小费,以最新一次加小费动作的金额为准,故下一次增加小费额必须大于上一次小费额。
|
||||
* @return bool
|
||||
*/
|
||||
public function addTip($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
// $data['tips'] = '2.5';
|
||||
// $data['city_code'] = '029';
|
||||
// $data['info'] = '';
|
||||
return self::getResult($this->API_ADDTIP,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增门店
|
||||
* @return bool
|
||||
*/
|
||||
public function addShop($data)
|
||||
{
|
||||
// $data['origin_shop_id'] = '';
|
||||
// $data['station_name'] = '';
|
||||
// $data['business'] = '';
|
||||
// $data['city_name'] = '';
|
||||
// $data['area_name'] = '';
|
||||
// $data['station_address'] = '';
|
||||
// $data['lng'] = '';
|
||||
// $data['lat'] = '';
|
||||
// $data['contact_name'] = '';
|
||||
// $data['phone'] = '';
|
||||
// $data['username'] = '';
|
||||
// $data['password'] = '';
|
||||
return self::getResult($this->API_ADDSHOP,$data);
|
||||
}
|
||||
|
||||
public function addMerchant($data)
|
||||
{
|
||||
// $data['mobile'] = '';
|
||||
// $data['city_name'] = '';
|
||||
// $data['enterprise_name'] = '';
|
||||
// $data['enterprise_address'] = '';
|
||||
// $data['contact_name'] = '';
|
||||
// $data['contact_phone'] = '';
|
||||
$this->SOURCE_ID = '';
|
||||
return self::getResult($this->API_ADDMERCHANT,$data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取取消订单原因列表
|
||||
* array {0 =>array{'reason' =>'没有达达接单','id' =>1},....}
|
||||
*/
|
||||
public function cancelReasons()
|
||||
{
|
||||
$res = self::getResult($this->API_CANCELREASONS);
|
||||
var_dump($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接单(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function acceptOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_ACCEPTORDER,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成取货(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function fetchOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_FETCHORDER,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成订单(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function finishOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_FINISHORDER,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单过期(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function expireOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_EXPIREORDER,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单状态变化后,达达回调我们
|
||||
*/
|
||||
public function processCallback()
|
||||
{
|
||||
$content = file_get_contents("php://input");
|
||||
//{"order_status":2,"cancel_reason":"","update_time":1482220973,"dm_id":666,"signature":"7a177ae4b1cf63d13261580e4f721cb9","dm_name":"测试达达","order_id":"12321","client_id":"","dm_mobile":"13546670420"}
|
||||
if($content){
|
||||
$arr = json_decode($content,true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取城市信息
|
||||
* @return bool
|
||||
*/
|
||||
public function cityCode($city){
|
||||
|
||||
$code = 0;
|
||||
|
||||
$data = self::getResult($this->API_CITY_LIST);
|
||||
|
||||
if(empty($data['result'])){
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
$city = str_replace('市','',$city);
|
||||
|
||||
$found_key = array_search($city, array_column($data['result'], 'cityName'));
|
||||
|
||||
if(!is_numeric($found_key)){
|
||||
|
||||
return ['code'=>500,'msg'=>'达达暂不支持该城市'];
|
||||
}
|
||||
|
||||
if(key_exists($found_key,$data['result'])){
|
||||
|
||||
$code = $data['result'][$found_key]['cityCode'];
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $param
|
||||
* @param $time
|
||||
* @return string
|
||||
*/
|
||||
private function sign($param,$time)
|
||||
{
|
||||
$tmpArr = array(
|
||||
"app_key"=>$this->APP_KEY,
|
||||
"body"=>$param,
|
||||
"format"=>"json",
|
||||
"source_id"=>$this->SOURCE_ID,
|
||||
"timestamp"=>$time,
|
||||
"v"=>$this->VERSION,
|
||||
);
|
||||
|
||||
// dump($tmpArr);exit;
|
||||
if(empty($this->SOURCE_ID)){
|
||||
unset($tmpArr['source_id']);
|
||||
}
|
||||
$str = '';
|
||||
foreach ($tmpArr as $k=>$v){
|
||||
$str .= $k.$v;
|
||||
}
|
||||
$str = $this->APP_SECRET.$str.$this->APP_SECRET;
|
||||
$signature = md5($str);
|
||||
|
||||
// dump($signature);exit;
|
||||
return strtoupper($signature);
|
||||
}
|
||||
|
||||
private function getParam($data='')
|
||||
{
|
||||
if(empty($data)){
|
||||
$param = '';
|
||||
}else{
|
||||
$param = json_encode($data);
|
||||
}
|
||||
$time = time();
|
||||
$sign = self::sign($param,$time);
|
||||
$tmpArr = array(
|
||||
"app_key"=>$this->APP_KEY,
|
||||
"body"=>$param,
|
||||
"format"=>"json",
|
||||
"signature"=>$sign,
|
||||
"source_id"=>$this->SOURCE_ID,
|
||||
"timestamp"=>$time,
|
||||
"v"=>$this->VERSION,
|
||||
);
|
||||
if(empty($this->SOURCE_ID)){
|
||||
unset($tmpArr['source_id']);
|
||||
}
|
||||
|
||||
return json_encode($tmpArr);
|
||||
}
|
||||
|
||||
/** 根据参数获取结果信息
|
||||
* @param $api
|
||||
* @param string $data
|
||||
* @return bool
|
||||
*/
|
||||
private function getResult($api,$data=''){
|
||||
$param = self::getParam($data);
|
||||
|
||||
$url = $this->URL.$api;
|
||||
$res = self::http_post($url,$param);
|
||||
|
||||
if($res){
|
||||
$res = json_decode($res,true);
|
||||
// if($res['status'] == $this->SUCCESS){
|
||||
return $res;
|
||||
// }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求
|
||||
* @param string $url
|
||||
* @param array $param
|
||||
* @param boolean $post_file 是否文件上传
|
||||
* @return string content
|
||||
*/
|
||||
private function http_post($url,$param,$post_file=false){
|
||||
$oCurl = curl_init();
|
||||
if(stripos($url,"https://")!==FALSE){
|
||||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
|
||||
}
|
||||
if (is_string($param) || $post_file) {
|
||||
$strPOST = $param;
|
||||
} else {
|
||||
$aPOST = array();
|
||||
foreach($param as $key=>$val){
|
||||
$aPOST[] = $key."=".urlencode($val);
|
||||
}
|
||||
$strPOST = join("&", $aPOST);
|
||||
}
|
||||
curl_setopt($oCurl, CURLOPT_URL, $url);
|
||||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
|
||||
curl_setopt($oCurl, CURLOPT_POST,true);
|
||||
curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
|
||||
$header = array(
|
||||
'Content-Type: application/json',
|
||||
);
|
||||
curl_setopt($oCurl, CURLOPT_HTTPHEADER, $header);
|
||||
|
||||
$sContent = curl_exec($oCurl);
|
||||
$aStatus = curl_getinfo($oCurl);
|
||||
curl_close($oCurl);
|
||||
if(intval($aStatus["http_code"])==200){
|
||||
return $sContent;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
298
longbingcore/wxcore/Excel.php
Normal file
298
longbingcore/wxcore/Excel.php
Normal file
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class Excel{
|
||||
|
||||
// static protected $uniacid;
|
||||
//
|
||||
// public function __construct($uniacid)
|
||||
// {
|
||||
// self::$uniacid = $uniacid;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @功能说明:读取excel文件 返回一个数组
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-02-13 18:21
|
||||
*/
|
||||
public function readExcel($filename){
|
||||
|
||||
//引用excel库
|
||||
require_once EXTEND_PATH.'PHPExcel/PHPExcel.php';
|
||||
//判断是否文件
|
||||
if(empty($filename)||!is_file($filename)){
|
||||
return '该文件错误';
|
||||
}
|
||||
//准备打开文件
|
||||
$objReader = \PHPExcel_IOFactory::createReaderForFile($filename);
|
||||
//载入文件
|
||||
$objPHPExcel = $objReader->load($filename);
|
||||
//设置第一个Sheet
|
||||
$objPHPExcel->setActiveSheetIndex(0);
|
||||
|
||||
$sheet = $objPHPExcel->getSheet(0);
|
||||
|
||||
$highestRow = $sheet->getHighestRow();
|
||||
|
||||
$highestColumn = $sheet->getHighestColumn();
|
||||
|
||||
for ($row = 2; $row <= $highestRow; $row++){
|
||||
//每一个文件
|
||||
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
|
||||
|
||||
$data[] = $rowData;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* User: chenniang
|
||||
* Date: 2019-09-10 10:47
|
||||
* @return \think\Response
|
||||
* descption:phpExcel 导出方法
|
||||
*/
|
||||
function excelExport($fileName = '', $headArr = [], $data = [],$type='',$status=0) {
|
||||
require_once EXTEND_PATH.'PHPExcel/PHPExcel.php';
|
||||
|
||||
ini_set("memory_limit", "1024M"); // 设置php可使用内存
|
||||
|
||||
set_time_limit(30);
|
||||
# 设置执行时间最大值
|
||||
// if(empty($fileName)){
|
||||
|
||||
$fileName .= ".xls";
|
||||
// }
|
||||
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
|
||||
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
||||
|
||||
$objPHPExcel->getProperties();
|
||||
|
||||
$key = ord("A"); // 设置表头
|
||||
|
||||
//dump($headArr);exit;
|
||||
$key2 = ord("@"); //64
|
||||
|
||||
foreach ($headArr as $v) {
|
||||
|
||||
$e=mb_detect_encoding($v, array('UTF-8', 'GBK'));
|
||||
|
||||
if($e!='UTF-8') {
|
||||
|
||||
$v = mb_convert_encoding($v, "UTF-8", "GBK");
|
||||
}
|
||||
|
||||
if($key > ord("Z"))
|
||||
{
|
||||
$colum = chr(ord("A")).chr(++$key2);//超过26个字母 AA1,AB1,AC1,AD1...BA1,BB1...
|
||||
}
|
||||
else
|
||||
{
|
||||
$colum = chr($key++);
|
||||
}
|
||||
|
||||
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
|
||||
|
||||
}
|
||||
$column = 2;
|
||||
|
||||
$objActSheet = $objPHPExcel->getActiveSheet(0);
|
||||
|
||||
if($type == 1){
|
||||
//合并名片的单元格
|
||||
$this->mergeCard($objPHPExcel);
|
||||
}
|
||||
|
||||
$fileName = iconv("utf-8", "GBK", $fileName);
|
||||
|
||||
foreach ($data as $key => $rows) { // 行写入
|
||||
|
||||
$span = ord("A");
|
||||
|
||||
$key2 = ord("@"); //64
|
||||
|
||||
foreach ($rows as $keyName => $value) { // 列写入
|
||||
|
||||
if($span > ord("Z"))
|
||||
{
|
||||
$colum = chr(ord("A")).chr(++$key2);//超过26个字母 AA1,AB1,AC1,AD1...BA1,BB1...
|
||||
}
|
||||
else
|
||||
{
|
||||
$colum = chr($span);
|
||||
}
|
||||
|
||||
if(!empty($value)&&is_string($value)){
|
||||
|
||||
$e=mb_detect_encoding($value, array('UTF-8', 'GBK'));
|
||||
|
||||
$value = $this->filterEmoji($value);
|
||||
|
||||
if($e!='UTF-8'){
|
||||
|
||||
$value = mb_convert_encoding($value, "UTF-8", "GBK");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$objActSheet->setCellValueExplicit($colum . $column, $value);
|
||||
|
||||
$span++;
|
||||
}
|
||||
$column++;
|
||||
}
|
||||
|
||||
if(!empty($status)){
|
||||
|
||||
$this->mergeOrderExcel($objPHPExcel,$data,$status);
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
|
||||
header("Content-Disposition: attachment;filename=$fileName");
|
||||
|
||||
header('Cache-Control: max-age=0');
|
||||
|
||||
header('content-Type:application/vnd.ms-excel;charset=utf-8');
|
||||
|
||||
$objWriter->save('php://output');// 文件通过浏览器下载
|
||||
|
||||
return $fileName;
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $obj
|
||||
* @param $data
|
||||
* 合并订单单元格
|
||||
*/
|
||||
public function mergeOrderExcel($obj,$data,$status=1){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
if(!empty($v)){
|
||||
|
||||
$v['key'] = $k+2;
|
||||
|
||||
$newdata[$v[0]][] = $v;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
switch ($status){
|
||||
case '1' :
|
||||
$arr = ['A','E','F','G','H','I','J','K','L','M','N','O','P'];
|
||||
break;
|
||||
|
||||
case '2' :
|
||||
$arr = ['A','E','F','G','H','I','J','K','L','M','N','O'];
|
||||
break;
|
||||
case '3' :
|
||||
$arr = ['A','F','G','H','I','J','K','L'];
|
||||
break;
|
||||
|
||||
}
|
||||
foreach ($newdata as $k=>$v){
|
||||
if(count($v)>1){
|
||||
$count = count($v)-1;
|
||||
foreach ($arr as $value){
|
||||
$me = $value.$v[0]['key'].':'.$value.$v[$count]['key'];
|
||||
|
||||
$obj->getActiveSheet()->mergeCells($me);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return string|string[]|null
|
||||
* 过滤表情包
|
||||
*/
|
||||
public function filterEmoji($str)
|
||||
{
|
||||
$str = preg_replace_callback(
|
||||
'/./u',
|
||||
function (array $match) {
|
||||
return strlen($match[0]) >= 4 ? '' : $match[0];
|
||||
},
|
||||
$str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-15 15:19
|
||||
* @功能说明:合并订单导出的单元格
|
||||
*/
|
||||
public function mergeCard($objPHPExcel){
|
||||
|
||||
|
||||
$arr = ['A','B','C','D'];
|
||||
|
||||
foreach ($arr as $value){
|
||||
|
||||
$s_icon = $value.'1'.':'.$value.'2';
|
||||
|
||||
$h_icon = $value.'1';
|
||||
|
||||
$objPHPExcel->getActiveSheet()->mergeCells($s_icon);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getstyle($s_icon)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle($h_icon)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
}
|
||||
|
||||
$arr2 = ['E1:F1','G1:H1','I1:J1','K1:L1','M1:N1','O1:P1'];
|
||||
|
||||
foreach ($arr2 as $value){
|
||||
|
||||
|
||||
$objPHPExcel->getActiveSheet()->mergeCells($value);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getstyle($value)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle($value)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
}
|
||||
|
||||
$arr3 = ['E2','F2','G2','H2','I2','J2','K2','L2','M2','N2','O2','P2'];
|
||||
|
||||
foreach ($arr3 as $value){
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle($value)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
178
longbingcore/wxcore/PayModel.php
Normal file
178
longbingcore/wxcore/PayModel.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\ApiRest;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class PayModel extends ApiRest {
|
||||
|
||||
// static protected $uniacid;
|
||||
|
||||
public function __construct($pay_config)
|
||||
{
|
||||
$this->pay_config = $pay_config;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-17 14:36
|
||||
* @功能说明:
|
||||
*/
|
||||
public function findOrder(){
|
||||
|
||||
$pay_config = $this->payConfig();
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/AopClient.php';
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/request/AlipayTradeQueryRequest.php';
|
||||
|
||||
$aop = new \AopClient ();
|
||||
|
||||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||||
// $aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
|
||||
|
||||
$aop->appId = $pay_config[ 'payment' ][ 'ali_appid' ];
|
||||
|
||||
$aop->rsaPrivateKey = $pay_config['payment']['ali_privatekey'];
|
||||
|
||||
$aop->alipayrsaPublicKey=$pay_config['payment']['ali_publickey'];
|
||||
$aop->apiVersion = '1.0';
|
||||
$aop->signType = 'RSA2';
|
||||
$aop->postCharset='UTF-8';
|
||||
$aop->format='json';
|
||||
$object = new \stdClass();
|
||||
$object->out_trade_no = '20150320010101001';
|
||||
//$object->trade_no = '2014112611001004680073956707';
|
||||
$json = json_encode($object);
|
||||
$request = new \AlipayTradeQueryRequest();
|
||||
$request->setBizContent($json);
|
||||
|
||||
$result = $aop->execute ( $request);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-10 16:36
|
||||
* @功能说明:支付宝支付
|
||||
*/
|
||||
public function aliPay($order_code,$price,$subject){
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/AopClient.php';
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/request/AlipayTradeAppPayRequest.php';
|
||||
|
||||
$pay_config = $this->payConfig();
|
||||
|
||||
$aop = new \AopClient ();
|
||||
|
||||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||||
|
||||
$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
|
||||
|
||||
$aop->appId = $pay_config[ 'payment' ][ 'ali_appid' ];
|
||||
|
||||
$aop->rsaPrivateKey = $pay_config['payment']['ali_privatekey'];;
|
||||
|
||||
$aop->alipayrsaPublicKey= $pay_config['payment']['ali_publickey'];;
|
||||
|
||||
$aop->apiVersion = '1.0';
|
||||
|
||||
$aop->signType = 'RSA2';
|
||||
|
||||
$aop->postCharset='UTF-8';
|
||||
|
||||
$aop->format='json';
|
||||
|
||||
$object = new \stdClass();
|
||||
|
||||
$object->out_trade_no = $order_code;
|
||||
|
||||
$object->total_amount = $price;
|
||||
|
||||
$object->subject = $subject;
|
||||
|
||||
$object->product_code ='QUICK_MSECURITY_PAY';
|
||||
|
||||
//$object->time_expire = date('Y-m-d H:i:s',time());
|
||||
|
||||
$json = json_encode($object);
|
||||
|
||||
$request = new \AlipayTradeAppPayRequest();
|
||||
|
||||
$request->setNotifyUrl("https://".$_SERVER['HTTP_HOST'].'/index.php/shop/IndexWxPay/aliNotify');
|
||||
|
||||
$request->setBizContent($json);
|
||||
|
||||
$result = $aop->sdkExecute ( $request);
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-11 17:23
|
||||
* @功能说明:退款
|
||||
*/
|
||||
public function aliRefund($order_code,$price){
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/AopClient.php';
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/request/AlipayTradeRefundRequest.php';
|
||||
|
||||
$pay_config = $this->payConfig();
|
||||
|
||||
$aop = new \AopClient ();
|
||||
|
||||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||||
|
||||
$aop->appId = $pay_config[ 'payment' ][ 'ali_appid' ];
|
||||
|
||||
$aop->rsaPrivateKey = $pay_config['payment']['ali_privatekey'];;
|
||||
|
||||
$aop->alipayrsaPublicKey= $pay_config['payment']['ali_publickey'];;
|
||||
|
||||
$aop->apiVersion = '1.0';
|
||||
|
||||
$aop->signType = 'RSA2';
|
||||
|
||||
$aop->postCharset='UTF-8';
|
||||
|
||||
$aop->format='json';
|
||||
|
||||
$object = new \stdClass();
|
||||
|
||||
$object->trade_no = $order_code;
|
||||
|
||||
$object->refund_amount = $price;
|
||||
|
||||
$object->out_request_no = 'HZ01RF001';
|
||||
|
||||
$json = json_encode($object);
|
||||
|
||||
$request = new \AlipayTradeRefundRequest();
|
||||
|
||||
$request->setBizContent($json);
|
||||
|
||||
$result = $aop->execute ( $request);
|
||||
|
||||
$result = !empty($result)?object_array($result):[];
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
72
longbingcore/wxcore/PayNotify.php
Normal file
72
longbingcore/wxcore/PayNotify.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\ApiRest;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class PayNotify {
|
||||
|
||||
// static protected $uniacid;
|
||||
|
||||
// public function __construct(App $app)
|
||||
// {
|
||||
// $this->app = $app;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-19 13:29
|
||||
* @功能说明:支付宝回调信息
|
||||
*/
|
||||
public function aliNotify($arr){
|
||||
|
||||
switch ($arr['subject']){
|
||||
|
||||
case '余额充值':
|
||||
//余额卡
|
||||
$order_model = new \app\farm\model\BalanceOrder();
|
||||
|
||||
break;
|
||||
|
||||
case '认养商品':
|
||||
//认养
|
||||
$order_model = new \app\farm\model\ClaimOrder();
|
||||
|
||||
break;
|
||||
case '土地商品':
|
||||
//土地
|
||||
$order_model = new \app\farm\model\LandOrder();
|
||||
|
||||
break;
|
||||
|
||||
case '配送订单':
|
||||
//配送订单
|
||||
$order_model = new \app\farm\model\SendOrder();
|
||||
|
||||
break;
|
||||
|
||||
case '养殖商品':
|
||||
//养殖订单
|
||||
$order_model = new \app\farm\model\BreedOrder();
|
||||
|
||||
break;
|
||||
case '商场商品':
|
||||
//商城订单
|
||||
$order_model = new \app\farm\model\ShopOrder();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$order_model->orderResult($arr['out_trade_no'],$arr['trade_no']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
156
longbingcore/wxcore/PospalApi.php
Normal file
156
longbingcore/wxcore/PospalApi.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 达达开放平台sdk
|
||||
* User: 仝帅
|
||||
* Date: 2016-12-19
|
||||
* Time: 16:48
|
||||
*/
|
||||
class PospalApi
|
||||
{
|
||||
|
||||
protected $appId;
|
||||
|
||||
protected $appKey;
|
||||
|
||||
protected $signature;
|
||||
|
||||
protected $url;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->appId = '205871490509191130';
|
||||
$this->appId = '9C7F3BFC37E729D9A5D6798B2D358E28';
|
||||
|
||||
$this->url = 'https://area56-win.pospal.cn:443/';
|
||||
|
||||
$this->account_key = '0e73963b251112af12835cd7d6dbadca';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:42
|
||||
* @功能说明:获取令牌
|
||||
*/
|
||||
|
||||
public function getToken(){
|
||||
|
||||
$url = 'https://api.ubibot.cn/accounts/generate_access_token?account_key='.$this->account_key;
|
||||
|
||||
$key = 'ubibot_token';
|
||||
|
||||
$data = getCache($key);
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
$data = $this->request($url,[],'GET');
|
||||
|
||||
if(!empty($data['result'])&&$data['result']=='success'){
|
||||
|
||||
setCache($key,$data,60);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:54
|
||||
* @功能说明:获取空间列表
|
||||
*/
|
||||
public function getRoomList(){
|
||||
|
||||
$url = 'https://api.ubibot.cn/channels?account_key='.$this->account_key;
|
||||
|
||||
$data = $this->request($url,[],'GET');
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:57
|
||||
* @功能说明:获取空间详情
|
||||
*/
|
||||
public function getRoomInfo($room_id){
|
||||
|
||||
$url = 'https://api.ubibot.cn/channels/'.$room_id.'?account_key='.$this->account_key;
|
||||
|
||||
$data = $this->request($url,[],'GET');
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $post_data
|
||||
* @param string $post_type
|
||||
* @功能说明:发送请求
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-26 14:38
|
||||
*/
|
||||
public function request($url,$post_data,$post_type='POST'){
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
$post_data = json_encode($post_data);
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => $post_type,
|
||||
CURLOPT_POSTFIELDS => $post_data,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Content-Type:application/json",
|
||||
"User-Agent:openApi",
|
||||
"Content-Type:application/json; charset=utf-8",
|
||||
"accept-encoding:gzip,deflate",
|
||||
"time-stamp:".time(),
|
||||
// "data-signature:D2C3D3C7289EAE111277999D21196D4D",
|
||||
"data-signature:".strtoupper(md5($this->appKey.$post_data))
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
return json_decode($response,true);
|
||||
|
||||
// if ($err) {
|
||||
// echo "cURL Error #:" . $err;
|
||||
// } else {
|
||||
// echo $response;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
241
longbingcore/wxcore/PushMsgModel.php
Normal file
241
longbingcore/wxcore/PushMsgModel.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\ApiRest;
|
||||
use app\farm\controller\IndexInfo;
|
||||
use app\farm\model\Config;
|
||||
use app\farm\model\SystemInfo;
|
||||
use app\farm\model\User;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class PushMsgModel {
|
||||
|
||||
|
||||
private $app_key;
|
||||
//待发送的应用程序(appKey),只能填一个。
|
||||
private $master_secret;
|
||||
//主密码
|
||||
private $url; //推送的地址
|
||||
//若实例化的时候传入相应的值则按新的相应值进行
|
||||
public function __construct($uniacid) {
|
||||
|
||||
$config_model = new Config();
|
||||
|
||||
$config = $config_model->dataInfo(['uniacid'=>$uniacid]);
|
||||
|
||||
$this->app_key = $config['push_key'];
|
||||
|
||||
$this->master_secret = $config['push_secret'];
|
||||
|
||||
$this->url = 'https://api.jpush.cn/v3/push';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* $receiver 接收者的信息
|
||||
all 字符串 该产品下面的所有用户. 对app_key下的所有用户推送消息
|
||||
tag(20个)Array标签组(并集): tag=>array('昆明','北京','曲靖','上海');
|
||||
tag_and(20个)Array标签组(交集): tag_and=>array('广州','女');
|
||||
alias(1000)Array别名(并集): alias=>array('93d78b73611d886a74*****88497f501','606d05090896228f66ae10d1*****310');
|
||||
registration_id(1000)注册ID设备标识(并集): registration_id=>array('20effc071de0b45c1a**********2824746e1ff2001bd80308a467d800bed39e');
|
||||
*/
|
||||
//$content 推送的内容。
|
||||
//$m_type 推送附加字段的类型(可不填) http,tips,chat....
|
||||
//$m_txt 推送附加字段的类型对应的内容(可不填) 可能是url,可能是一段文字。
|
||||
//$m_time 保存离线时间的秒数默认为一天(可不传)单位为秒
|
||||
/**
|
||||
* @param string $receiver 目标用户
|
||||
* @param string $content
|
||||
* @param string $m_type
|
||||
* @param string $m_txt
|
||||
* @param string $m_time
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-22 16:45
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function push($receiver='all',$content='',$m_type='',$m_txt='',$m_time='86400')
|
||||
{
|
||||
|
||||
if(empty($this->app_key)||empty($this->master_secret)){
|
||||
|
||||
return false;
|
||||
}
|
||||
// dump($this->app_key);exit;
|
||||
$base64 = base64_encode("$this->app_key:$this->master_secret");
|
||||
$header = array("Authorization:Basic $base64", "Content-Type:application/json");
|
||||
$data = array();
|
||||
$data['platform'] = 'all'; //目标用户终端手机的平台类型android,ios,winphone
|
||||
$data['audience'] = $receiver; //目标用户
|
||||
|
||||
$data['notification'] = array(
|
||||
//统一的模式--标准模式
|
||||
"alert" => $content,
|
||||
//安卓自定义
|
||||
"android" => array(
|
||||
"alert" => $content,
|
||||
"title" => "",
|
||||
"builder_id" => 1,
|
||||
"extras" => array("type" => $m_type, "txt" => $m_txt)
|
||||
),
|
||||
//ios的自定义
|
||||
"ios" => array(
|
||||
"alert" => $content,
|
||||
"badge" => "1",
|
||||
"sound" => "default",
|
||||
"extras" => array("type" => $m_type, "txt" => $m_txt)
|
||||
)
|
||||
);
|
||||
//苹果自定义---为了弹出值方便调测
|
||||
$data['message'] = array(
|
||||
"msg_content"=>$content,
|
||||
"extras"=>array("type"=>$m_type, "txt"=>$m_txt)
|
||||
);
|
||||
|
||||
//附加选项
|
||||
$data['options'] = array(
|
||||
"sendno"=>time(),
|
||||
// "time_to_live"=>$m_time, //保存离线时间的秒数默认为一天
|
||||
"apns_production"=>false, //布尔类型 指定 APNS 通知发送环境:0开发环境,1生产环境。或者传递false和true
|
||||
);
|
||||
$param = json_encode($data);
|
||||
$res = $this->push_curl($param,$header);
|
||||
|
||||
if($res){ //得到返回值--成功已否后面判断
|
||||
return $res;
|
||||
}else{ //未得到返回值--返回失败
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function push_curl($param="",$header="") {
|
||||
if (empty($param)) { return false; }
|
||||
$postUrl = $this->url;
|
||||
$curlPost = $param;
|
||||
$ch = curl_init(); //初始化curl
|
||||
curl_setopt($ch, CURLOPT_URL,$postUrl); //抓取指定网页
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
|
||||
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER,$header); // 增加 HTTP Header(头)里的字段
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 终止从服务端进行验证
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
$data = curl_exec($ch); //运行curl
|
||||
curl_close($ch);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $type
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-23 13:54
|
||||
*/
|
||||
public function sendMsg($data,$type){
|
||||
|
||||
$info_model = new SystemInfo();
|
||||
|
||||
$user_model = new User();
|
||||
//添加信息
|
||||
$info_model->infoAdd($data,$type);
|
||||
|
||||
$data = $info_model->returnMsg($type,$data);
|
||||
|
||||
$push_id = $user_model->where(['id'=>$data['user_id']])->value('push_id');
|
||||
|
||||
if(!empty($push_id)){
|
||||
|
||||
$push_id = ['registration_id'=>[$push_id]];
|
||||
//发送消息
|
||||
$this->send_pub($data['msg'],$push_id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-22 16:46
|
||||
* @功能说明:
|
||||
*/
|
||||
public function send_pub($content,$receive='all'){
|
||||
//推送附加字段的类型
|
||||
$m_type = 'http';
|
||||
//推送附加字段的类型对应的内容(可不填) 可能是url,可能是一段文字。
|
||||
$m_txt = 'http://www.groex.cn/';
|
||||
//离线保留时间
|
||||
$m_time = '86400';
|
||||
|
||||
$result = $this->push($receive,$content,$m_type,$m_txt,$m_time);
|
||||
|
||||
$res_arr=!empty($result)?json_decode($result, true):[];
|
||||
|
||||
return $res_arr;
|
||||
|
||||
if($result){
|
||||
|
||||
$res_arr = json_decode($result, true);
|
||||
|
||||
|
||||
if(isset($res_arr['error'])){
|
||||
//错误信息
|
||||
$error_code=$res_arr['error']['code'];
|
||||
//错误码
|
||||
switch ($error_code) {
|
||||
case 200:
|
||||
$message= '发送成功!';
|
||||
break;
|
||||
case 1000:
|
||||
$message= '失败(系统内部错误)';
|
||||
break;
|
||||
case 1001:
|
||||
$message = '失败(只支持 HTTP Post 方法,不支持 Get 方法)';
|
||||
break;
|
||||
case 1002:
|
||||
$message= '失败(缺少了必须的参数)';
|
||||
break;
|
||||
case 1003:
|
||||
$message= '失败(参数值不合法)';
|
||||
break;
|
||||
case 1004:
|
||||
$message= '失败(验证失败)';
|
||||
break;
|
||||
case 1005:
|
||||
$message= '失败(消息体太大)';
|
||||
break;
|
||||
case 1008:
|
||||
$message= '失败(appkey参数非法)';
|
||||
break;
|
||||
case 1020:
|
||||
$message= '失败(只支持 HTTPS 请求)';
|
||||
break;
|
||||
case 1030:
|
||||
$message= '失败(内部服务超时)';
|
||||
break;
|
||||
default:
|
||||
$message= '失败(返回其他状态,目前不清楚额,请联系开发人员!)';
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
$message="发送成功!";
|
||||
}
|
||||
}else{ //接口调用失败或无响应
|
||||
$message='接口调用失败或无响应';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
138
longbingcore/wxcore/WxMsg.php
Normal file
138
longbingcore/wxcore/WxMsg.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\extend\wxWork\work;
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class WxMsg{
|
||||
|
||||
static protected $uniacid;
|
||||
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
self::$uniacid = $uniacid;
|
||||
|
||||
$this->config = $this->getConfig($uniacid);
|
||||
|
||||
$this->appid = $this->getAppid();
|
||||
|
||||
// $this->appsecret = $this->getAppsecret();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-27 17:35
|
||||
* @功能说明:企业微信消息
|
||||
*/
|
||||
public function WxMsg($to_user,$title='',$page='',$description='',$content_item=''){
|
||||
|
||||
$data = [
|
||||
//接受者
|
||||
'touser' => $to_user,
|
||||
//类型
|
||||
'msgtype'=> 'miniprogram_notice',
|
||||
|
||||
'miniprogram_notice' => [
|
||||
|
||||
'appid' => $this->appid ,
|
||||
//放大第一个字段
|
||||
// 'emphasis_first_item' => true,
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
if(!empty($page)){
|
||||
//路径
|
||||
$data['miniprogram_notice']['page'] = $page;
|
||||
}
|
||||
if(!empty($title)){
|
||||
//标题
|
||||
$data['miniprogram_notice']['title'] = $title;
|
||||
}
|
||||
if(!empty($content_item)){
|
||||
//内容
|
||||
$data['miniprogram_notice']['content_item'] = $content_item;
|
||||
}
|
||||
if(!empty($description)){
|
||||
//描述
|
||||
$data['miniprogram_notice']['description'] = $description;
|
||||
}
|
||||
//初始化配置模型
|
||||
$service_model = new WxSetting(self::$uniacid);
|
||||
//发送消息
|
||||
$result = $service_model->sendCompanyMsg($data);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 功能说明 获取appid
|
||||
*
|
||||
* @return mixed|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:36
|
||||
*/
|
||||
protected function getAppid()
|
||||
{
|
||||
if(isset($this->config['appid'])) return $this->config['appid'];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取appsecret
|
||||
*
|
||||
* @return mixed|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:36
|
||||
*/
|
||||
protected function getAppsecret()
|
||||
{
|
||||
if(isset($this->config['app_secret'])) return $this->config['app_secret'];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取配置信息
|
||||
*
|
||||
* @param $uniacid
|
||||
* @return array|bool|mixed|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:35
|
||||
*/
|
||||
public function getConfig($uniacid)
|
||||
{
|
||||
//config key
|
||||
$key = 'longbing_card_app_config_' . $uniacid;
|
||||
//获取config
|
||||
$config = getCache($key, $uniacid);
|
||||
//判断缓存是否存在
|
||||
if(!empty($config)) return $config;
|
||||
//获取数据
|
||||
$config = Db::name('longbing_card_config')->where(['uniacid'=>$uniacid])->find();
|
||||
|
||||
if(empty($config)){
|
||||
Db::name('longbing_card_config')->insert(['uniacid'=>$uniacid]);
|
||||
$config = Db::name('longbing_card_config')->where(['uniacid'=>$uniacid])->find();
|
||||
}
|
||||
//判断数据是否存在
|
||||
if(!empty($config)) setCache($key ,$config ,3600,$uniacid);
|
||||
//返回数据
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
113
longbingcore/wxcore/WxPay.php
Normal file
113
longbingcore/wxcore/WxPay.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class WxPay{
|
||||
|
||||
static protected $uniacid;
|
||||
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
self::$uniacid = $uniacid;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取支付信息
|
||||
*/
|
||||
public function payConfig (){
|
||||
$uniacid_id = self::$uniacid;
|
||||
|
||||
$pay = Db::name('longbing_card_config_pay')->where(['uniacid'=>$uniacid_id])->find();
|
||||
$config = Db::name( 'longbing_card_config')->where(['uniacid' => $uniacid_id])->find();
|
||||
if(empty($pay[ 'mch_id' ])||empty($pay[ 'pay_key' ])){
|
||||
|
||||
return [
|
||||
|
||||
'result_code' => false,
|
||||
|
||||
'return_code' => false,
|
||||
|
||||
'err_code_des'=> '未配置支付信息'
|
||||
];
|
||||
}
|
||||
$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['app_secret'];
|
||||
return $setting;
|
||||
}
|
||||
/**
|
||||
* @param string $uid
|
||||
* @param string $money
|
||||
* @功能说明:提现
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-03-24 14:52
|
||||
*/
|
||||
public function crteateMchPay($paymentApp,$openid,$money='')
|
||||
{
|
||||
|
||||
$money = $money*100;
|
||||
|
||||
$payid = substr(md5('longbing1'.time()),0,11);
|
||||
//没有配置支付信息
|
||||
if(empty($paymentApp['app_id'])||empty($paymentApp['payment']['merchant_id'])){
|
||||
|
||||
return $paymentApp;
|
||||
|
||||
}
|
||||
//没有openid
|
||||
if(empty($openid)){
|
||||
|
||||
return [
|
||||
|
||||
'result_code' => false,
|
||||
|
||||
'return_code' => false,
|
||||
|
||||
'err_code_des'=> '用户信息错误'
|
||||
];
|
||||
}
|
||||
|
||||
$setting['mini_appid'] = $paymentApp['app_id'];
|
||||
$setting['mini_appsecrept'] = $paymentApp['secret'];
|
||||
$setting['mini_mid'] = $paymentApp['payment']['merchant_id'];
|
||||
$setting['mini_apicode'] = $paymentApp['payment']['key'];
|
||||
$setting['apiclient_cert'] = $paymentApp['payment']['cert_path'];
|
||||
$setting['apiclient_cert_key'] = $paymentApp['payment']['key_path'];
|
||||
|
||||
|
||||
define('WX_APPID', $setting['mini_appid']);
|
||||
define('WX_MCHID', $setting['mini_mid']);
|
||||
define('WX_KEY', $setting['mini_apicode']);
|
||||
define('WX_APPSECRET', $setting['mini_appsecrept']);
|
||||
define('WX_SSLCERT_PATH', $setting['apiclient_cert']);
|
||||
define('WX_SSLKEY_PATH', $setting['apiclient_cert_key']);
|
||||
define('WX_CURL_PROXY_HOST', '0.0.0.0');
|
||||
define('WX_CURL_PROXY_PORT', 0);
|
||||
define('WX_REPORT_LEVENL', 0);
|
||||
|
||||
require_once PAY_PATH . "weixinpay/lib/WxPay.Api.php";
|
||||
require_once PAY_PATH . "weixinpay/example/WxPay.JsApiPay.php";
|
||||
require_once PAY_PATH . "weixinpay/lib/WxMchPay.php";
|
||||
$payClass=new \WxMchPay();
|
||||
|
||||
$res=$payClass->MchPayOrder($openid,$money,$payid);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
449
longbingcore/wxcore/WxSetting.php
Normal file
449
longbingcore/wxcore/WxSetting.php
Normal file
@@ -0,0 +1,449 @@
|
||||
<?php
|
||||
/*
|
||||
* 服务通知
|
||||
*
|
||||
*************************************/
|
||||
namespace longbingcore\wxcore;
|
||||
use app\admin\model\AppConfig;
|
||||
use app\sendmsg\model\SendConfig;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
class WxSetting
|
||||
{
|
||||
//accesstoken
|
||||
protected $access_token = null;
|
||||
//appid
|
||||
protected $appid = null;
|
||||
//appsecret
|
||||
protected $appsecret = null;
|
||||
//uniacid
|
||||
protected $uniacid = '7777';
|
||||
//配置信息
|
||||
protected $config = [];
|
||||
//初始化
|
||||
function __construct($uniacid = '1'){
|
||||
$this->uniacid = $uniacid;
|
||||
|
||||
$this->config = $this->getConfig($this->uniacid);
|
||||
|
||||
$this->appid = $this->getAppid();
|
||||
|
||||
$this->appsecret = $this->getAppsecret();
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取appid
|
||||
*
|
||||
* @return mixed|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:36
|
||||
*/
|
||||
protected function getAppid()
|
||||
{
|
||||
if(isset($this->config['appid'])) return $this->config['appid'];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取appsecret
|
||||
*
|
||||
* @return mixed|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:36
|
||||
*/
|
||||
protected function getAppsecret()
|
||||
{
|
||||
if(isset($this->config['appsecret'])) return $this->config['appsecret'];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取配置信息
|
||||
*
|
||||
* @param $uniacid
|
||||
* @return array|bool|mixed|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:35
|
||||
*/
|
||||
public function getConfig($uniacid)
|
||||
{
|
||||
|
||||
$config = longbingGetAppConfig($uniacid);
|
||||
//返回数据
|
||||
return $config;
|
||||
}
|
||||
|
||||
//检查信息是否存在
|
||||
public function checkConfig()
|
||||
{
|
||||
$result = true;
|
||||
if(empty($this->uniacid) || empty($this->appid) || empty($this->appsecret)) $result = false;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取token
|
||||
*
|
||||
* @return bool|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:35
|
||||
*/
|
||||
public function lbSingleGetAccessToken ()
|
||||
{
|
||||
$key = "longbing_card_access_token";
|
||||
|
||||
$value = getCache( $key,$this->uniacid );
|
||||
|
||||
|
||||
if ( $value !=false )
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
$uniacid = $this->uniacid;
|
||||
//基础检查
|
||||
if(!$this->checkConfig()){
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
//appid
|
||||
$appid = $this->appid;
|
||||
//appsecret
|
||||
$appsecret = $this->appsecret;
|
||||
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret={$appsecret}";
|
||||
|
||||
|
||||
$accessToken = file_get_contents( $url );
|
||||
|
||||
// dump($accessToken);exit;
|
||||
|
||||
if ( strstr( $accessToken, 'errcode' ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$accessToken = json_decode( $accessToken, true );
|
||||
$accessToken = $accessToken[ 'access_token' ];
|
||||
|
||||
setCache( $key, $accessToken, 7000, $uniacid );
|
||||
|
||||
return $accessToken;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* User: chenniang
|
||||
* Date: 2019-12-25 11:52
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* descrption:添加模版 返回模版消息id
|
||||
*/
|
||||
public function addTmpl($data){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
// dump($access_token);exit;
|
||||
//添加模版的小程序地址
|
||||
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token={$access_token}";
|
||||
//请求
|
||||
$data = json_encode( $data, JSON_UNESCAPED_UNICODE );
|
||||
//返回模版消息id 是个array
|
||||
$res = $this->curlPost( $url,$data );
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 11:39
|
||||
* @功能说明:获取所有模版消息列表
|
||||
*/
|
||||
public function getAllTpmlList(){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//获取小程序所有 模版消息的url
|
||||
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token={$access_token}";
|
||||
//请求
|
||||
$res = $this->curlPost($url,NULL,'GET');
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $tpml_id
|
||||
* @功能说明: 删除模版消息
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 14:08
|
||||
*/
|
||||
public function deleteTmpl($tpml_id){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//获取小程序所有 模版消息的url
|
||||
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token={$access_token}";
|
||||
//请求参数
|
||||
$data['priTmplId'] = $tpml_id;
|
||||
//请求
|
||||
$data = json_encode( $data, JSON_UNESCAPED_UNICODE );
|
||||
$res = $this->curlPost($url,$data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 18:54
|
||||
* @功能说明:发送模版消息
|
||||
*/
|
||||
public function sendTmpl($data){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//获取小程序所有 模版消息的url
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$access_token}";
|
||||
//请求
|
||||
$data = json_encode( $data, JSON_UNESCAPED_UNICODE );
|
||||
// dump($data);exit;
|
||||
$res = $this->curlPost($url,$data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 18:54
|
||||
* @功能说明:获取当前账号下的所有模版消息
|
||||
*/
|
||||
public function getUserTmpl(){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//获取小程序所有 模版消息的url
|
||||
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token={$access_token}";
|
||||
//请求
|
||||
$res = $this->curlPost($url,[],'GET');
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @功能说明:企业微信消息
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-27 18:33
|
||||
*/
|
||||
public function sendCompanyMsg(array $data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
$accessTokenWW = $this->companyMsgToken();
|
||||
|
||||
$url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$accessTokenWW}";
|
||||
|
||||
$res = $this->curlPost($url, $data);
|
||||
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-28 13:40
|
||||
* @功能说明:获取企业消息token
|
||||
*/
|
||||
public function companyMsgToken(){
|
||||
|
||||
$key = "longbing_card_access_token_qy_cn";
|
||||
|
||||
$value = getCache($key,$this->uniacid);
|
||||
|
||||
if ( $value !== false )
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
$send_model = new SendConfig();
|
||||
//配置信息
|
||||
$config = $send_model->configInfo(['uniacid'=>$this->uniacid]);
|
||||
|
||||
if (!empty($config['yq_corpid'])&& !empty($config['yq_corpsecret'] ))
|
||||
{
|
||||
$key = $config['yq_corpid'];
|
||||
|
||||
$secret = $config['yq_corpsecret'];
|
||||
|
||||
$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$key&corpsecret=$secret";
|
||||
|
||||
$accessToken = file_get_contents( $url );
|
||||
|
||||
$accessToken = json_decode( $accessToken, true );
|
||||
|
||||
if($accessToken['errcode'] != 0){
|
||||
|
||||
echo json_encode( [ 'code' => 402, 'error' => '获取token失败' ] );
|
||||
|
||||
exit;
|
||||
}
|
||||
$accessToken = $accessToken[ 'access_token' ];
|
||||
|
||||
setCache( $key, $accessToken, 7200, $this->uniacid );
|
||||
}
|
||||
|
||||
return !empty($accessToken)?$accessToken:'';
|
||||
}
|
||||
/**
|
||||
* 功能说明 post 请求
|
||||
*
|
||||
* @param $url
|
||||
* @param $post
|
||||
* @param $method
|
||||
* @param int $header
|
||||
* @return bool|string
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 18:40
|
||||
*/
|
||||
public function curlPost($url,$post=NULL,$post_type='POST'){
|
||||
$result = $this->crulGetData($url,$post,$post_type);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 功能说明 post 请求
|
||||
*
|
||||
* @param $url
|
||||
* @param $post
|
||||
* @param $method
|
||||
* @param int $header
|
||||
* @return bool|string
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 18:40
|
||||
*/
|
||||
public function crulGetData($url, $post, $method, $header=1){
|
||||
$this->_errno = NULL;
|
||||
$this->_error = NULL;
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
if($post != NULL)
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
|
||||
curl_setopt($ch, CURLOPT_AUTOREFERER,true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
||||
|
||||
if($header)
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
"Content-Type: application/json; charset=utf-8",
|
||||
)
|
||||
);
|
||||
$result = curl_exec($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $content
|
||||
* @param $access_token
|
||||
* @功能说明: 违禁词检测
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-01-02 17:07
|
||||
*/
|
||||
public function wxContentRlue($content)
|
||||
{
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
|
||||
if(empty($access_token)){
|
||||
|
||||
return ['errcode'=>0];
|
||||
}
|
||||
|
||||
$url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token={$access_token}";
|
||||
$tmp = [
|
||||
'url' => $url,
|
||||
'data' => [
|
||||
'content' => urlencode($content)
|
||||
],
|
||||
];
|
||||
$rest = $this->curlPost($tmp['url'], urldecode(json_encode($tmp['data'])));
|
||||
$rest = json_decode($rest, true);
|
||||
return $rest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $img_path
|
||||
* @功能说明:图片检测
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-03-27 11:44
|
||||
*/
|
||||
function imgSecCheck($img_path){
|
||||
|
||||
//token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//地址
|
||||
$url ='https://api.weixin.qq.com/wxa/img_sec_check?access_token='.$access_token;
|
||||
//请求包
|
||||
$post_data = [
|
||||
'media'=>new \CURLFile($img_path)
|
||||
];
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL,$url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-14 18:56
|
||||
* @功能说明:php二维码 返回base64
|
||||
*/
|
||||
public function phpQrCode($data){
|
||||
|
||||
require_once EXTEND_PATH.'phpqrcode/phpqrcode.php';
|
||||
|
||||
$errorCorrectionLevel = 'L'; //容错级别
|
||||
|
||||
$matrixPointSize = 10;
|
||||
//生成图片大小
|
||||
ob_start();
|
||||
|
||||
\QRcode::png($data,false,$errorCorrectionLevel,$matrixPointSize,2,false,0xFFFFFF,0x000000);
|
||||
|
||||
$imgstr = base64_encode(ob_get_contents());
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
$imgstr = 'data:image/png;base64,'.$imgstr;
|
||||
|
||||
return $imgstr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
235
longbingcore/wxcore/WxTmpl.php
Normal file
235
longbingcore/wxcore/WxTmpl.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class WxTmpl{
|
||||
|
||||
static protected $uniacid;
|
||||
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
self::$uniacid = $uniacid;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* $data = ['tmpl_name' => '模版名', 'model_name'=> '模块名', 'tid' => 模版消息的标题id, 'kidList' => [4,2,1,3] 模版消息的列表, 'sceneDesc' => '订单支付成功',];
|
||||
* @param $send_data
|
||||
* @功能说明: 添加模版消息
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 14:18
|
||||
*/
|
||||
|
||||
static public function addtmpl ($dis)
|
||||
{
|
||||
//查询数据库里的模版消息
|
||||
$tmpl = Db::name('longbing_card_tmpl_config')->where($dis)->find();
|
||||
//判断数据库里面有没有tmpl_id 没有就生成
|
||||
if(empty($tmpl['tmpl_id'])){
|
||||
//初始化配置模型
|
||||
$service_model = new WxSetting(self::$uniacid);
|
||||
//生成模版消息的参数
|
||||
$send_data = [
|
||||
'tid' => $tmpl['tid'],
|
||||
'kidList' => explode(',',$tmpl['kid']),
|
||||
'sceneDesc' => $tmpl['sceneDesc']
|
||||
];
|
||||
//给客户的小程序添加模版 并返回模版id
|
||||
$tmpl_info = $service_model->addTmpl($send_data);
|
||||
$tmpl_info = json_decode($tmpl_info,true);
|
||||
}else{
|
||||
//有数据就直接返回模版id
|
||||
$tmpl_info['priTmplId'] = $tmpl['tmpl_id'];
|
||||
$tmpl_info['errcode'] = 0;
|
||||
|
||||
}
|
||||
return $tmpl_info;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-01-02 11:34
|
||||
* @功能说明:获取模版消息 需要发送的key
|
||||
*/
|
||||
static public function getTmplKey($tmpl_id){
|
||||
|
||||
if(empty($tmpl_id)){
|
||||
return [];
|
||||
}
|
||||
$cach_data = getCache($tmpl_id,self::$uniacid);
|
||||
//如果有缓存直接返回
|
||||
if(!empty($cach_data)){
|
||||
return $cach_data;
|
||||
}
|
||||
//微信库类
|
||||
$service_model = new WxSetting(self::$uniacid);
|
||||
//获取所有模版消息
|
||||
$data = $service_model->getUserTmpl();
|
||||
//没有返回空
|
||||
if(empty($data)){
|
||||
return [];
|
||||
}
|
||||
$data = json_decode($data,true);
|
||||
//如果报错 直接返回
|
||||
if(empty($data['data'])){
|
||||
return [];
|
||||
}
|
||||
$data = $data['data'];
|
||||
//找到该模版id 的模版
|
||||
$found_key = array_search($tmpl_id, array_column($data, 'priTmplId'));
|
||||
|
||||
if(!is_numeric($found_key)){
|
||||
return [];
|
||||
}
|
||||
//获取该模版
|
||||
$tmpl = $data[$found_key];
|
||||
//获取该模版的内容
|
||||
$content = explode('{{',$tmpl['content']);
|
||||
//转换格式
|
||||
foreach ($content as $k =>$value){
|
||||
if($k == 0){
|
||||
unset($content[$k]);
|
||||
continue;
|
||||
}
|
||||
$content[$k] = substr($value,0,strpos($value, '.'));
|
||||
}
|
||||
//存入缓存
|
||||
setCache($tmpl_id,$content,86400,self::$uniacid);
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 15:04
|
||||
* @功能说明:模版参数
|
||||
*/
|
||||
|
||||
static public function tmplParam($key){
|
||||
//订单支付通知
|
||||
$data['pay_order'] = [
|
||||
//标题id
|
||||
'tid' => 1754,
|
||||
//内容的key(暂时不需要)
|
||||
'kidList' => 'thing4,amount2,character_string1,date3',
|
||||
//模版场景类容
|
||||
'sceneDesc' => '订单支付成功',
|
||||
//自动生成模版时内容的顺序
|
||||
'kid' => '4,2,1,3',
|
||||
//模版内容的样板
|
||||
'example' => '物品名称、金额、单号、支付时间',
|
||||
];
|
||||
//订单发货通知
|
||||
$data['send_order'] = [
|
||||
//标题id
|
||||
'tid' => 2414,
|
||||
//内容的key(暂时不需要)
|
||||
'kidList' => '',
|
||||
//模版场景类容
|
||||
'sceneDesc' => '订单发货通知',
|
||||
//自动生成模版时内容的顺序
|
||||
'kid' => '1,2,3,4',
|
||||
//模版内容的样板
|
||||
'example' => '发货时间、订单编号、物流编号、物流公司',
|
||||
];
|
||||
|
||||
//IM 未读私信通知
|
||||
$data['land_order'] = [
|
||||
//标题id
|
||||
'tid' => 585,
|
||||
//内容的key(暂时不需要)
|
||||
'kidList' => '',
|
||||
//模版场景类容
|
||||
'sceneDesc' => '土地订单通知',
|
||||
//自动生成模版时内容的顺序
|
||||
'kid' => '1,2,3,4,5',
|
||||
//模版内容的样板
|
||||
'example' => '订单编号、商品名称、商品详情、订单金额、下单时间',
|
||||
];
|
||||
|
||||
$data['land_over'] = [
|
||||
//标题id
|
||||
'tid' => 30781,
|
||||
//内容的key(暂时不需要)
|
||||
'kidList' => '',
|
||||
//模版场景类容
|
||||
'sceneDesc' => '土地到期提醒',
|
||||
//自动生成模版时内容的顺序
|
||||
'kid' => '1,2,3,4',
|
||||
//模版内容的样板
|
||||
'example' => '土地名称、到期时间、单号、温馨提示',
|
||||
];
|
||||
|
||||
if(key_exists($key,$data)){
|
||||
|
||||
return $data[$key];
|
||||
|
||||
}else{
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $poenid
|
||||
* @param $key_data
|
||||
* @param $send_data
|
||||
* @param $page
|
||||
* @功能说明: 发送模版消息
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 11:22
|
||||
*/
|
||||
static public function sendTmpl($poenid,$tmpl_id,$send_data,$page){
|
||||
//发送信息内容
|
||||
$data = [
|
||||
//用户openid
|
||||
'touser' => $poenid,
|
||||
//模版id
|
||||
'template_id' => $tmpl_id,
|
||||
//跳转页面
|
||||
'page' => $page,
|
||||
//发送内容
|
||||
'data' => $send_data
|
||||
];
|
||||
//初始化配置模型
|
||||
$service_model = new WxSetting(self::$uniacid);
|
||||
//发送消息
|
||||
$res = $service_model->sendTmpl($data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @功能说明:转utf 8
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-01-03 19:23
|
||||
*/
|
||||
|
||||
static public function strToUtf8($str){
|
||||
|
||||
$encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
|
||||
|
||||
if($encode == 'UTF-8'){
|
||||
return $str;
|
||||
}else{
|
||||
return mb_convert_encoding($str, 'UTF-8', $encode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
284
longbingcore/wxcore/YsCloudApi.php
Normal file
284
longbingcore/wxcore/YsCloudApi.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use app\farm\model\Config;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 达达开放平台sdk
|
||||
* User: 仝帅
|
||||
* Date: 2016-12-19
|
||||
* Time: 16:48
|
||||
*/
|
||||
class YsCloudApi
|
||||
{
|
||||
|
||||
protected $appId;
|
||||
|
||||
protected $appKey;
|
||||
|
||||
protected $signature;
|
||||
|
||||
protected $url;
|
||||
|
||||
protected $uniacid;
|
||||
|
||||
|
||||
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
$this->uniacid= $uniacid;
|
||||
|
||||
$config_model = new Config();
|
||||
|
||||
$config = $config_model->dataInfo(['uniacid'=>$uniacid]);
|
||||
|
||||
$this->AppKey = $config['ys_appkey'];
|
||||
|
||||
$this->Secret = $config['ys_secret'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:42
|
||||
* @功能说明:获取令牌
|
||||
*/
|
||||
|
||||
public function getToken(){
|
||||
|
||||
$url = 'https://open.ys7.com/api/lapp/token/get';
|
||||
|
||||
$key = 'yscloud_token';
|
||||
|
||||
$token = getCache($key,$this->uniacid);
|
||||
|
||||
$post_data = [
|
||||
|
||||
'appKey' => $this->AppKey,
|
||||
|
||||
'appSecret' => $this->Secret
|
||||
];
|
||||
|
||||
if(empty($token)){
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
if(!empty($data['code'])&&$data['code']==200){
|
||||
|
||||
$token = $data['data']['accessToken'];
|
||||
|
||||
setCache($key,$token,86400*6,$this->uniacid);
|
||||
|
||||
}else{
|
||||
|
||||
$token = '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:54
|
||||
* @功能说明:获取空间列表
|
||||
*/
|
||||
public function getVideoList(){
|
||||
|
||||
$url = 'https://open.ys7.com/api/lapp/live/video/list';
|
||||
|
||||
$post_data = [
|
||||
|
||||
'accessToken' => $this->getToken(),
|
||||
|
||||
'pageSize' => 100
|
||||
];
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:57
|
||||
* @功能说明:获取空间详情
|
||||
*/
|
||||
public function getVideoInfo($deviceSerial,$channelNo=1){
|
||||
|
||||
$url = 'https://open.ys7.com/api/lapp/v2/live/address/get';
|
||||
|
||||
$key = $deviceSerial.'-2'.$channelNo;
|
||||
|
||||
$url_data = getCache($key,$this->uniacid);
|
||||
|
||||
if(empty($url_data)){
|
||||
|
||||
$post_data = [
|
||||
|
||||
'accessToken' => $this->getToken(),
|
||||
|
||||
'deviceSerial'=> $deviceSerial,
|
||||
|
||||
'channelNo' => $channelNo,
|
||||
|
||||
'protocol' => 2,
|
||||
|
||||
'quality' => 2
|
||||
];
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = @json_decode($data,true);
|
||||
|
||||
if(isset($data['code'])&&$data['code']==200){
|
||||
|
||||
$url_data = $data['data']['url'];
|
||||
|
||||
setCache($key,$url_data,86400,$this->uniacid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $url_data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $deviceSerial
|
||||
* @param $direction
|
||||
* @param int $channelNo
|
||||
* @功能说明:开始转动
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-04-12 10:51
|
||||
*/
|
||||
public function startTurn($deviceSerial,$direction,$channelNo=1)
|
||||
{
|
||||
$url='https://open.ys7.com/api/lapp/device/ptz/start';
|
||||
|
||||
$post_data = [
|
||||
|
||||
'accessToken' => $this->getToken(),
|
||||
|
||||
'deviceSerial'=> $deviceSerial,
|
||||
|
||||
'channelNo' => $channelNo,
|
||||
|
||||
'direction' => $direction,
|
||||
|
||||
'speed' => 1
|
||||
];
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $deviceSerial
|
||||
* @param $direction
|
||||
* @param int $channelNo
|
||||
* @功能说明:停止转动
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-04-12 10:51
|
||||
*/
|
||||
public function stopTurn($deviceSerial,$direction=0,$channelNo=1)
|
||||
{
|
||||
$url='https://open.ys7.com/api/lapp/device/ptz/stop';
|
||||
|
||||
$post_data = [
|
||||
|
||||
'accessToken' => $this->getToken(),
|
||||
|
||||
'deviceSerial'=> $deviceSerial,
|
||||
|
||||
'channelNo' => $channelNo,
|
||||
|
||||
'direction' => $direction,
|
||||
|
||||
];
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $post_data
|
||||
* @param string $post_type
|
||||
* @功能说明:发送请求
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-26 14:38
|
||||
*/
|
||||
public function request($url,$post_data,$post_type='POST'){
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
$post_data = json_encode($post_data);
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => $post_type,
|
||||
CURLOPT_POSTFIELDS => $post_data,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Content-Type:application/json",
|
||||
"User-Agent:openApi",
|
||||
"Content-Type:application/json; charset=utf-8",
|
||||
"accept-encoding:gzip,deflate",
|
||||
"time-stamp:".time(),
|
||||
// "data-signature:D2C3D3C7289EAE111277999D21196D4D",
|
||||
"data-signature:".strtoupper(md5($this->appKey.$post_data))
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
return json_decode($response,true);
|
||||
|
||||
// if ($err) {
|
||||
// echo "cURL Error #:" . $err;
|
||||
// } else {
|
||||
// echo $response;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user