mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-05 19:41:44 +08:00
[更新]代码标准化
This commit is contained in:
parent
c958252c02
commit
1ccbf8322d
@ -27,7 +27,8 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/02/15 18:13
|
||||
*/
|
||||
class Auth extends BasicAdmin {
|
||||
class Auth extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 默认数据模型
|
||||
@ -38,7 +39,8 @@ class Auth extends BasicAdmin {
|
||||
/**
|
||||
* 权限列表
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$this->title = '系统权限管理';
|
||||
return parent::_list($this->table);
|
||||
}
|
||||
@ -47,7 +49,8 @@ class Auth extends BasicAdmin {
|
||||
* 权限授权
|
||||
* @return string
|
||||
*/
|
||||
public function apply() {
|
||||
public function apply()
|
||||
{
|
||||
$auth_id = $this->request->get('id', '0');
|
||||
$method = '_apply_' . strtolower($this->request->get('action', '0'));
|
||||
if (method_exists($this, $method)) {
|
||||
@ -61,7 +64,8 @@ class Auth extends BasicAdmin {
|
||||
* 读取授权节点
|
||||
* @param $auth_id
|
||||
*/
|
||||
protected function _apply_getnode($auth_id) {
|
||||
protected function _apply_getnode($auth_id)
|
||||
{
|
||||
$nodes = NodeService::get();
|
||||
$checked = Db::name('SystemAuthNode')->where('auth', $auth_id)->column('node');
|
||||
foreach ($nodes as $key => &$node) {
|
||||
@ -78,7 +82,8 @@ class Auth extends BasicAdmin {
|
||||
* 保存授权节点
|
||||
* @param $auth_id
|
||||
*/
|
||||
protected function _apply_save($auth_id) {
|
||||
protected function _apply_save($auth_id)
|
||||
{
|
||||
$data = [];
|
||||
$post = $this->request->post();
|
||||
foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) {
|
||||
@ -95,7 +100,8 @@ class Auth extends BasicAdmin {
|
||||
* @param int $level
|
||||
* @return array
|
||||
*/
|
||||
protected function _apply_filter($nodes, $level = 1) {
|
||||
protected function _apply_filter($nodes, $level = 1)
|
||||
{
|
||||
foreach ($nodes as $key => &$node) {
|
||||
if (!empty($node['_sub_']) && is_array($node['_sub_'])) {
|
||||
$node['_sub_'] = $this->_apply_filter($node['_sub_'], $level + 1);
|
||||
@ -109,21 +115,24 @@ class Auth extends BasicAdmin {
|
||||
/**
|
||||
* 权限添加
|
||||
*/
|
||||
public function add() {
|
||||
public function add()
|
||||
{
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限编辑
|
||||
*/
|
||||
public function edit() {
|
||||
public function edit()
|
||||
{
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限禁用
|
||||
*/
|
||||
public function forbid() {
|
||||
public function forbid()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("权限禁用成功!", '');
|
||||
}
|
||||
@ -133,7 +142,8 @@ class Auth extends BasicAdmin {
|
||||
/**
|
||||
* 权限恢复
|
||||
*/
|
||||
public function resume() {
|
||||
public function resume()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("权限启用成功!", '');
|
||||
}
|
||||
@ -143,7 +153,8 @@ class Auth extends BasicAdmin {
|
||||
/**
|
||||
* 权限删除
|
||||
*/
|
||||
public function del() {
|
||||
public function del()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$id = $this->request->post('id');
|
||||
Db::name('SystemAuthNode')->where('auth', $id)->delete();
|
||||
|
@ -24,7 +24,8 @@ use service\LogService;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/02/15 18:05
|
||||
*/
|
||||
class Config extends BasicAdmin {
|
||||
class Config extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 当前默认数据模型
|
||||
@ -41,7 +42,8 @@ class Config extends BasicAdmin {
|
||||
/**
|
||||
* 显示系统常规配置
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->assign('title', $this->title);
|
||||
return view();
|
||||
@ -56,7 +58,8 @@ class Config extends BasicAdmin {
|
||||
/**
|
||||
* 文件存储配置
|
||||
*/
|
||||
public function file() {
|
||||
public function file()
|
||||
{
|
||||
$this->title = '文件存储配置';
|
||||
$alert = ['type' => 'success', 'title' => '操作提示', 'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!'];
|
||||
$this->assign('alert', $alert);
|
||||
|
@ -28,13 +28,15 @@ use think\View;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/02/15 10:41
|
||||
*/
|
||||
class Index extends BasicAdmin {
|
||||
class Index extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 后台框架布局
|
||||
* @return View
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
NodeService::applyAuthNode();
|
||||
$list = Db::name('SystemMenu')->where('status', '1')->order('sort asc,id asc')->select();
|
||||
$menus = $this->_filterMenu(ToolsService::arr2tree($list));
|
||||
@ -46,7 +48,8 @@ class Index extends BasicAdmin {
|
||||
* @param array $menus
|
||||
* @return array
|
||||
*/
|
||||
private function _filterMenu($menus) {
|
||||
private function _filterMenu($menus)
|
||||
{
|
||||
foreach ($menus as $key => &$menu) {
|
||||
if (!empty($menu['sub'])) {
|
||||
$menu['sub'] = $this->_filterMenu($menu['sub']);
|
||||
@ -68,12 +71,13 @@ class Index extends BasicAdmin {
|
||||
* 主机信息显示
|
||||
* @return View
|
||||
*/
|
||||
public function main() {
|
||||
public function main()
|
||||
{
|
||||
if (session('user.username') === 'admin' && session('user.password') === '21232f297a57a5a743894a0e4a801fc3') {
|
||||
$url = url('admin/index/pass') . '?id=' . session('user.id');
|
||||
$alert = [
|
||||
'type' => 'danger',
|
||||
'title' => '安全提示',
|
||||
'type' => 'danger',
|
||||
'title' => '安全提示',
|
||||
'content' => "超级管理员默认密码未修改,建议马上<a href='javascript:void(0)' data-modal='{$url}'>修改</a>!"
|
||||
];
|
||||
$this->assign('alert', $alert);
|
||||
@ -87,7 +91,8 @@ class Index extends BasicAdmin {
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public function pass() {
|
||||
public function pass()
|
||||
{
|
||||
if (in_array('10000', explode(',', $this->request->post('id')))) {
|
||||
$this->error('系统超级账号禁止操作!');
|
||||
}
|
||||
@ -117,7 +122,8 @@ class Index extends BasicAdmin {
|
||||
/**
|
||||
* 修改资料
|
||||
*/
|
||||
public function info() {
|
||||
public function info()
|
||||
{
|
||||
if (in_array('10000', explode(',', $this->request->post('id')))) {
|
||||
$this->error('系统超级账号禁止操作!');
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/02/15 18:12
|
||||
*/
|
||||
class Log extends BasicAdmin {
|
||||
class Log extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 指定当前数据表
|
||||
@ -36,7 +37,8 @@ class Log extends BasicAdmin {
|
||||
/**
|
||||
* 日志列表
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$this->title = '系统操作日志';
|
||||
$get = $this->request->get();
|
||||
$actions = Db::name($this->table)->group('action')->column('action');
|
||||
@ -54,7 +56,8 @@ class Log extends BasicAdmin {
|
||||
* 列表数据处理
|
||||
* @param $data
|
||||
*/
|
||||
protected function _index_data_filter(&$data) {
|
||||
protected function _index_data_filter(&$data)
|
||||
{
|
||||
$ip = new \Ip2Region();
|
||||
foreach ($data as &$vo) {
|
||||
$result = $ip->btreeSearch($vo['ip']);
|
||||
@ -66,7 +69,8 @@ class Log extends BasicAdmin {
|
||||
/**
|
||||
* 日志删除操作
|
||||
*/
|
||||
public function del() {
|
||||
public function del()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("日志删除成功!", '');
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/02/10 13:59
|
||||
*/
|
||||
class Login extends BasicAdmin {
|
||||
class Login extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 默认检查用户登录状态
|
||||
@ -43,7 +44,8 @@ class Login extends BasicAdmin {
|
||||
/**
|
||||
* 控制器基础方法
|
||||
*/
|
||||
public function _initialize() {
|
||||
public function _initialize()
|
||||
{
|
||||
if (session('user') && $this->request->action() !== 'out') {
|
||||
$this->redirect('@admin');
|
||||
}
|
||||
@ -53,7 +55,8 @@ class Login extends BasicAdmin {
|
||||
* 用户登录
|
||||
* @return string
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
return $this->fetch('', ['title' => '用户登录']);
|
||||
} else {
|
||||
@ -80,7 +83,8 @@ class Login extends BasicAdmin {
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
public function out() {
|
||||
public function out()
|
||||
{
|
||||
LogService::write('系统管理', '用户退出系统成功');
|
||||
session('user', null);
|
||||
session_destroy();
|
||||
|
@ -27,7 +27,8 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/02/15
|
||||
*/
|
||||
class Menu extends BasicAdmin {
|
||||
class Menu extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 绑定操作模型
|
||||
@ -38,7 +39,8 @@ class Menu extends BasicAdmin {
|
||||
/**
|
||||
* 菜单列表
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$this->title = '系统菜单管理';
|
||||
$db = Db::name($this->table)->order('sort asc,id asc');
|
||||
return parent::_list($db, false);
|
||||
@ -48,7 +50,8 @@ class Menu extends BasicAdmin {
|
||||
* 列表数据处理
|
||||
* @param array $data
|
||||
*/
|
||||
protected function _index_data_filter(&$data) {
|
||||
protected function _index_data_filter(&$data)
|
||||
{
|
||||
foreach ($data as &$vo) {
|
||||
($vo['url'] !== '#') && ($vo['url'] = url($vo['url']));
|
||||
$vo['ids'] = join(',', ToolsService::getArrSubIds($data, $vo['id']));
|
||||
@ -59,14 +62,16 @@ class Menu extends BasicAdmin {
|
||||
/**
|
||||
* 添加菜单
|
||||
*/
|
||||
public function add() {
|
||||
public function add()
|
||||
{
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
*/
|
||||
public function edit() {
|
||||
public function edit()
|
||||
{
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
|
||||
@ -74,7 +79,8 @@ class Menu extends BasicAdmin {
|
||||
* 表单数据前缀方法
|
||||
* @param array $vo
|
||||
*/
|
||||
protected function _form_filter(&$vo) {
|
||||
protected function _form_filter(&$vo)
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
// 上级菜单处理
|
||||
$_menus = Db::name($this->table)->where('status', '1')->order('sort desc,id desc')->select();
|
||||
@ -107,7 +113,8 @@ class Menu extends BasicAdmin {
|
||||
/**
|
||||
* 删除菜单
|
||||
*/
|
||||
public function del() {
|
||||
public function del()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("菜单删除成功!", '');
|
||||
}
|
||||
@ -117,7 +124,8 @@ class Menu extends BasicAdmin {
|
||||
/**
|
||||
* 菜单禁用
|
||||
*/
|
||||
public function forbid() {
|
||||
public function forbid()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("菜单禁用成功!", '');
|
||||
}
|
||||
@ -127,7 +135,8 @@ class Menu extends BasicAdmin {
|
||||
/**
|
||||
* 菜单禁用
|
||||
*/
|
||||
public function resume() {
|
||||
public function resume()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("菜单启用成功!", '');
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ use service\ToolsService;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/02/15 18:13
|
||||
*/
|
||||
class Node extends BasicAdmin {
|
||||
class Node extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 指定当前默认模型
|
||||
@ -37,7 +38,8 @@ class Node extends BasicAdmin {
|
||||
/**
|
||||
* 显示节点列表
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$alert = ['type' => 'danger', 'title' => '安全警告', 'content' => '结构为系统自动生成, 状态数据请勿随意修改!'];
|
||||
$nodes = ToolsService::arr2table(NodeService::get(), 'node', 'pnode');
|
||||
return view('', ['title' => '系统节点管理', 'nodes' => $nodes, 'alert' => $alert]);
|
||||
@ -46,7 +48,8 @@ class Node extends BasicAdmin {
|
||||
/**
|
||||
* 保存节点变更
|
||||
*/
|
||||
public function save() {
|
||||
public function save()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
if (isset($post['name']) && isset($post['value'])) {
|
||||
|
@ -25,7 +25,8 @@ use think\View;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/02/21
|
||||
*/
|
||||
class Plugs extends BasicAdmin {
|
||||
class Plugs extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 默认检查用户登录状态
|
||||
@ -43,7 +44,8 @@ class Plugs extends BasicAdmin {
|
||||
* 文件上传
|
||||
* @return View
|
||||
*/
|
||||
public function upfile() {
|
||||
public function upfile()
|
||||
{
|
||||
if (!in_array(($uptype = $this->request->get('uptype')), ['local', 'qiniu'])) {
|
||||
$uptype = sysconf('storage_type');
|
||||
}
|
||||
@ -58,7 +60,8 @@ class Plugs extends BasicAdmin {
|
||||
* 通用文件上传
|
||||
* @return string
|
||||
*/
|
||||
public function upload() {
|
||||
public function upload()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$md5s = str_split($this->request->post('md5'), 16);
|
||||
if (($info = $this->request->file('file')->move('static' . DS . 'upload' . DS . $md5s[0], $md5s[1], true))) {
|
||||
@ -74,7 +77,8 @@ class Plugs extends BasicAdmin {
|
||||
/**
|
||||
* 文件状态检查
|
||||
*/
|
||||
public function upstate() {
|
||||
public function upstate()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$filename = join('/', str_split($post['md5'], 16)) . '.' . pathinfo($post['filename'], PATHINFO_EXTENSION);
|
||||
// 检查文件是否已上传
|
||||
@ -111,15 +115,16 @@ class Plugs extends BasicAdmin {
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function _getQiniuToken($key) {
|
||||
protected function _getQiniuToken($key)
|
||||
{
|
||||
$accessKey = sysconf('storage_qiniu_access_key');
|
||||
$secretKey = sysconf('storage_qiniu_secret_key');
|
||||
$bucket = sysconf('storage_qiniu_bucket');
|
||||
$host = sysconf('storage_qiniu_domain');
|
||||
$protocol = sysconf('storage_qiniu_is_https') ? 'https' : 'http';
|
||||
$params = [
|
||||
"scope" => "{$bucket}:{$key}",
|
||||
"deadline" => 3600 + time(),
|
||||
"scope" => "{$bucket}:{$key}",
|
||||
"deadline" => 3600 + time(),
|
||||
"returnBody" => "{\"data\":{\"site_url\":\"{$protocol}://{$host}/$(key)\",\"file_url\":\"$(key)\"}, \"code\": \"SUCCESS\"}",
|
||||
];
|
||||
$data = str_replace(['+', '/'], ['-', '_'], base64_encode(json_encode($params)));
|
||||
@ -129,7 +134,8 @@ class Plugs extends BasicAdmin {
|
||||
/**
|
||||
* 字体图标
|
||||
*/
|
||||
public function icon() {
|
||||
public function icon()
|
||||
{
|
||||
$this->assign('field', $this->request->get('field', 'icon'));
|
||||
return view();
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/02/15 18:12
|
||||
*/
|
||||
class User extends BasicAdmin {
|
||||
class User extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 指定当前数据表
|
||||
@ -36,7 +37,8 @@ class User extends BasicAdmin {
|
||||
/**
|
||||
* 用户列表
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
// 设置页面标题
|
||||
$this->title = '系统用户管理';
|
||||
// 获取到所有GET参数
|
||||
@ -57,28 +59,32 @@ class User extends BasicAdmin {
|
||||
* 授权管理
|
||||
* @return array|string
|
||||
*/
|
||||
public function auth() {
|
||||
public function auth()
|
||||
{
|
||||
return $this->_form($this->table, 'auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户添加
|
||||
*/
|
||||
public function add() {
|
||||
public function add()
|
||||
{
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户编辑
|
||||
*/
|
||||
public function edit() {
|
||||
public function edit()
|
||||
{
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户密码修改
|
||||
*/
|
||||
public function pass() {
|
||||
public function pass()
|
||||
{
|
||||
if (in_array('10000', explode(',', $this->request->post('id')))) {
|
||||
$this->error('系统超级账号禁止操作!');
|
||||
}
|
||||
@ -100,7 +106,8 @@ class User extends BasicAdmin {
|
||||
* 表单数据默认处理
|
||||
* @param array $data
|
||||
*/
|
||||
public function _form_filter(&$data) {
|
||||
public function _form_filter(&$data)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
if (isset($data['authorize']) && is_array($data['authorize'])) {
|
||||
$data['authorize'] = join(',', $data['authorize']);
|
||||
@ -119,7 +126,8 @@ class User extends BasicAdmin {
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
public function del() {
|
||||
public function del()
|
||||
{
|
||||
if (in_array('10000', explode(',', $this->request->post('id')))) {
|
||||
$this->error('系统超级账号禁止删除!');
|
||||
}
|
||||
@ -132,7 +140,8 @@ class User extends BasicAdmin {
|
||||
/**
|
||||
* 用户禁用
|
||||
*/
|
||||
public function forbid() {
|
||||
public function forbid()
|
||||
{
|
||||
if (in_array('10000', explode(',', $this->request->post('id')))) {
|
||||
$this->error('系统超级账号禁止操作!');
|
||||
}
|
||||
@ -145,7 +154,8 @@ class User extends BasicAdmin {
|
||||
/**
|
||||
* 用户禁用
|
||||
*/
|
||||
public function resume() {
|
||||
public function resume()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("用户启用成功!", '');
|
||||
}
|
||||
|
@ -24,7 +24,8 @@ use think\Db;
|
||||
* @param bool $replace
|
||||
* @param string|null $pathname
|
||||
*/
|
||||
function p($data, $replace = false, $pathname = NULL) {
|
||||
function p($data, $replace = false, $pathname = NULL)
|
||||
{
|
||||
is_null($pathname) && $pathname = RUNTIME_PATH . date('Ymd') . '.txt';
|
||||
$str = (is_string($data) ? $data : (is_array($data) || is_object($data)) ? print_r($data, true) : var_export($data, true)) . "\n";
|
||||
$replace ? file_put_contents($pathname, $str) : file_put_contents($pathname, $str, FILE_APPEND);
|
||||
@ -35,20 +36,21 @@ function p($data, $replace = false, $pathname = NULL) {
|
||||
* @param string $type
|
||||
* @return \Wechat\WechatReceive|\Wechat\WechatUser|\Wechat\WechatPay|\Wechat\WechatScript|\Wechat\WechatOauth|\Wechat\WechatMenu
|
||||
*/
|
||||
function & load_wechat($type = '') {
|
||||
function & load_wechat($type = '')
|
||||
{
|
||||
static $wechat = array();
|
||||
$index = md5(strtolower($type));
|
||||
if (!isset($wechat[$index])) {
|
||||
$config = [
|
||||
'token' => sysconf('wechat_token'),
|
||||
'appid' => sysconf('wechat_appid'),
|
||||
'appsecret' => sysconf('wechat_appsecret'),
|
||||
'token' => sysconf('wechat_token'),
|
||||
'appid' => sysconf('wechat_appid'),
|
||||
'appsecret' => sysconf('wechat_appsecret'),
|
||||
'encodingaeskey' => sysconf('wechat_encodingaeskey'),
|
||||
'mch_id' => sysconf('wechat_mch_id'),
|
||||
'partnerkey' => sysconf('wechat_partnerkey'),
|
||||
'ssl_cer' => sysconf('wechat_cert_cert'),
|
||||
'ssl_key' => sysconf('wechat_cert_key'),
|
||||
'cachepath' => CACHE_PATH . 'wxpay' . DS,
|
||||
'mch_id' => sysconf('wechat_mch_id'),
|
||||
'partnerkey' => sysconf('wechat_partnerkey'),
|
||||
'ssl_cer' => sysconf('wechat_cert_cert'),
|
||||
'ssl_key' => sysconf('wechat_cert_key'),
|
||||
'cachepath' => CACHE_PATH . 'wxpay' . DS,
|
||||
];
|
||||
$wechat[$index] = Loader::get($type, $config);
|
||||
}
|
||||
@ -60,7 +62,8 @@ function & load_wechat($type = '') {
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function encode($string) {
|
||||
function encode($string)
|
||||
{
|
||||
$chars = '';
|
||||
$len = strlen($string = iconv('utf-8', 'gbk', $string));
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
@ -74,7 +77,8 @@ function encode($string) {
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function decode($string) {
|
||||
function decode($string)
|
||||
{
|
||||
$chars = '';
|
||||
foreach (str_split($string, 2) as $char) {
|
||||
$chars .= chr(intval(base_convert($char, 36, 10)));
|
||||
@ -87,7 +91,8 @@ function decode($string) {
|
||||
* @param string $node
|
||||
* @return bool
|
||||
*/
|
||||
function auth($node) {
|
||||
function auth($node)
|
||||
{
|
||||
return NodeService::checkAuthNode($node);
|
||||
}
|
||||
|
||||
@ -97,7 +102,8 @@ function auth($node) {
|
||||
* @param bool $value 默认是false为获取值,否则为更新
|
||||
* @return string|bool
|
||||
*/
|
||||
function sysconf($name, $value = false) {
|
||||
function sysconf($name, $value = false)
|
||||
{
|
||||
static $config = [];
|
||||
if ($value !== false) {
|
||||
$config = [];
|
||||
@ -117,7 +123,8 @@ function sysconf($name, $value = false) {
|
||||
*/
|
||||
if (!function_exists("array_column")) {
|
||||
|
||||
function array_column(array &$rows, $column_key, $index_key = null) {
|
||||
function array_column(array &$rows, $column_key, $index_key = null)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($rows as $row) {
|
||||
if (empty($index_key)) {
|
||||
|
@ -23,12 +23,14 @@ use think\Controller;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/04/05 10:38
|
||||
*/
|
||||
class Index extends Controller {
|
||||
class Index extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 网站入口
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$this->redirect('@admin');
|
||||
}
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | Think.Admin
|
||||
// +----------------------------------------------------------------------
|
||||
// | 版权所有 2016~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | 官方网站: http://think.ctolog.com
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zoujingli/Think.Admin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use controller\BasicApi;
|
||||
use service\FileService;
|
||||
|
||||
class Test extends BasicApi {
|
||||
|
||||
public function index() {
|
||||
dump(FileService::oss('fassdfsa', 'fsadfasdf'));
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,8 @@ use controller\BasicWechat;
|
||||
use service\DataService;
|
||||
use service\PayService;
|
||||
|
||||
class Wap extends BasicWechat {
|
||||
class Wap extends BasicWechat
|
||||
{
|
||||
|
||||
/**
|
||||
* 禁用自动网页授权
|
||||
@ -29,7 +30,8 @@ class Wap extends BasicWechat {
|
||||
/**
|
||||
* 网页授权DEMO
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
// dump($this->oAuth(false)); // 仅获取用户openid
|
||||
dump($this->oAuth()); // 获取用户详情信息
|
||||
dump($this->fansinfo); // 打
|
||||
@ -39,7 +41,8 @@ class Wap extends BasicWechat {
|
||||
* 微信二维码支付DEMO
|
||||
* @return \think\response\Json|\think\response\View
|
||||
*/
|
||||
public function payqrc() {
|
||||
public function payqrc()
|
||||
{
|
||||
switch ($this->request->get('action')) {
|
||||
case 'payqrc':
|
||||
$pay = &load_wechat('pay');
|
||||
@ -69,7 +72,8 @@ class Wap extends BasicWechat {
|
||||
* 微信JSAPI支付DEMO
|
||||
* @return \think\response\Json|\think\response\View
|
||||
*/
|
||||
public function payjs() {
|
||||
public function payjs()
|
||||
{
|
||||
$this->openid = $this->oAuth(false);
|
||||
switch ($this->request->get('action')) {
|
||||
case 'options':
|
||||
|
@ -27,7 +27,8 @@ use Wechat\WechatReceive;
|
||||
* @package app\wechat\controller
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
*/
|
||||
class Api extends Controller {
|
||||
class Api extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 微信openid
|
||||
@ -45,7 +46,8 @@ class Api extends Controller {
|
||||
* 微信消息接口
|
||||
* @return string
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
// 实例接口对象
|
||||
$this->wechat = &load_wechat('Receive');
|
||||
// 验证接口请求
|
||||
@ -79,7 +81,8 @@ class Api extends Controller {
|
||||
* @param bool $isForce
|
||||
* @return string
|
||||
*/
|
||||
private function _keys($keys, $isForce = false) {
|
||||
private function _keys($keys, $isForce = false)
|
||||
{
|
||||
list($table, $field, $value) = explode('#', $keys . '##');
|
||||
if (is_array($info = Db::name($table)->where($field, $value)->find()) && isset($info['type'])) {
|
||||
// 数据状态检查
|
||||
@ -152,15 +155,16 @@ class Api extends Controller {
|
||||
* @param int $news_id
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function _news($news_id = 0) {
|
||||
protected function _news($news_id = 0)
|
||||
{
|
||||
if (is_array($newsinfo = WechatService::getNewsById($news_id)) && !empty($newsinfo['articles'])) {
|
||||
$newsdata = array();
|
||||
foreach ($newsinfo['articles'] as $vo) {
|
||||
$newsdata[] = [
|
||||
'Title' => $vo['title'],
|
||||
'Title' => $vo['title'],
|
||||
'Description' => $vo['digest'],
|
||||
'PicUrl' => $vo['local_url'],
|
||||
'Url' => url("@wechat/review", '', true, true) . "?content={$vo['id']}&type=article",
|
||||
'PicUrl' => $vo['local_url'],
|
||||
'Url' => url("@wechat/review", '', true, true) . "?content={$vo['id']}&type=article",
|
||||
];
|
||||
}
|
||||
return $this->wechat->news($newsdata)->reply(false, true);
|
||||
@ -171,7 +175,8 @@ class Api extends Controller {
|
||||
/**
|
||||
* 事件处理
|
||||
*/
|
||||
protected function _event() {
|
||||
protected function _event()
|
||||
{
|
||||
$event = $this->wechat->getRevEvent();
|
||||
switch (strtolower($event['event'])) {
|
||||
case 'subscribe': // 粉丝关注事件
|
||||
@ -204,7 +209,8 @@ class Api extends Controller {
|
||||
* @param string $event
|
||||
* @return mixed
|
||||
*/
|
||||
private function _spread($event) {
|
||||
private function _spread($event)
|
||||
{
|
||||
$key = preg_replace('|^.*?(\d+).*?$|', '$1', "{$event}");
|
||||
// 检测推荐是否有效
|
||||
$fans = Db::name('WechatFans')->where('id', $key)->find();
|
||||
@ -221,14 +227,16 @@ class Api extends Controller {
|
||||
* 位置事情回复
|
||||
* @return string
|
||||
*/
|
||||
private function _location() {
|
||||
private function _location()
|
||||
{
|
||||
return 'success';
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片事件处理
|
||||
*/
|
||||
private function _image() {
|
||||
private function _image()
|
||||
{
|
||||
return 'success';
|
||||
}
|
||||
|
||||
@ -236,7 +244,8 @@ class Api extends Controller {
|
||||
* 同步粉丝状态
|
||||
* @param bool $subscribe 关注状态
|
||||
*/
|
||||
protected function _updateFansInfo($subscribe = true) {
|
||||
protected function _updateFansInfo($subscribe = true)
|
||||
{
|
||||
if ($subscribe) {
|
||||
$fans = WechatService::getFansInfo($this->openid);
|
||||
if (empty($fans) || empty($fans['subscribe'])) {
|
||||
|
@ -27,7 +27,8 @@ use think\response\View;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/27 14:43
|
||||
*/
|
||||
class Config extends BasicAdmin {
|
||||
class Config extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 定义当前操作表名
|
||||
@ -39,7 +40,8 @@ class Config extends BasicAdmin {
|
||||
* 微信基础参数配置
|
||||
* @return View
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
return view('', ['title' => '微信接口配置']);
|
||||
}
|
||||
@ -54,7 +56,8 @@ class Config extends BasicAdmin {
|
||||
* 微信商户参数配置
|
||||
* @return View
|
||||
*/
|
||||
public function pay() {
|
||||
public function pay()
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
switch ($this->request->get('action')) {
|
||||
// 生成测试支付二维码
|
||||
|
@ -27,7 +27,8 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/27 14:43
|
||||
*/
|
||||
class Fans extends BasicAdmin {
|
||||
class Fans extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 定义当前默认数据表
|
||||
@ -39,7 +40,8 @@ class Fans extends BasicAdmin {
|
||||
* 显示粉丝列表
|
||||
* @return array|string
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$this->title = '微信粉丝管理';
|
||||
$db = Db::name($this->table)->where('is_back', '0')->order('subscribe_time desc');
|
||||
$get = $this->request->get();
|
||||
@ -59,7 +61,8 @@ class Fans extends BasicAdmin {
|
||||
* 列表数据处理
|
||||
* @param type $list
|
||||
*/
|
||||
protected function _data_filter(&$list) {
|
||||
protected function _data_filter(&$list)
|
||||
{
|
||||
$tags = Db::name('WechatFansTags')->column('id,name');
|
||||
foreach ($list as &$vo) {
|
||||
$vo['nickname'] = ToolsService::emojiDecode($vo['nickname']);
|
||||
@ -78,7 +81,8 @@ class Fans extends BasicAdmin {
|
||||
/**
|
||||
* 黑名单列表
|
||||
*/
|
||||
public function back() {
|
||||
public function back()
|
||||
{
|
||||
$this->title = '微信粉丝黑名单管理';
|
||||
$db = Db::name($this->table)->where('is_back', '1')->order('subscribe_time desc');
|
||||
$get = $this->request->get();
|
||||
@ -97,8 +101,9 @@ class Fans extends BasicAdmin {
|
||||
/**
|
||||
* 设置黑名单
|
||||
*/
|
||||
public function backadd() {
|
||||
$wechat = & load_wechat('User');
|
||||
public function backadd()
|
||||
{
|
||||
$wechat = &load_wechat('User');
|
||||
$openids = $this->_getActionOpenids();
|
||||
if (false !== $wechat->addBacklist($openids)) {
|
||||
Db::name($this->table)->where('openid', 'in', $openids)->setField('is_back', '1');
|
||||
@ -110,12 +115,13 @@ class Fans extends BasicAdmin {
|
||||
/**
|
||||
* 标签选择
|
||||
*/
|
||||
public function tagset() {
|
||||
public function tagset()
|
||||
{
|
||||
$tags = $this->request->post('tags', '');
|
||||
$fans_id = $this->request->post('fans_id', '');
|
||||
$fans = Db::name('WechatFans')->where('id', $fans_id)->find();
|
||||
empty($fans) && $this->error('需要操作的数据不存在!');
|
||||
$wechat = & load_wechat('User');
|
||||
$wechat = &load_wechat('User');
|
||||
foreach (explode(',', $fans['tagid_list']) as $tagid) {
|
||||
is_numeric($tagid) && $wechat->batchDeleteUserTag($tagid, [$fans['openid']]);
|
||||
}
|
||||
@ -131,8 +137,9 @@ class Fans extends BasicAdmin {
|
||||
/**
|
||||
* 取消黑名
|
||||
*/
|
||||
public function backdel() {
|
||||
$wechat = & load_wechat('User');
|
||||
public function backdel()
|
||||
{
|
||||
$wechat = &load_wechat('User');
|
||||
$openids = $this->_getActionOpenids();
|
||||
if (false !== $wechat->delBacklist($openids)) {
|
||||
Db::name($this->table)->where('openid', 'in', $openids)->setField('is_back', '0');
|
||||
@ -144,11 +151,12 @@ class Fans extends BasicAdmin {
|
||||
/**
|
||||
* 给粉丝增加标签
|
||||
*/
|
||||
public function tagadd() {
|
||||
public function tagadd()
|
||||
{
|
||||
$tagid = $this->request->post('tag_id', 0);
|
||||
empty($tagid) && $this->error('没有可能操作的标签ID');
|
||||
$openids = $this->_getActionOpenids();
|
||||
$wechat = & load_wechat('User');
|
||||
$wechat = &load_wechat('User');
|
||||
if (false !== $wechat->batchAddUserTag($tagid, $openids)) {
|
||||
$this->success('设置粉丝标签成功!', '');
|
||||
}
|
||||
@ -158,11 +166,12 @@ class Fans extends BasicAdmin {
|
||||
/**
|
||||
* 移除粉丝标签
|
||||
*/
|
||||
public function tagdel() {
|
||||
public function tagdel()
|
||||
{
|
||||
$tagid = $this->request->post('tag_id', 0);
|
||||
empty($tagid) && $this->error('没有可能操作的标签ID');
|
||||
$openids = $this->_getActionOpenids();
|
||||
$wechat = & load_wechat('User');
|
||||
$wechat = &load_wechat('User');
|
||||
if (false !== $wechat->batchDeleteUserTag($tagid, $openids)) {
|
||||
$this->success('删除粉丝标签成功!', '');
|
||||
}
|
||||
@ -173,7 +182,8 @@ class Fans extends BasicAdmin {
|
||||
* 获取当前操作用户openid数组
|
||||
* @return array
|
||||
*/
|
||||
private function _getActionOpenids() {
|
||||
private function _getActionOpenids()
|
||||
{
|
||||
$ids = $this->request->post('id', '');
|
||||
empty($ids) && $this->error('没有需要操作的数据!');
|
||||
$openids = Db::name($this->table)->where('id', 'in', explode(',', $ids))->column('openid');
|
||||
@ -184,7 +194,8 @@ class Fans extends BasicAdmin {
|
||||
/**
|
||||
* 同步粉丝列表
|
||||
*/
|
||||
public function sync() {
|
||||
public function sync()
|
||||
{
|
||||
Db::name($this->table)->where('1=1')->delete();
|
||||
if (WechatService::syncAllFans('')) {
|
||||
WechatService::syncBlackFans('');
|
||||
|
@ -24,7 +24,8 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/27 14:43
|
||||
*/
|
||||
class Keys extends BasicAdmin {
|
||||
class Keys extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 指定当前数据表
|
||||
@ -35,7 +36,8 @@ class Keys extends BasicAdmin {
|
||||
/**
|
||||
* 显示关键字列表
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$this->assign('title', '微信关键字');
|
||||
$db = Db::name($this->table)->where('keys', 'not in', ['subscribe', 'default']);
|
||||
return $this->_list($db);
|
||||
@ -45,7 +47,8 @@ class Keys extends BasicAdmin {
|
||||
* 列表数据处理
|
||||
* @param array $data
|
||||
*/
|
||||
protected function _index_data_filter(&$data) {
|
||||
protected function _index_data_filter(&$data)
|
||||
{
|
||||
$types = ['keys' => '关键字', 'image' => '图片', 'news' => '图文', 'music' => '音乐', 'text' => '文字', 'video' => '视频', 'voice' => '语音'];
|
||||
foreach ($data as &$vo) {
|
||||
$vo['type'] = isset($types[$vo['type']]) ? $types[$vo['type']] : $vo['type'];
|
||||
@ -56,7 +59,8 @@ class Keys extends BasicAdmin {
|
||||
* 添加关键字
|
||||
* @return string
|
||||
*/
|
||||
public function add() {
|
||||
public function add()
|
||||
{
|
||||
$this->title = '添加关键字规则';
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
@ -65,7 +69,8 @@ class Keys extends BasicAdmin {
|
||||
* 编辑关键字
|
||||
* @return string
|
||||
*/
|
||||
public function edit() {
|
||||
public function edit()
|
||||
{
|
||||
$this->title = '编辑关键字规则';
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
@ -75,7 +80,8 @@ class Keys extends BasicAdmin {
|
||||
* 表单处理
|
||||
* @param $data
|
||||
*/
|
||||
protected function _form_filter($data) {
|
||||
protected function _form_filter($data)
|
||||
{
|
||||
if ($this->request->isPost() && isset($data['keys'])) {
|
||||
$db = Db::name($this->table)->where('keys', $data['keys']);
|
||||
!empty($data['id']) && $db->where('id', 'neq', $data['id']);
|
||||
@ -86,7 +92,8 @@ class Keys extends BasicAdmin {
|
||||
/**
|
||||
* 删除关键字
|
||||
*/
|
||||
public function del() {
|
||||
public function del()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("关键字删除成功!", '');
|
||||
}
|
||||
@ -97,7 +104,8 @@ class Keys extends BasicAdmin {
|
||||
/**
|
||||
* 关键字禁用
|
||||
*/
|
||||
public function forbid() {
|
||||
public function forbid()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("关键字禁用成功!", '');
|
||||
}
|
||||
@ -107,7 +115,8 @@ class Keys extends BasicAdmin {
|
||||
/**
|
||||
* 关键字禁用
|
||||
*/
|
||||
public function resume() {
|
||||
public function resume()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("关键字启用成功!", '');
|
||||
}
|
||||
@ -117,7 +126,8 @@ class Keys extends BasicAdmin {
|
||||
/**
|
||||
* 关注默认回复
|
||||
*/
|
||||
public function subscribe() {
|
||||
public function subscribe()
|
||||
{
|
||||
$this->assign('title', '编辑默认回复');
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
@ -126,7 +136,8 @@ class Keys extends BasicAdmin {
|
||||
* 关注默认回复表单处理
|
||||
* @param $data
|
||||
*/
|
||||
protected function _subscribe_form_filter(&$data) {
|
||||
protected function _subscribe_form_filter(&$data)
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
$data = Db::name($this->table)->where('keys', 'subscribe')->find();
|
||||
}
|
||||
@ -137,7 +148,8 @@ class Keys extends BasicAdmin {
|
||||
/**
|
||||
* 无配置默认回复
|
||||
*/
|
||||
public function defaults() {
|
||||
public function defaults()
|
||||
{
|
||||
$this->assign('title', '编辑无配置默认回复');
|
||||
return $this->_form($this->table, 'form');
|
||||
}
|
||||
@ -147,7 +159,8 @@ class Keys extends BasicAdmin {
|
||||
* 无配置默认回复表单处理
|
||||
* @param $data
|
||||
*/
|
||||
protected function _defaults_form_filter(&$data) {
|
||||
protected function _defaults_form_filter(&$data)
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
$data = Db::name($this->table)->where('keys', 'default')->find();
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/27 14:43
|
||||
*/
|
||||
class Menu extends BasicAdmin {
|
||||
class Menu extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 指定当前页面标题
|
||||
@ -45,20 +46,21 @@ class Menu extends BasicAdmin {
|
||||
* @var array
|
||||
*/
|
||||
protected $menu_type = array(
|
||||
'view' => '跳转URL',
|
||||
'click' => '点击推事件',
|
||||
'scancode_push' => '扫码推事件',
|
||||
'scancode_waitmsg' => '扫码推事件且弹出“消息接收中”提示框',
|
||||
'pic_sysphoto' => '弹出系统拍照发图',
|
||||
'view' => '跳转URL',
|
||||
'click' => '点击推事件',
|
||||
'scancode_push' => '扫码推事件',
|
||||
'scancode_waitmsg' => '扫码推事件且弹出“消息接收中”提示框',
|
||||
'pic_sysphoto' => '弹出系统拍照发图',
|
||||
'pic_photo_or_album' => '弹出拍照或者相册发图',
|
||||
'pic_weixin' => '弹出微信相册发图器',
|
||||
'location_select' => '弹出地理位置选择器',
|
||||
'pic_weixin' => '弹出微信相册发图器',
|
||||
'location_select' => '弹出地理位置选择器',
|
||||
);
|
||||
|
||||
/**
|
||||
* 显示列表操作
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
return parent::_list(Db::name($this->table), false, true);
|
||||
}
|
||||
|
||||
@ -66,14 +68,16 @@ class Menu extends BasicAdmin {
|
||||
* 列表数据处理
|
||||
* @param array $data
|
||||
*/
|
||||
protected function _index_data_filter(&$data) {
|
||||
protected function _index_data_filter(&$data)
|
||||
{
|
||||
$data = ToolsService::arr2tree($data, 'index', 'pindex');
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信菜单编辑
|
||||
*/
|
||||
public function edit() {
|
||||
public function edit()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
!isset($post['data']) && $this->error('访问出错,请稍候再试!');
|
||||
@ -103,7 +107,8 @@ class Menu extends BasicAdmin {
|
||||
/**
|
||||
* 取消菜单
|
||||
*/
|
||||
public function cancel() {
|
||||
public function cancel()
|
||||
{
|
||||
$wehcat = &load_wechat('Menu');
|
||||
if (false !== $wehcat->deleteMenu()) {
|
||||
$this->success('菜单取消成功,重新关注可立即生效!', '');
|
||||
@ -114,12 +119,13 @@ class Menu extends BasicAdmin {
|
||||
/**
|
||||
* 菜单推送
|
||||
*/
|
||||
protected function _push() {
|
||||
protected function _push()
|
||||
{
|
||||
$result = Db::name($this->table)
|
||||
->field('id,index,pindex,name,type,content')
|
||||
->where('status', '1')
|
||||
->order('sort ASC,id ASC')
|
||||
->select();
|
||||
->field('id,index,pindex,name,type,content')
|
||||
->where('status', '1')
|
||||
->order('sort ASC,id ASC')
|
||||
->select();
|
||||
foreach ($result as &$row) {
|
||||
empty($row['content']) && $row['content'] = uniqid();
|
||||
switch ($row['type']) {
|
||||
|
@ -29,7 +29,8 @@ use think\response\View;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/27 14:43
|
||||
*/
|
||||
class News extends BasicAdmin {
|
||||
class News extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置默认操作表
|
||||
@ -40,7 +41,8 @@ class News extends BasicAdmin {
|
||||
/**
|
||||
* 图文列表
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$this->assign('title', '图文列表');
|
||||
$db = Db::name($this->table)->where('is_deleted', '0')->order('id desc');
|
||||
return parent::_list($db);
|
||||
@ -50,7 +52,8 @@ class News extends BasicAdmin {
|
||||
* 图文选择器
|
||||
* @return string
|
||||
*/
|
||||
public function select() {
|
||||
public function select()
|
||||
{
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
@ -58,7 +61,8 @@ class News extends BasicAdmin {
|
||||
* 媒体资源显示
|
||||
* @return array
|
||||
*/
|
||||
public function image() {
|
||||
public function image()
|
||||
{
|
||||
$_GET['rows'] = 18;
|
||||
$this->assign('field', $this->request->get('field', 'local_url'));
|
||||
return $this->_list(Db::name('WechatNewsMedia')->where('type', 'image'));
|
||||
@ -68,7 +72,8 @@ class News extends BasicAdmin {
|
||||
* 图文列表数据处理
|
||||
* @param $data
|
||||
*/
|
||||
protected function _index_data_filter(&$data) {
|
||||
protected function _index_data_filter(&$data)
|
||||
{
|
||||
foreach ($data as &$vo) {
|
||||
$vo = WechatService::getNewsById($vo['id']);
|
||||
}
|
||||
@ -78,7 +83,8 @@ class News extends BasicAdmin {
|
||||
* 图文列表数据处理
|
||||
* @param $data
|
||||
*/
|
||||
protected function _select_data_filter(&$data) {
|
||||
protected function _select_data_filter(&$data)
|
||||
{
|
||||
foreach ($data as &$vo) {
|
||||
$vo = WechatService::getNewsById($vo['id']);
|
||||
}
|
||||
@ -88,7 +94,8 @@ class News extends BasicAdmin {
|
||||
* 添加图文
|
||||
* @return View
|
||||
*/
|
||||
public function add() {
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
return view('form', ['title' => '新建图文']);
|
||||
}
|
||||
@ -108,7 +115,8 @@ class News extends BasicAdmin {
|
||||
* 编辑图文
|
||||
* @return View
|
||||
*/
|
||||
public function edit() {
|
||||
public function edit()
|
||||
{
|
||||
$id = $this->request->get('id', '');
|
||||
if ($this->request->isGet()) {
|
||||
empty($id) && $this->error('参数错误,请稍候再试!');
|
||||
@ -131,7 +139,8 @@ class News extends BasicAdmin {
|
||||
* @param array $ids
|
||||
* @return string
|
||||
*/
|
||||
protected function _apply_news_article($data, $ids = []) {
|
||||
protected function _apply_news_article($data, $ids = [])
|
||||
{
|
||||
foreach ($data as &$vo) {
|
||||
$vo['create_by'] = session('user.id');
|
||||
$vo['create_at'] = date('Y-m-d H:i:s');
|
||||
@ -152,7 +161,8 @@ class News extends BasicAdmin {
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
public function del() {
|
||||
public function del()
|
||||
{
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("图文删除成功!", '');
|
||||
}
|
||||
@ -163,7 +173,8 @@ class News extends BasicAdmin {
|
||||
* 推荐图文
|
||||
* @return array|void
|
||||
*/
|
||||
public function push() {
|
||||
public function push()
|
||||
{
|
||||
# 获取将要推送的粉丝列表
|
||||
switch (strtolower($this->request->get('action', ''))) {
|
||||
case 'getuser':
|
||||
@ -182,8 +193,8 @@ class News extends BasicAdmin {
|
||||
if ($this->request->isGet()) {
|
||||
$fans_tags = Db::name('WechatFansTags')->select();
|
||||
array_unshift($fans_tags, [
|
||||
'id' => 0,
|
||||
'name' => '全部',
|
||||
'id' => 0,
|
||||
'name' => '全部',
|
||||
'count' => Db::name('WechatFans')->where('subscribe', '1')->count(),
|
||||
]);
|
||||
return view('push', ['vo' => $newsinfo, 'fans_tags' => $fans_tags]);
|
||||
@ -218,7 +229,8 @@ class News extends BasicAdmin {
|
||||
* @param type $newsinfo
|
||||
* @return boolean
|
||||
*/
|
||||
private function _uploadWechatNews(&$newsinfo) {
|
||||
private function _uploadWechatNews(&$newsinfo)
|
||||
{
|
||||
foreach ($newsinfo['articles'] as &$article) {
|
||||
$article['thumb_media_id'] = WechatService::uploadForeverMedia($article['local_url']);
|
||||
$article['content'] = preg_replace_callback("/<img(.*?)src=['\"](.*?)['\"](.*?)\/?>/i", function ($matches) {
|
||||
@ -226,7 +238,7 @@ class News extends BasicAdmin {
|
||||
return "<img{$matches[1]}src=\"{$src}\"{$matches[3]}/>";
|
||||
}, htmlspecialchars_decode($article['content']));
|
||||
}
|
||||
$wechat = & load_wechat('media');
|
||||
$wechat = &load_wechat('media');
|
||||
// 如果已经上传过,先删除之前的历史记录
|
||||
!empty($newsinfo['media_id']) && $wechat->delForeverMedia($newsinfo['media_id']);
|
||||
// 上传图文到微信服务器
|
||||
|
@ -25,9 +25,11 @@ use think\Log;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/04/05 14:02
|
||||
*/
|
||||
class Notify extends Controller {
|
||||
class Notify extends Controller
|
||||
{
|
||||
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
// 实例支付接口
|
||||
$pay = &load_wechat('Pay');
|
||||
|
||||
@ -43,7 +45,7 @@ class Notify extends Controller {
|
||||
//支付通知数据获取成功
|
||||
if ($notifyInfo['result_code'] == 'SUCCESS' && $notifyInfo['return_code'] == 'SUCCESS') {
|
||||
// 记录支付通知数据
|
||||
if(!Db::name('WechatPayNotify')->insert($notifyInfo)){
|
||||
if (!Db::name('WechatPayNotify')->insert($notifyInfo)) {
|
||||
$pay->replyXml(['return_code' => 'ERROR', 'return_msg' => '系统记录微信通知时发生异常!']);
|
||||
}
|
||||
$prepayMap = ['out_trade_no' => $notifyInfo['out_trade_no']];
|
||||
|
@ -19,13 +19,15 @@ use service\WechatService;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
|
||||
class Review extends Controller {
|
||||
class Review extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示手机预览
|
||||
* @return string
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$content = str_replace("\n", "<br>", $this->request->get('content', '')); // 内容
|
||||
$type = $this->request->get('type', 'text'); // 类型
|
||||
@ -49,7 +51,8 @@ class Review extends Controller {
|
||||
/**
|
||||
* 微信图片显示
|
||||
*/
|
||||
public function img() {
|
||||
public function img()
|
||||
{
|
||||
$url = $this->request->get('url', '');
|
||||
$filename = FileService::getFileName($url, 'jpg', 'tmp/');
|
||||
if (false === ($img = FileService::getFileUrl($filename))) {
|
||||
|
@ -27,7 +27,8 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/27 14:43
|
||||
*/
|
||||
class Tags extends BasicAdmin {
|
||||
class Tags extends BasicAdmin
|
||||
{
|
||||
|
||||
/**
|
||||
* 定义当前默认数据表
|
||||
@ -39,7 +40,8 @@ class Tags extends BasicAdmin {
|
||||
* 显示粉丝标签列表
|
||||
* @return array|string
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
$this->title = '微信粉丝标签管理';
|
||||
$get = $this->request->get();
|
||||
$db = Db::name($this->table)->order('id asc');
|
||||
@ -54,14 +56,15 @@ class Tags extends BasicAdmin {
|
||||
/**
|
||||
* 添加粉丝标签
|
||||
*/
|
||||
public function add() {
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
return parent::_form($this->table, 'form', 'id');
|
||||
}
|
||||
$name = $this->request->post('name', '');
|
||||
empty($name) && $this->error('粉丝标签名不能为空!');
|
||||
(Db::name($this->table)->where('name', $name)->count() > 0) && $this->error('粉丝标签标签名已经存在, 请使用其它标签名!');
|
||||
$wechat = & load_wechat('User');
|
||||
$wechat = &load_wechat('User');
|
||||
if (false === ($result = $wechat->createTags($name)) && isset($result['tag'])) {
|
||||
$this->error("添加粉丝标签失败. {$wechat->errMsg}[{$wechat->errCode}]");
|
||||
}
|
||||
@ -73,7 +76,8 @@ class Tags extends BasicAdmin {
|
||||
/**
|
||||
* 编辑粉丝标签
|
||||
*/
|
||||
public function edit() {
|
||||
public function edit()
|
||||
{
|
||||
// 显示编辑界面
|
||||
if ($this->request->isGet()) {
|
||||
return parent::_form($this->table, 'form', 'id');
|
||||
@ -98,7 +102,8 @@ class Tags extends BasicAdmin {
|
||||
/**
|
||||
* 同步粉丝标签列表
|
||||
*/
|
||||
public function sync() {
|
||||
public function sync()
|
||||
{
|
||||
Db::name($this->table)->where('1=1')->delete();
|
||||
if (WechatService::syncFansTags()) {
|
||||
LogService::write('微信管理', '同步全部微信粉丝标签成功');
|
||||
|
@ -24,7 +24,8 @@ use think\Db;
|
||||
* Class BasicAdmin
|
||||
* @package controller
|
||||
*/
|
||||
class BasicAdmin extends Controller {
|
||||
class BasicAdmin extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 页面标题
|
||||
@ -59,13 +60,14 @@ class BasicAdmin extends Controller {
|
||||
* @param array $extendData 扩展数据
|
||||
* @return array|string
|
||||
*/
|
||||
protected function _form($dbQuery = null, $tplFile = '', $pkField = '', $where = [], $extendData = []) {
|
||||
protected function _form($dbQuery = null, $tplFile = '', $pkField = '', $where = [], $extendData = [])
|
||||
{
|
||||
$db = is_null($dbQuery) ? Db::name($this->table) : (is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery);
|
||||
$pk = empty($pkField) ? ($db->getPk() ? $db->getPk() : 'id') : $pkField;
|
||||
$pkValue = $this->request->request($pk, isset($where[$pk]) ? $where[$pk] : (isset($extendData[$pk]) ? $extendData[$pk] : null));
|
||||
// 非POST请求, 获取数据并显示表单页面
|
||||
if (!$this->request->isPost()) {
|
||||
$vo = ($pkValue !== null) ? array_merge((array) $db->where($pk, $pkValue)->where($where)->find(), $extendData) : $extendData;
|
||||
$vo = ($pkValue !== null) ? array_merge((array)$db->where($pk, $pkValue)->where($where)->find(), $extendData) : $extendData;
|
||||
if (false !== $this->_callback('_form_filter', $vo)) {
|
||||
empty($this->title) || $this->assign('title', $this->title);
|
||||
return $this->fetch($tplFile, ['vo' => $vo]);
|
||||
@ -90,7 +92,8 @@ class BasicAdmin extends Controller {
|
||||
* @param bool $total 总记录数
|
||||
* @return array|string
|
||||
*/
|
||||
protected function _list($dbQuery = null, $isPage = true, $isDisplay = true, $total = false) {
|
||||
protected function _list($dbQuery = null, $isPage = true, $isDisplay = true, $total = false)
|
||||
{
|
||||
$db = is_null($dbQuery) ? Db::name($this->table) : (is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery);
|
||||
// 列表排序默认处理
|
||||
if ($this->request->isPost() && $this->request->post('action') === 'resort') {
|
||||
@ -131,7 +134,8 @@ class BasicAdmin extends Controller {
|
||||
* @param array|bool $data
|
||||
* @return bool
|
||||
*/
|
||||
protected function _callback($method, &$data) {
|
||||
protected function _callback($method, &$data)
|
||||
{
|
||||
foreach ([$method, "_" . $this->request->action() . "{$method}"] as $_method) {
|
||||
if (method_exists($this, $_method) && false === $this->$_method($data)) {
|
||||
return false;
|
||||
|
@ -24,7 +24,8 @@ use think\Response;
|
||||
* Class BasicApi
|
||||
* @package controller
|
||||
*/
|
||||
class BasicApi {
|
||||
class BasicApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 访问请求对象
|
||||
@ -42,7 +43,8 @@ class BasicApi {
|
||||
* 基础接口SDK
|
||||
* @param Request|null $request
|
||||
*/
|
||||
public function __construct(Request $request = null) {
|
||||
public function __construct(Request $request = null)
|
||||
{
|
||||
// CORS 跨域 Options 检测响应
|
||||
ToolsService::corsOptionsHandler();
|
||||
// 获取当前 Request 对象
|
||||
@ -66,7 +68,8 @@ class BasicApi {
|
||||
* @param string $type 返回类型 JSON XML
|
||||
* @return Response
|
||||
*/
|
||||
public function response($msg, $code = 'SUCCESS', $data = [], $type = 'json') {
|
||||
public function response($msg, $code = 'SUCCESS', $data = [], $type = 'json')
|
||||
{
|
||||
$result = ['msg' => $msg, 'code' => $code, 'data' => $data, 'token' => $this->token, 'dataType' => strtolower($type)];
|
||||
return Response::create($result, $type)->header(ToolsService::corsRequestHander())->code(200);
|
||||
}
|
||||
@ -78,7 +81,8 @@ class BasicApi {
|
||||
* @param int|null $expire 有效时间 0为永久
|
||||
* @return bool
|
||||
*/
|
||||
public function setCache($name, $value, $expire = null) {
|
||||
public function setCache($name, $value, $expire = null)
|
||||
{
|
||||
return Cache::set("{$this->token}_{$name}", $value, $expire);
|
||||
}
|
||||
|
||||
@ -88,7 +92,8 @@ class BasicApi {
|
||||
* @param mixed $default 默认值
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCache($name, $default = false) {
|
||||
public function getCache($name, $default = false)
|
||||
{
|
||||
return Cache::get("{$this->token}_{$name}", $default);
|
||||
}
|
||||
|
||||
@ -97,7 +102,8 @@ class BasicApi {
|
||||
* @param string $name 缓存标识
|
||||
* @return bool
|
||||
*/
|
||||
public function delCache($name) {
|
||||
public function delCache($name)
|
||||
{
|
||||
return Cache::rm("{$this->token}_{$name}");
|
||||
}
|
||||
|
||||
@ -105,7 +111,8 @@ class BasicApi {
|
||||
* API接口调度
|
||||
* @return Response
|
||||
*/
|
||||
public function _empty() {
|
||||
public function _empty()
|
||||
{
|
||||
list($module, $controller, $action, $method) = explode('/', $this->request->path() . '///');
|
||||
if (!empty($module) && !empty($controller) && !empty($action) && !empty($method)) {
|
||||
$action = ucfirst($action);
|
||||
|
@ -23,7 +23,8 @@ use think\Log;
|
||||
* Class BasicWechat
|
||||
* @package controller
|
||||
*/
|
||||
class BasicWechat extends Controller {
|
||||
class BasicWechat extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 当前粉丝用户OPENID
|
||||
@ -52,7 +53,8 @@ class BasicWechat extends Controller {
|
||||
/**
|
||||
* 初始化方法
|
||||
*/
|
||||
public function _initialize() {
|
||||
public function _initialize()
|
||||
{
|
||||
// 当前完整URL地址
|
||||
$this->url = $this->request->url(true);
|
||||
// 网页授权,并获粉丝信息
|
||||
@ -66,7 +68,8 @@ class BasicWechat extends Controller {
|
||||
* @param bool $fullMode 获取完整
|
||||
* @return string
|
||||
*/
|
||||
protected function oAuth($fullMode = true) {
|
||||
protected function oAuth($fullMode = true)
|
||||
{
|
||||
// 本地开发调试用户 openid
|
||||
if (in_array($this->request->host(), ['127.0.0.1', 'localhost'])) {
|
||||
session('openid', 'oBWB3wWVNujb-PJlmPmxC5CBTNF0');
|
||||
|
@ -26,7 +26,8 @@ use think\View;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/05/12 11:59
|
||||
*/
|
||||
class AccessAuth {
|
||||
class AccessAuth
|
||||
{
|
||||
|
||||
/**
|
||||
* 当前请求对象
|
||||
@ -38,7 +39,8 @@ class AccessAuth {
|
||||
* 行为入口
|
||||
* @param $params
|
||||
*/
|
||||
public function run(&$params) {
|
||||
public function run(&$params)
|
||||
{
|
||||
$this->request = Request::instance();
|
||||
list($module, $controller, $action) = [$this->request->module(), $this->request->controller(), $this->request->action()];
|
||||
$vars = get_class_vars(config('app_namespace') . "\\{$module}\\controller\\{$controller}");
|
||||
|
@ -23,7 +23,8 @@ use think\Request;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/04/25 11:59
|
||||
*/
|
||||
class FilterView {
|
||||
class FilterView
|
||||
{
|
||||
|
||||
/**
|
||||
* 当前请求对象
|
||||
@ -35,12 +36,13 @@ class FilterView {
|
||||
* 行为入口
|
||||
* @param $params
|
||||
*/
|
||||
public function run(&$params) {
|
||||
public function run(&$params)
|
||||
{
|
||||
$this->request = Request::instance();
|
||||
$appRoot = $this->request->root(true);
|
||||
$replace = [
|
||||
'__APP__' => $appRoot,
|
||||
'__SELF__' => $this->request->url(true),
|
||||
'__APP__' => $appRoot,
|
||||
'__SELF__' => $this->request->url(true),
|
||||
'__PUBLIC__' => strpos($appRoot, EXT) ? ltrim(dirname($appRoot), DS) : $appRoot,
|
||||
];
|
||||
$params = str_replace(array_keys($replace), array_values($replace), $params);
|
||||
@ -51,7 +53,8 @@ class FilterView {
|
||||
* 百度统计实现代码
|
||||
* @param $params
|
||||
*/
|
||||
public function baidu(&$params) {
|
||||
public function baidu(&$params)
|
||||
{
|
||||
if (($key = sysconf('tongji_baidu_key'))) {
|
||||
$script = <<<SCRIPT
|
||||
<script>
|
||||
|
@ -24,7 +24,8 @@ use think\Request;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/22 15:32
|
||||
*/
|
||||
class DataService {
|
||||
class DataService
|
||||
{
|
||||
|
||||
/**
|
||||
* 删除指定序号
|
||||
@ -32,7 +33,8 @@ class DataService {
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
public static function deleteSequence($sequence, $type = 'SYSTEM') {
|
||||
public static function deleteSequence($sequence, $type = 'SYSTEM')
|
||||
{
|
||||
$data = ['sequence' => $sequence, 'type' => strtoupper($type)];
|
||||
return Db::name('SystemSequence')->where($data)->delete();
|
||||
}
|
||||
@ -43,7 +45,8 @@ class DataService {
|
||||
* @param string $type 序号顾类型
|
||||
* @return string
|
||||
*/
|
||||
public static function createSequence($length = 10, $type = 'SYSTEM') {
|
||||
public static function createSequence($length = 10, $type = 'SYSTEM')
|
||||
{
|
||||
$times = 0;
|
||||
while ($times++ < 10) {
|
||||
$i = 0;
|
||||
@ -69,7 +72,8 @@ class DataService {
|
||||
* @param array $where 其它的where条件
|
||||
* @return bool
|
||||
*/
|
||||
public static function save($dbQuery, $data, $key = 'id', $where = []) {
|
||||
public static function save($dbQuery, $data, $key = 'id', $where = [])
|
||||
{
|
||||
$db = is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery;
|
||||
$where[$key] = isset($data[$key]) ? $data[$key] : '';
|
||||
if ($db->where($where)->count() > 0) {
|
||||
@ -84,7 +88,8 @@ class DataService {
|
||||
* @param array $where 额外查询条件
|
||||
* @return bool|null
|
||||
*/
|
||||
public static function update(&$dbQuery, $where = []) {
|
||||
public static function update(&$dbQuery, $where = [])
|
||||
{
|
||||
$request = Request::instance();
|
||||
$db = is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery;
|
||||
$ids = explode(',', $request->post('id', ''));
|
||||
|
@ -21,7 +21,8 @@ namespace service;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/15 15:17
|
||||
*/
|
||||
class ExpressService {
|
||||
class ExpressService
|
||||
{
|
||||
|
||||
const APPID = '1232779';
|
||||
const APPKEY = 'ac45f461-8c1a-4518-87b1-bb8e835a2f9d';
|
||||
@ -33,14 +34,15 @@ class ExpressService {
|
||||
* @param $LogisticCode string 物流单号
|
||||
* @return string array 轨迹数据
|
||||
*/
|
||||
public static function line($ShipperCode, $LogisticCode) {
|
||||
public static function line($ShipperCode, $LogisticCode)
|
||||
{
|
||||
$sendData = json_encode(array('ShipperCode' => $ShipperCode, 'LogisticCode' => $LogisticCode), JSON_UNESCAPED_UNICODE);
|
||||
$data = array(
|
||||
'RequestData' => $sendData,
|
||||
'EBusinessID' => self::APPID,
|
||||
'RequestType' => '1002',
|
||||
'DataType' => 2,
|
||||
'DataSign' => base64_encode(md5($sendData . self::APPKEY)),
|
||||
'DataType' => 2,
|
||||
'DataSign' => base64_encode(md5($sendData . self::APPKEY)),
|
||||
);
|
||||
$result = HttpService::post(self::APIURI, $data);
|
||||
!($resultJson = json_decode($result, true)) && die(var_export($result));
|
||||
@ -52,7 +54,8 @@ class ExpressService {
|
||||
* @param $result 结果处理
|
||||
* @return array 通用的结果集 array('result' => 'success或者fail','data' => array( array('time' => '时间','info' => '地点'),......),'reason' => '失败原因')
|
||||
*/
|
||||
public static function response($result) {
|
||||
public static function response($result)
|
||||
{
|
||||
$status = "fail";
|
||||
$data = array();
|
||||
$message = "此单号无跟踪记录";
|
||||
|
@ -30,7 +30,8 @@ use think\Log;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/15 15:17
|
||||
*/
|
||||
class FileService {
|
||||
class FileService
|
||||
{
|
||||
|
||||
/**
|
||||
* 根据文件后缀获取文件MINE
|
||||
@ -38,7 +39,8 @@ class FileService {
|
||||
* @param array $mine 文件后缀MINE信息
|
||||
* @return string
|
||||
*/
|
||||
public static function getFileMine($exts, $mine = []) {
|
||||
public static function getFileMine($exts, $mine = [])
|
||||
{
|
||||
$mines = Config::get('mines');
|
||||
foreach (is_string($exts) ? explode(',', $exts) : $exts as $_e) {
|
||||
if (isset($mines[strtolower($_e)])) {
|
||||
@ -55,7 +57,8 @@ class FileService {
|
||||
* @param string|null $storage
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function getFileUrl($filename, $storage = null) {
|
||||
public static function getFileUrl($filename, $storage = null)
|
||||
{
|
||||
if (self::hasFile($filename, $storage) === false) {
|
||||
return false;
|
||||
}
|
||||
@ -74,7 +77,8 @@ class FileService {
|
||||
* 根据配置获取到七牛云文件上传目标地址
|
||||
* @return string
|
||||
*/
|
||||
public static function getUploadLocalUrl() {
|
||||
public static function getUploadLocalUrl()
|
||||
{
|
||||
return url('@admin/plugs/upload');
|
||||
}
|
||||
|
||||
@ -83,7 +87,8 @@ class FileService {
|
||||
* @param bool $isClient
|
||||
* @return string
|
||||
*/
|
||||
public static function getUploadQiniuUrl($isClient = true) {
|
||||
public static function getUploadQiniuUrl($isClient = true)
|
||||
{
|
||||
$region = sysconf('storage_qiniu_region');
|
||||
$isHttps = !!sysconf('storage_qiniu_is_https');
|
||||
switch ($region) {
|
||||
@ -115,7 +120,8 @@ class FileService {
|
||||
* 获取AliOSS上传地址
|
||||
* @return string
|
||||
*/
|
||||
public static function getUploadOssUrl() {
|
||||
public static function getUploadOssUrl()
|
||||
{
|
||||
return (request()->isSsl() ? 'https' : 'http') . '://' . sysconf('storage_oss_domain');
|
||||
}
|
||||
|
||||
@ -123,7 +129,8 @@ class FileService {
|
||||
* 获取服务器URL前缀
|
||||
* @return string
|
||||
*/
|
||||
public static function getBaseUriLocal() {
|
||||
public static function getBaseUriLocal()
|
||||
{
|
||||
$request = request();
|
||||
$base = $request->root();
|
||||
$root = strpos($base, '.') ? ltrim(dirname($base), DS) : $base;
|
||||
@ -137,7 +144,8 @@ class FileService {
|
||||
* 获取七牛云URL前缀
|
||||
* @return string
|
||||
*/
|
||||
public static function getBaseUriQiniu() {
|
||||
public static function getBaseUriQiniu()
|
||||
{
|
||||
return (sysconf('storage_qiniu_is_https') ? 'https' : 'http') . '://' . sysconf('storage_qiniu_domain') . '/';
|
||||
}
|
||||
|
||||
@ -145,7 +153,8 @@ class FileService {
|
||||
* 获取AliOss URL前缀
|
||||
* @return string
|
||||
*/
|
||||
public static function getBaseUriOss() {
|
||||
public static function getBaseUriOss()
|
||||
{
|
||||
return (sysconf('storage_oss_is_https') ? 'https' : 'http') . '://' . sysconf('storage_oss_domain') . '/';
|
||||
}
|
||||
|
||||
@ -156,7 +165,8 @@ class FileService {
|
||||
* @param string $pre 文件前缀
|
||||
* @return string
|
||||
*/
|
||||
public static function getFileName($source, $ext = '', $pre = '') {
|
||||
public static function getFileName($source, $ext = '', $pre = '')
|
||||
{
|
||||
return $pre . join('/', str_split(md5($source), 16)) . '.' . $ext;
|
||||
}
|
||||
|
||||
@ -166,7 +176,8 @@ class FileService {
|
||||
* @param string|null $storage
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasFile($filename, $storage = null) {
|
||||
public static function hasFile($filename, $storage = null)
|
||||
{
|
||||
switch (empty($storage) ? sysconf('storage_type') : $storage) {
|
||||
case 'local':
|
||||
return file_exists(ROOT_PATH . 'static/upload/' . $filename);
|
||||
@ -188,7 +199,8 @@ class FileService {
|
||||
* @param string|null $storage
|
||||
* @return string|null
|
||||
*/
|
||||
public static function readFile($filename, $storage = null) {
|
||||
public static function readFile($filename, $storage = null)
|
||||
{
|
||||
switch (empty($storage) ? sysconf('storage_type') : $storage) {
|
||||
case 'local':
|
||||
$filepath = ROOT_PATH . 'static/upload/' . $filename;
|
||||
@ -213,7 +225,8 @@ class FileService {
|
||||
* @param string|null $file_storage
|
||||
* @return array|false
|
||||
*/
|
||||
public static function save($filename, $content, $file_storage = null) {
|
||||
public static function save($filename, $content, $file_storage = null)
|
||||
{
|
||||
$type = empty($file_storage) ? sysconf('storage_type') : $file_storage;
|
||||
if (!method_exists(__CLASS__, $type)) {
|
||||
Log::error("保存存储失败,调用{$type}存储引擎不存在!");
|
||||
@ -228,7 +241,8 @@ class FileService {
|
||||
* @param string $content
|
||||
* @return array|null
|
||||
*/
|
||||
public static function local($filename, $content) {
|
||||
public static function local($filename, $content)
|
||||
{
|
||||
try {
|
||||
$filepath = ROOT_PATH . 'static/upload/' . $filename;
|
||||
!file_exists(dirname($filepath)) && mkdir(dirname($filepath), '0755', true);
|
||||
@ -248,7 +262,8 @@ class FileService {
|
||||
* @param string $content
|
||||
* @return array|null
|
||||
*/
|
||||
public static function qiniu($filename, $content) {
|
||||
public static function qiniu($filename, $content)
|
||||
{
|
||||
$auth = new Auth(sysconf('storage_qiniu_access_key'), sysconf('storage_qiniu_secret_key'));
|
||||
$token = $auth->uploadToken(sysconf('storage_qiniu_bucket'));
|
||||
$uploadMgr = new UploadManager();
|
||||
@ -268,7 +283,8 @@ class FileService {
|
||||
* @param string $content
|
||||
* @return array|null
|
||||
*/
|
||||
public static function oss($filename, $content) {
|
||||
public static function oss($filename, $content)
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient(sysconf('storage_oss_keyid'), sysconf('storage_oss_secret'), self::getBaseUriOss(), true);
|
||||
$result = $ossClient->putObject(sysconf('storage_oss_bucket'), $filename, $content);
|
||||
@ -285,7 +301,8 @@ class FileService {
|
||||
* @param bool $isForce 是否强制重新下载文件
|
||||
* @return array|null;
|
||||
*/
|
||||
public static function download($url, $isForce = false) {
|
||||
public static function download($url, $isForce = false)
|
||||
{
|
||||
try {
|
||||
$filename = self::getFileName($url, strtolower(pathinfo($url, 4)), 'download/');
|
||||
if (false === $isForce && ($siteUrl = self::getFileUrl($filename, 'local'))) {
|
||||
|
@ -23,7 +23,8 @@ use CURLFile;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/22 15:32
|
||||
*/
|
||||
class HttpService {
|
||||
class HttpService
|
||||
{
|
||||
|
||||
/**
|
||||
* HTTP GET 请求
|
||||
@ -33,7 +34,8 @@ class HttpService {
|
||||
* @param array $header 请求Header信息
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function get($url, $data = array(), $second = 30, $header = []) {
|
||||
public static function get($url, $data = array(), $second = 30, $header = [])
|
||||
{
|
||||
if (!empty($data)) {
|
||||
$url .= (stripos($url, '?') === false ? '?' : '&');
|
||||
$url .= (is_array($data) ? http_build_query($data) : $data);
|
||||
@ -58,7 +60,8 @@ class HttpService {
|
||||
* @param array $header 请求Header信息
|
||||
* @return bool|string
|
||||
*/
|
||||
static public function post($url, $data = [], $second = 30, $header = []) {
|
||||
static public function post($url, $data = [], $second = 30, $header = [])
|
||||
{
|
||||
self::_setUploadFile($data);
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $second);
|
||||
@ -80,7 +83,8 @@ class HttpService {
|
||||
* @param $curl
|
||||
* @param string $url
|
||||
*/
|
||||
private static function _setSsl(&$curl, $url) {
|
||||
private static function _setSsl(&$curl, $url)
|
||||
{
|
||||
if (stripos($url, "https") === 0) {
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
@ -93,7 +97,8 @@ class HttpService {
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
private static function _setUploadFile(&$data) {
|
||||
private static function _setUploadFile(&$data)
|
||||
{
|
||||
if (!is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -24,13 +24,15 @@ use think\Request;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/24 13:25
|
||||
*/
|
||||
class LogService {
|
||||
class LogService
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取数据操作对象
|
||||
* @return \think\db\Query
|
||||
*/
|
||||
protected static function db() {
|
||||
protected static function db()
|
||||
{
|
||||
return Db::name('SystemLog');
|
||||
}
|
||||
|
||||
@ -40,7 +42,8 @@ class LogService {
|
||||
* @param string $content
|
||||
* @return bool
|
||||
*/
|
||||
public static function write($action = '行为', $content = "内容描述") {
|
||||
public static function write($action = '行为', $content = "内容描述")
|
||||
{
|
||||
$request = Request::instance();
|
||||
$node = strtolower(join('/', [$request->module(), $request->controller(), $request->action()]));
|
||||
$data = ['ip' => $request->ip(), 'node' => $node, 'username' => session('user.username') . '', 'action' => $action, 'content' => $content];
|
||||
|
@ -23,13 +23,15 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/05/08 11:28
|
||||
*/
|
||||
class NodeService {
|
||||
class NodeService
|
||||
{
|
||||
|
||||
/**
|
||||
* 应用用户权限节点
|
||||
* @return bool
|
||||
*/
|
||||
public static function applyAuthNode() {
|
||||
public static function applyAuthNode()
|
||||
{
|
||||
cache('need_access_node', null);
|
||||
if (($userid = session('user.id'))) {
|
||||
session('user', Db::name('SystemUser')->where('id', $userid)->find());
|
||||
@ -50,7 +52,8 @@ class NodeService {
|
||||
* 获取授权节点
|
||||
* @return array
|
||||
*/
|
||||
public static function getAuthNode() {
|
||||
public static function getAuthNode()
|
||||
{
|
||||
$nodes = cache('need_access_node');
|
||||
if (empty($nodes)) {
|
||||
$nodes = Db::name('SystemNode')->where('is_auth', '1')->column('node');
|
||||
@ -64,7 +67,8 @@ class NodeService {
|
||||
* @param string $node 节点
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkAuthNode($node) {
|
||||
public static function checkAuthNode($node)
|
||||
{
|
||||
list($module, $controller, $action) = explode('/', str_replace(['?', '=', '&'], '/', $node . '///'));
|
||||
$auth_node = strtolower(trim("{$module}/{$controller}/{$action}", '/'));
|
||||
if (session('user.username') === 'admin' || stripos($node, 'admin/index') === 0) {
|
||||
@ -80,7 +84,8 @@ class NodeService {
|
||||
* 获取系统代码节点
|
||||
* @return array
|
||||
*/
|
||||
public static function get() {
|
||||
public static function get()
|
||||
{
|
||||
$alias = [];
|
||||
foreach (Db::name('SystemNode')->select() as $vo) {
|
||||
$alias["{$vo['node']}"] = $vo;
|
||||
@ -113,7 +118,8 @@ class NodeService {
|
||||
* @param array $nodes 额外数据
|
||||
* @return array
|
||||
*/
|
||||
public static function getNodeTree($path, $nodes = []) {
|
||||
public static function getNodeTree($path, $nodes = [])
|
||||
{
|
||||
foreach (self::_getFilePaths($path) as $vo) {
|
||||
if (!preg_match('|/(\w+)/controller/(\w+)|', str_replace(DS, '/', $vo), $matches) || count($matches) !== 3) {
|
||||
continue;
|
||||
@ -138,7 +144,8 @@ class NodeService {
|
||||
* @param string $ext 文件后缀
|
||||
* @return array
|
||||
*/
|
||||
private static function _getFilePaths($path, $data = [], $ext = 'php') {
|
||||
private static function _getFilePaths($path, $data = [], $ext = 'php')
|
||||
{
|
||||
foreach (scandir($path) as $dir) {
|
||||
if ($dir[0] === '.') {
|
||||
continue;
|
||||
|
@ -26,14 +26,16 @@ use think\Db;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2016/10/25 14:49
|
||||
*/
|
||||
class PayService {
|
||||
class PayService
|
||||
{
|
||||
|
||||
/**
|
||||
* 查询订单是否已经支付
|
||||
* @param string $order_no
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPay($order_no) {
|
||||
public static function isPay($order_no)
|
||||
{
|
||||
$map = ['order_no' => $order_no, 'is_pay' => '1'];
|
||||
return Db::name('WechatPayPrepayid')->where($map)->count() > 0;
|
||||
}
|
||||
@ -47,7 +49,8 @@ class PayService {
|
||||
* @param string $from 订单来源
|
||||
* @return false|string
|
||||
*/
|
||||
public static function createWechatPayQrc(WechatPay $pay, $order_no, $fee, $title, $from = 'wechat') {
|
||||
public static function createWechatPayQrc(WechatPay $pay, $order_no, $fee, $title, $from = 'wechat')
|
||||
{
|
||||
$prepayid = self::createWechatPrepayid($pay, null, $order_no, $fee, $title, 'NATIVE', $from);
|
||||
if ($prepayid === false) {
|
||||
return false;
|
||||
@ -71,7 +74,8 @@ class PayService {
|
||||
* @param string $title 订单标题
|
||||
* @return bool|array
|
||||
*/
|
||||
public static function createWechatPayJsPicker(WechatPay $pay, $openid, $order_no, $fee, $title) {
|
||||
public static function createWechatPayJsPicker(WechatPay $pay, $openid, $order_no, $fee, $title)
|
||||
{
|
||||
if (($prepayid = self::createWechatPrepayid($pay, $openid, $order_no, $fee, $title, 'JSAPI')) === false) {
|
||||
return false;
|
||||
}
|
||||
@ -86,7 +90,8 @@ class PayService {
|
||||
* @param string|null $refund_no 退款订单号
|
||||
* @return bool
|
||||
*/
|
||||
public static function putWechatRefund(WechatPay $pay, $order_no, $fee = 0, $refund_no = NULL, $refund_account = '') {
|
||||
public static function putWechatRefund(WechatPay $pay, $order_no, $fee = 0, $refund_no = NULL, $refund_account = '')
|
||||
{
|
||||
$map = array('order_no' => $order_no, 'is_pay' => '1', 'appid' => $pay->appid);
|
||||
$notify = Db::name('WechatPayPrepayid')->where($map)->find();
|
||||
if (empty($notify)) {
|
||||
@ -116,7 +121,8 @@ class PayService {
|
||||
* @param string $from 订单来源
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function createWechatPrepayid(WechatPay $pay, $openid, $order_no, $fee, $title, $trade_type = 'JSAPI', $from = 'wechat') {
|
||||
public static function createWechatPrepayid(WechatPay $pay, $openid, $order_no, $fee, $title, $trade_type = 'JSAPI', $from = 'wechat')
|
||||
{
|
||||
$map = ['order_no' => $order_no, 'is_pay' => '1', 'expires_in' => time(), 'appid' => $pay->appid, 'trade_type' => $trade_type];
|
||||
$where = 'appid=:appid and order_no=:order_no and (is_pay=:is_pay or expires_in>:expires_in) and trade_type=:trade_type';
|
||||
$prepayinfo = Db::name('WechatPayPrepayid')->where($where, $map)->find();
|
||||
|
@ -21,12 +21,14 @@ namespace service;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2016/10/25 14:49
|
||||
*/
|
||||
class ToolsService {
|
||||
class ToolsService
|
||||
{
|
||||
|
||||
/**
|
||||
* Cors Options 授权处理
|
||||
*/
|
||||
public static function corsOptionsHandler() {
|
||||
public static function corsOptionsHandler()
|
||||
{
|
||||
if (request()->isOptions()) {
|
||||
header('Access-Control-Allow-Origin:*');
|
||||
header('Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,token');
|
||||
@ -44,13 +46,14 @@ class ToolsService {
|
||||
* Cors Request Header信息
|
||||
* @return array
|
||||
*/
|
||||
public static function corsRequestHander() {
|
||||
public static function corsRequestHander()
|
||||
{
|
||||
return [
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
'Access-Control-Allow-Credentials' => true,
|
||||
'Access-Control-Allow-Methods' => 'GET,POST,OPTIONS',
|
||||
'X-Support' => 'service@cuci.cc',
|
||||
'X-Servers' => 'Guangzhou Cuci Technology Co. Ltd',
|
||||
'Access-Control-Allow-Methods' => 'GET,POST,OPTIONS',
|
||||
'X-Support' => 'service@cuci.cc',
|
||||
'X-Servers' => 'Guangzhou Cuci Technology Co. Ltd',
|
||||
];
|
||||
}
|
||||
|
||||
@ -59,10 +62,11 @@ class ToolsService {
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public static function emojiEncode($content) {
|
||||
return json_decode(preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i", function($str) {
|
||||
return addslashes($str[0]);
|
||||
}, json_encode($content)));
|
||||
public static function emojiEncode($content)
|
||||
{
|
||||
return json_decode(preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i", function ($str) {
|
||||
return addslashes($str[0]);
|
||||
}, json_encode($content)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,10 +74,11 @@ class ToolsService {
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public static function emojiDecode($content) {
|
||||
return json_decode(preg_replace_callback('/\\\\\\\\/i', function() {
|
||||
return '\\';
|
||||
}, json_encode($content)));
|
||||
public static function emojiDecode($content)
|
||||
{
|
||||
return json_decode(preg_replace_callback('/\\\\\\\\/i', function () {
|
||||
return '\\';
|
||||
}, json_encode($content)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,7 +89,8 @@ class ToolsService {
|
||||
* @param string $son 定义子数据Key
|
||||
* @return array
|
||||
*/
|
||||
public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub') {
|
||||
public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub')
|
||||
{
|
||||
$tree = $map = array();
|
||||
foreach ($list as $item) {
|
||||
$map[$item[$id]] = $item;
|
||||
@ -108,7 +114,8 @@ class ToolsService {
|
||||
* @param string $path
|
||||
* @return array
|
||||
*/
|
||||
public static function arr2table($list, $id = 'id', $pid = 'pid', $path = 'path', $ppath = '') {
|
||||
public static function arr2table($list, $id = 'id', $pid = 'pid', $path = 'path', $ppath = '')
|
||||
{
|
||||
$_array_tree = self::arr2tree($list, $id, $pid);
|
||||
$tree = array();
|
||||
foreach ($_array_tree as $_tree) {
|
||||
@ -122,7 +129,7 @@ class ToolsService {
|
||||
$tree[] = $_tree;
|
||||
if (!empty($sub)) {
|
||||
$sub_array = self::arr2table($sub, $id, $pid, $path, $_tree[$path]);
|
||||
$tree = array_merge($tree, (Array) $sub_array);
|
||||
$tree = array_merge($tree, (Array)$sub_array);
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
@ -136,7 +143,8 @@ class ToolsService {
|
||||
* @param string $pkey 父Key
|
||||
* @return array
|
||||
*/
|
||||
public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid') {
|
||||
public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid')
|
||||
{
|
||||
$ids = array(intval($id));
|
||||
foreach ($list as $vo) {
|
||||
if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) == intval($id)) {
|
||||
|
@ -24,7 +24,8 @@ use think\Log;
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @date 2017/03/22 15:32
|
||||
*/
|
||||
class WechatService {
|
||||
class WechatService
|
||||
{
|
||||
|
||||
/**
|
||||
* 通过图文ID读取图文信息
|
||||
@ -32,7 +33,8 @@ class WechatService {
|
||||
* @param array $where 额外的查询条件
|
||||
* @return array
|
||||
*/
|
||||
public static function getNewsById($id, $where = []) {
|
||||
public static function getNewsById($id, $where = [])
|
||||
{
|
||||
$data = Db::name('WechatNews')->where('id', $id)->where($where)->find();
|
||||
$article_ids = explode(',', $data['article_id']);
|
||||
$articles = Db::name('WechatNewsArticle')->where('id', 'in', $article_ids)->select();
|
||||
@ -54,7 +56,8 @@ class WechatService {
|
||||
* @param string $local_url
|
||||
* @return string|null
|
||||
*/
|
||||
public static function uploadImage($local_url) {
|
||||
public static function uploadImage($local_url)
|
||||
{
|
||||
# 检测文件上否已经上传过了
|
||||
if (($img = Db::name('WechatNewsImage')->where('md5', md5($local_url))->find()) && isset($img['media_url'])) {
|
||||
return $img['media_url'];
|
||||
@ -84,7 +87,8 @@ class WechatService {
|
||||
* @param array $video_info 视频信息
|
||||
* @return string|null
|
||||
*/
|
||||
public static function uploadForeverMedia($local_url = '', $type = 'image', $is_video = false, $video_info = array()) {
|
||||
public static function uploadForeverMedia($local_url = '', $type = 'image', $is_video = false, $video_info = array())
|
||||
{
|
||||
# 检测文件上否已经上传过了
|
||||
$wechat = &load_wechat('media');
|
||||
# 检查文件URL是否已经上传为永久素材
|
||||
@ -112,7 +116,8 @@ class WechatService {
|
||||
* 从微信服务器获取所有标签
|
||||
* @return bool
|
||||
*/
|
||||
public static function syncFansTags() {
|
||||
public static function syncFansTags()
|
||||
{
|
||||
$wechat = &load_wechat("User");
|
||||
if (($result = $wechat->getTags()) !== false) {
|
||||
$tags = $result['tags'];
|
||||
@ -132,7 +137,8 @@ class WechatService {
|
||||
* @param string $openid
|
||||
* @return bool
|
||||
*/
|
||||
public static function syncFansTagsByOpenid($openid) {
|
||||
public static function syncFansTagsByOpenid($openid)
|
||||
{
|
||||
$wechat = &load_wechat('User');
|
||||
$tagsid = $wechat->getUserTags($openid);
|
||||
if ($tagsid === false || !is_array($tagsid)) {
|
||||
@ -148,7 +154,8 @@ class WechatService {
|
||||
* @param string $appid
|
||||
* @return bool
|
||||
*/
|
||||
public static function setFansInfo($userInfo, $appid = '') {
|
||||
public static function setFansInfo($userInfo, $appid = '')
|
||||
{
|
||||
if (!empty($userInfo['subscribe_time'])) {
|
||||
$userInfo['subscribe_at'] = date('Y-m-d H:i:s', $userInfo['subscribe_time']);
|
||||
}
|
||||
@ -166,7 +173,8 @@ class WechatService {
|
||||
* @param string $appid 公众号appid
|
||||
* @return array|false
|
||||
*/
|
||||
public static function getFansInfo($openid, $appid = null) {
|
||||
public static function getFansInfo($openid, $appid = null)
|
||||
{
|
||||
$map = ['openid' => $openid];
|
||||
is_string($appid) && $map['appid'] = $appid;
|
||||
if (($fans = Db::name('WechatFans')->where($map)->find()) && isset($fans['nickname'])) {
|
||||
@ -180,7 +188,8 @@ class WechatService {
|
||||
* @param string $next_openid
|
||||
* @return bool
|
||||
*/
|
||||
public static function syncAllFans($next_openid = '') {
|
||||
public static function syncAllFans($next_openid = '')
|
||||
{
|
||||
$wechat = &load_wechat('User');
|
||||
if (false === ($result = $wechat->getUserList($next_openid)) || empty($result['data']['openid'])) {
|
||||
Log::error("获取粉丝列表失败, {$wechat->errMsg} [{$wechat->errCode}]");
|
||||
@ -209,7 +218,8 @@ class WechatService {
|
||||
* @param string $next_openid
|
||||
* @return bool
|
||||
*/
|
||||
public static function syncBlackFans($next_openid = '') {
|
||||
public static function syncBlackFans($next_openid = '')
|
||||
{
|
||||
$wechat = &load_wechat('User');
|
||||
$result = $wechat->getBacklist($next_openid);
|
||||
if ($result === false || (empty($result['data']['openid']))) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user