Initial project files: BESCMS full source
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php namespace Phpcmf\Model\Weixin;
|
||||
|
||||
// 权限验证
|
||||
class Auth extends \Phpcmf\Model
|
||||
{
|
||||
// 判断底部链接的显示权限
|
||||
public function is_bottom_auth($mid) {
|
||||
|
||||
if (SITE_ID == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 这里的程序体,有权限返回1,没权限返回0
|
||||
return 0;
|
||||
}
|
||||
// 判断右侧链接的显示权限
|
||||
public function is_link_auth($mid) {
|
||||
|
||||
// $mid 是当前模块的目录名称
|
||||
// 这里的程序体,显示返回1,不显示返回0
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function is_tpl_use($mid, $data) {
|
||||
|
||||
$config = \Phpcmf\Service::R(WRITEPATH.'config/weixin_sendtpl.php');
|
||||
if (!isset($config[$mid])) {
|
||||
return 0;
|
||||
} elseif (!isset($config[$mid]['use']) || !$config[$mid]['use']) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,516 @@
|
||||
<?php namespace Phpcmf\Model;
|
||||
|
||||
class User extends \Phpcmf\Model
|
||||
{
|
||||
public $openid;
|
||||
|
||||
// 获取微信表名
|
||||
public function wxtable($name) {
|
||||
return weixin_wxtable($name);
|
||||
}
|
||||
|
||||
// 绑定二维码
|
||||
public function qrcode_bang($member) {
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if ($rt['code']) {
|
||||
$access_token = $rt['msg'];
|
||||
$param = [
|
||||
'expire_seconds' => 2592000,
|
||||
'action_name' => 'QR_STR_SCENE',
|
||||
'action_info' => array(
|
||||
'scene' => array(
|
||||
'scene_str' => $member ? 'bang-'.(int)$member['id'] : 'login-'.md5(SYS_TIME.(string)$_SERVER['HTTP_USER_AGENT']),
|
||||
),
|
||||
)
|
||||
];
|
||||
|
||||
$rt = wx_post_https_json_data(
|
||||
'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $access_token,
|
||||
$param
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
return dr_return_data(0, 'qrcode '.$rt['msg']);
|
||||
}
|
||||
// 更新状态
|
||||
if ($member) {
|
||||
\Phpcmf\Service::M()->db->table('member_oauth')->where('uid', $member['id'])->where('oauth', 'wechat')->update([
|
||||
'access_token' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
$url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $rt['data']['ticket'];
|
||||
return dr_return_data(1, $url, $param);
|
||||
} else {
|
||||
return dr_return_data(0, 'access_token '.$rt['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取本地用户组信息
|
||||
public function get_group_data() {
|
||||
|
||||
$data = $this->db->table(weixin_wxtable('group'))->orderBy('id asc')->get()->getResultArray();
|
||||
if (!$data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rt = [];
|
||||
foreach ($data as $t) {
|
||||
$rt[$t['tag']] = $t;
|
||||
}
|
||||
|
||||
return $rt;
|
||||
}
|
||||
|
||||
// 服务器获取用户组
|
||||
public function down_group() {
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
$rt = wx_get_https_json_data('https://api.weixin.qq.com/cgi-bin/tags/get?access_token='.$rt['msg']);
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
if ($rt['data']['tags']) {
|
||||
\Phpcmf\Service::M()->table(weixin_wxtable('group'))->clear_all();
|
||||
foreach ($rt['data']['tags'] as $t) {
|
||||
$this->db->table(weixin_wxtable('group'))->insert([
|
||||
'tag' => $t['id'],
|
||||
'name' => $t['name'],
|
||||
'count' => $t['count'],
|
||||
'groupid' => 0,
|
||||
]);
|
||||
}
|
||||
return dr_return_data(1, 'ok');
|
||||
} else {
|
||||
return dr_return_data(0, '公众号上没有任何粉丝组');
|
||||
}
|
||||
}
|
||||
|
||||
// 获取同步规则值
|
||||
private function _get_menu_data($t) {
|
||||
|
||||
$data = array(
|
||||
'type' => $t['type'],
|
||||
'name' => dr_html2emoji($t['name']),
|
||||
);
|
||||
|
||||
//$root_url = \Phpcmf\Service::C()->site_info[1]['SITE_MURL'] ? \Phpcmf\Service::C()->site_info[1]['SITE_MURL'] : ROOT_URL;
|
||||
$root_url = ROOT_URL;
|
||||
|
||||
switch ($t['type']) {
|
||||
|
||||
case 'view':
|
||||
$data['url'] = $t['value'];
|
||||
break;
|
||||
|
||||
case 'login':
|
||||
$data['url'] = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.\Phpcmf\Service::C()->weixin['account']['appid'].'&redirect_uri='.urlencode($root_url.'index.php?s=weixin&c=member').'&response_type=code&scope=snsapi_base&state='.urlencode($t['value']).'#wechat_redirect';
|
||||
$data['type'] = 'view';
|
||||
break;
|
||||
|
||||
case 'article_view_limited':
|
||||
$data['article_id'] = $t['value'];
|
||||
break;
|
||||
|
||||
case 'miniprogram':
|
||||
$value = dr_string2array($t['value']);
|
||||
$data['appid'] = $value['appid'];
|
||||
$data['pagepath'] = $value['path'];
|
||||
$data['url'] = $value['url'];
|
||||
break;
|
||||
|
||||
default:
|
||||
$data['key'] = $t['value'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 服务器同步更新菜单
|
||||
public function sync_menu() {
|
||||
|
||||
$at = weixin_get_access_token();
|
||||
if (!$at['code']) {
|
||||
return $at;
|
||||
}
|
||||
|
||||
// 全局菜单
|
||||
$data = $this->db->table(weixin_wxtable('menu'))->where('gid', 0)->where('pid', 0)->orderBy('displayorder asc')->get()->getResultArray();
|
||||
if ($data) {
|
||||
$json = array();
|
||||
foreach ($data as $i => $t) {
|
||||
$list = $this->db->table(weixin_wxtable('menu'))->where('pid', (int)$t['id'])->orderBy('displayorder asc')->get()->getResultArray();
|
||||
if ($list) {
|
||||
$val = array();
|
||||
foreach ($list as $c) {
|
||||
$val[] = $this->_get_menu_data($c);
|
||||
}
|
||||
$json[] = array(
|
||||
'name' => dr_html2emoji($t['name']),
|
||||
'sub_button' => $val
|
||||
);
|
||||
} else {
|
||||
$json[] = $this->_get_menu_data($t);
|
||||
}
|
||||
}
|
||||
$data = array('button'=>$json);
|
||||
$rt = wx_post_https_json_data('https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$at['msg'], $data);
|
||||
if (!$rt['code']) {
|
||||
$rt['msg'] = '全局菜单:'.$rt['msg'];
|
||||
return $rt;
|
||||
}
|
||||
} else {
|
||||
return dr_return_data(0, '你还没有创建菜单');
|
||||
}
|
||||
|
||||
// 个性菜单
|
||||
$group = $this->db->table(weixin_wxtable('group'))->orderBy('id asc')->get()->getResultArray();
|
||||
if ($group) {
|
||||
foreach ($group as $g) {
|
||||
$gid = $g['tag'];
|
||||
$data = $this->db->table(weixin_wxtable('menu'))->where('gid', $gid)->where('pid', 0)->orderBy('displayorder asc')->get()->getResultArray();
|
||||
if ($data) {
|
||||
$json = array();
|
||||
foreach ($data as $i => $t) {
|
||||
$list = $this->db->table(weixin_wxtable('menu'))->where('pid', (int)$t['id'])->orderBy('displayorder asc')->get()->getResultArray();
|
||||
if ($list) {
|
||||
$val = array();
|
||||
foreach ($list as $c) {
|
||||
$val[] = $this->_get_menu_data($c);
|
||||
}
|
||||
$json[] = array(
|
||||
'name' => dr_html2emoji($t['name']),
|
||||
'sub_button' => $val
|
||||
);
|
||||
} else {
|
||||
$json[] = $this->_get_menu_data($t);
|
||||
}
|
||||
}
|
||||
$data = array(
|
||||
'button'=>$json,
|
||||
'matchrule' => [
|
||||
'tag_id' => $gid,
|
||||
]
|
||||
);
|
||||
$rt = wx_post_https_json_data('https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token='.$at['msg'], $data);
|
||||
if (!$rt['code']) {
|
||||
$rt['msg'] = '个性菜单['.$g['name'].']:'.$rt['msg'];
|
||||
return $rt;
|
||||
}
|
||||
$this->db->table(weixin_wxtable('menu'))->where('gid', $gid)->update(['menuid' => (int)$rt['data']['menuid']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
|
||||
//https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=ACCESS_TOKEN
|
||||
}
|
||||
|
||||
// 服务器获取菜单
|
||||
public function down_menu() {
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
$rt = wx_get_https_json_data('https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token='.$rt['msg']);
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
} elseif (!$rt['data']['is_menu_open']) {
|
||||
return dr_return_data(0, '公众号上菜单没有开启');
|
||||
} elseif ($rt['data']['selfmenu_info']) {
|
||||
\Phpcmf\Service::M()->table(weixin_wxtable('menu'))->clear_all();
|
||||
foreach ($rt['data']['selfmenu_info']['button'] as $top) {
|
||||
if ($top['sub_button']) {
|
||||
$this->db->table(weixin_wxtable('menu'))->insert([
|
||||
'gid' => 0,
|
||||
'pid' => 0,
|
||||
'name' => dr_emoji2html($top['name']),
|
||||
'type' => '',
|
||||
'value' => '',
|
||||
'displayorder' => 0,
|
||||
]);
|
||||
$pid = $this->db->insertID();
|
||||
// 子菜单
|
||||
foreach ($top['sub_button']['list'] as $menu) {
|
||||
$this->db->table(weixin_wxtable('menu'))->insert([
|
||||
'gid' => 0,
|
||||
'pid' => $pid,
|
||||
'name' => dr_emoji2html($menu['name']),
|
||||
'type' => $menu['type'],
|
||||
'value' => (string)($menu['url'] ? $menu['url'] : $menu['key']),
|
||||
'displayorder' => 0,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
// 本身菜单
|
||||
$this->db->table(weixin_wxtable('menu'))->insert([
|
||||
'gid' => 0,
|
||||
'pid' => 0,
|
||||
'name' => dr_emoji2html($top['name']),
|
||||
'type' => $top['type'],
|
||||
'value' => (string)($top['url'] ? $top['url'] : $top['key']),
|
||||
'displayorder' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
}
|
||||
|
||||
// 顶级菜单
|
||||
public function top_menu() {
|
||||
return $this->db->table(weixin_wxtable('menu'))->where('pid', 0)->orderBy('displayorder asc')->get()->getResultArray();
|
||||
}
|
||||
|
||||
// 修改标签
|
||||
public function edit_group($id, $name) {
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
$rt = wx_post_https_json_data(
|
||||
'https://api.weixin.qq.com/cgi-bin/tags/update?access_token='.$rt['msg'],
|
||||
[
|
||||
'tag' => [
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
]
|
||||
]
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
}
|
||||
|
||||
// 添加标签
|
||||
public function add_group($name) {
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
$rt = wx_post_https_json_data(
|
||||
'https://api.weixin.qq.com/cgi-bin/tags/create?access_token='.$rt['msg'],
|
||||
[
|
||||
'tag' => [
|
||||
'name' => $name,
|
||||
]
|
||||
]
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
return dr_return_data($rt['data']['tag']['id'], 'ok');
|
||||
}
|
||||
|
||||
// 删除标签
|
||||
public function delete_group($id) {
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
$rt = wx_post_https_json_data(
|
||||
'https://api.weixin.qq.com/cgi-bin/tags/delete?access_token='.$rt['msg'],
|
||||
[
|
||||
'tag' => [
|
||||
'id' => $id,
|
||||
]
|
||||
]
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
}
|
||||
|
||||
// 更新本地账户表
|
||||
public function insert_user($data) {
|
||||
|
||||
$save = [
|
||||
'uid' => 0,
|
||||
'username' => '',
|
||||
'openid' => $data['openid'],
|
||||
'nickname' => dr_emoji2html($data['nickname']?$data['nickname']:'微信用户'),
|
||||
'sex' => $data['sex'],
|
||||
'city' => $data['city'],
|
||||
'province' => $data['province'],
|
||||
'country' => $data['country'],
|
||||
'headimgurl' => (string)$data['headimgurl'],
|
||||
'subscribe' => (int)$data['subscribe_time'],
|
||||
'subscribe_time' => SYS_TIME,
|
||||
'unionid' => (string)$data['unionid'],
|
||||
'remark' => dr_emoji2html($data['remark']),
|
||||
'groupids' => $this->_get_groupids($data['tagid_list']),
|
||||
'content' => dr_array2string($data),
|
||||
];
|
||||
|
||||
$oauth = $this->db->table('member_oauth')->where('oid', $data['openid'])->get()->getRowArray();
|
||||
if ($oauth) {
|
||||
$save['uid'] = $oauth['uid'];
|
||||
$save['username'] = \Phpcmf\Service::M('member')->username($save['uid']);
|
||||
}
|
||||
|
||||
$row = $this->db->table(weixin_wxtable('user'))->where('openid', $data['openid'])->get()->getRowArray();
|
||||
if ($row) {
|
||||
$rt = $this->table(weixin_wxtable('user'))->update($row['id'], $save);
|
||||
if ($rt['code']) {
|
||||
$save['id'] = $row['id'];
|
||||
return $save;
|
||||
}
|
||||
} else {
|
||||
$rt = $this->table(weixin_wxtable('user'))->insert($save);
|
||||
if ($rt['code']) {
|
||||
$save['id'] = $rt['code'];
|
||||
return $save;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
// 更新本地账户表
|
||||
public function update_user($user, $data, $time = SYS_TIME) {
|
||||
|
||||
$save = [
|
||||
'openid' => $data['openid'],
|
||||
'nickname' => dr_emoji2html($data['nickname']?$data['nickname']:'微信用户'),
|
||||
'sex' => $data['sex'],
|
||||
'city' => $data['city'],
|
||||
'province' => $data['province'],
|
||||
'country' => $data['country'],
|
||||
'headimgurl' => $data['headimgurl'],
|
||||
'subscribe' => (int)$data['subscribe_time'],
|
||||
'subscribe_time' => $time,
|
||||
'unionid' => (string)$data['unionid'],
|
||||
'remark' => dr_emoji2html($data['remark']),
|
||||
'groupids' => $this->_get_groupids($data['tagid_list']),
|
||||
'content' => dr_array2string($data),
|
||||
];
|
||||
|
||||
$this->table(weixin_wxtable('user'))->update($user['id'], $save);
|
||||
|
||||
return dr_array22array($user, $save);
|
||||
}
|
||||
|
||||
// 更新组
|
||||
public function add_member_group($uid, $groupid) {
|
||||
|
||||
$group = $this->db->table(weixin_wxtable('group'))->where('groupid', $groupid)->get()->getRowArray();
|
||||
if (!$group) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gid = $group['tag'];
|
||||
$user = $this->db->table(weixin_wxtable('user'))->where('uid', $uid)->get()->getRowArray();
|
||||
if ($user && $gid) {
|
||||
$tags = dr_string2array($user['groupids']);
|
||||
if (!dr_in_array($gid, $tags)) {
|
||||
$tags[] = (string)$gid;
|
||||
$this->table(weixin_wxtable('user'))->update($user['id'], [
|
||||
'groupids' => $this->_get_groupids($tags),
|
||||
]);
|
||||
// 增加标签
|
||||
$rt = weixin_get_access_token();
|
||||
if ($rt['code']) {
|
||||
$access_token = $rt['msg'];
|
||||
|
||||
$param = [
|
||||
'openid_list' => [$user['openid']],
|
||||
'tagid' => $gid,
|
||||
];
|
||||
$rt = wx_post_https_json_data(
|
||||
'https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=' . $access_token,
|
||||
$param
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
log_message('error', '联动变更微信组标签:'.$rt['msg']);
|
||||
}
|
||||
} else {
|
||||
log_message('error', '联动变更微信组标签:'.$rt['msg']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除组
|
||||
public function delete_member_group($uid, $groupid) {
|
||||
|
||||
$group = $this->db->table(weixin_wxtable('group'))->where('groupid', $groupid)->get()->getRowArray();
|
||||
if (!$group) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gid = $group['tag'];
|
||||
$user = $this->db->table(weixin_wxtable('user'))->where('uid', $uid)->get()->getRowArray();
|
||||
if ($user && $gid) {
|
||||
$tags = dr_string2array($user['groupids']);
|
||||
if (dr_in_array($gid, $tags)) {
|
||||
$tags[] = (string)$gid;
|
||||
|
||||
foreach ($tags as $i => $v) {
|
||||
if ($v == $gid) {
|
||||
unset($tags[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->table(weixin_wxtable('user'))->update($user['id'], [
|
||||
'groupids' => $this->_get_groupids($tags),
|
||||
]);
|
||||
// 删除标签
|
||||
$rt = weixin_get_access_token();
|
||||
if ($rt['code']) {
|
||||
$access_token = $rt['msg'];
|
||||
|
||||
$param = [
|
||||
'openid_list' => [$user['openid']],
|
||||
'tagid' => $gid,
|
||||
];
|
||||
$rt = wx_post_https_json_data(
|
||||
'https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=' . $access_token,
|
||||
$param
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
log_message('error', '联动变更微信组标签:'.$rt['msg']);
|
||||
}
|
||||
} else {
|
||||
log_message('error', '联动变更微信组标签:'.$rt['msg']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化
|
||||
private function _get_groupids($arr) {
|
||||
|
||||
if ($arr) {
|
||||
foreach ($arr as $i => $t) {
|
||||
$arr[$i] = (string)$t;
|
||||
}
|
||||
}
|
||||
|
||||
return dr_array2string($arr);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,701 @@
|
||||
<?php namespace Phpcmf\Model\Weixin;
|
||||
|
||||
class Weixin extends \Phpcmf\Model
|
||||
{
|
||||
|
||||
// 发送通知
|
||||
public function send_notice($value, $siteid, $error) {
|
||||
|
||||
$content = [];
|
||||
if (isset($value['config']['weixin']['tpl_content']) && is_array($value['config']['weixin']['tpl_content'])) {
|
||||
$content = $value['config']['weixin']['tpl_content'];
|
||||
if (!$content) {
|
||||
$error[] = $debug = '自定义通知内容参数tpl_content不存在';
|
||||
CI_DEBUG && log_message('debug', '通知任务('.$value['name'].')微信执行失败:'.$debug);
|
||||
}
|
||||
} else {
|
||||
$rt = \Phpcmf\Service::L('notice')->_get_tpl_content($siteid, $value['name'], 'weixin', $value['data']);
|
||||
if (!$rt['code']) {
|
||||
$error[] = $rt['msg'];
|
||||
CI_DEBUG && log_message('debug', '通知任务('.$value['name'].')执行失败:'.$rt['msg']);
|
||||
} else {
|
||||
$xml = \Phpcmf\Service::L('notice')->_xml_array($rt['msg']);
|
||||
if (!$xml || !isset($xml['xml']) || !$xml['xml']) {
|
||||
$error[] = $debug = 'xml解析失败,检查文件格式是否正确:'.$value['name'].'.html';
|
||||
CI_DEBUG && log_message('debug', '通知任务('.$value['name'].')微信执行失败:'.$debug.'<br>'.$rt['msg']);
|
||||
} else {
|
||||
$content = $xml['xml'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($content) {
|
||||
$rt = \Phpcmf\Service::M('member')->weixin_template($value['data']['uid'], $content['id'], $content['param'], $content['url']);
|
||||
if (!$rt['code']) {
|
||||
$error[] = $debug = '微信消息执行错误:'.$rt['msg'];
|
||||
CI_DEBUG && log_message('debug', '通知任务('.$value['name'].')微信执行失败:'.$debug);
|
||||
} else {
|
||||
// 成功
|
||||
unset($value['config']['weixin']);
|
||||
}
|
||||
}
|
||||
return [$error, $value];
|
||||
}
|
||||
|
||||
// 获取微信表名
|
||||
public function wxtable($name) {
|
||||
return weixin_wxtable($name);
|
||||
}
|
||||
|
||||
// 获取配置信息
|
||||
public function get_config($name) {
|
||||
|
||||
$data = $this->db->table(weixin_wxtable('weixin'))->where('name', $name)->get()->getRowArray();
|
||||
if ($data) {
|
||||
$data = dr_string2array($data['value']);
|
||||
return $data;
|
||||
} else {
|
||||
$this->db->table(weixin_wxtable('weixin'))->insert([
|
||||
'name' => $name,
|
||||
'value' => '',
|
||||
]);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// 存储配置信息
|
||||
public function save_config($name, $post) {
|
||||
|
||||
$rt = $this->db->table(weixin_wxtable('weixin'))->replace([
|
||||
'name' => $name,
|
||||
'value' => dr_array2string($post),
|
||||
]);
|
||||
|
||||
if ($rt->connID->error) {
|
||||
return dr_return_data(0, $this->table.': '.$rt->connID->error);
|
||||
}
|
||||
|
||||
return dr_return_data(1);
|
||||
}
|
||||
|
||||
// 上传图文消息内的图片获取URL
|
||||
public function get_file_media_id($access_token, $type, $filename) {
|
||||
|
||||
// 查询本地库
|
||||
$rt = $this->table(weixin_wxtable('media_id'))->where('file', md5($filename))->getRow();
|
||||
if ($rt) {
|
||||
return dr_return_data(1, 'ok', $rt);
|
||||
}
|
||||
$id = dr_get_file($filename, true);
|
||||
if (!$id) {
|
||||
return dr_return_data(0, '文件不存在');
|
||||
}
|
||||
$file = WRITEPATH.'temp/sync_'.md5($id).'.'.substr(strrchr($id, '.'), 1);;
|
||||
$c = dr_catcher_data($id);
|
||||
if (!$c) {
|
||||
return dr_return_data(0, '无法获取文件内容:'.$id);
|
||||
}
|
||||
$rt = file_put_contents($file, $c);
|
||||
if (!$rt) {
|
||||
return dr_return_data(0, '本地文件写入失败:'.$id);
|
||||
} elseif (!is_file($file)) {
|
||||
return dr_return_data(0, '本地文件不存在');
|
||||
}
|
||||
|
||||
$rt = ihttp_request(
|
||||
'https://api.weixin.qq.com/cgi-bin/material/add_material?access_token='.$access_token,
|
||||
[
|
||||
'type' => 'image',
|
||||
'media' => '@' . $file
|
||||
]
|
||||
);
|
||||
if ($rt['code']) {
|
||||
// 更新到媒体表
|
||||
$save = [
|
||||
'file' => md5($filename),
|
||||
'url' => $rt['data']['url'],
|
||||
'media_id' => $rt['data']['media_id'],
|
||||
];
|
||||
$this->table(weixin_wxtable('media_id'))->insert($save);
|
||||
}
|
||||
|
||||
return $rt;
|
||||
}
|
||||
|
||||
// 同步素材到服务器
|
||||
public function sync_content($access_token, $t, $return = 0) {
|
||||
|
||||
if (!$t['media_id'] || $return) {
|
||||
// 图文素材
|
||||
$url = 'https://api.weixin.qq.com/cgi-bin/draft/add?access_token='.$access_token;
|
||||
$param = [
|
||||
'articles' => [
|
||||
|
||||
]
|
||||
];
|
||||
$value = dr_string2array($t['content']);
|
||||
for ($i = 1; $i<=9; $i++) {
|
||||
if (!$value['title_'.$i]) {
|
||||
break;
|
||||
}
|
||||
if (!$value['thumb_'.$i]) {
|
||||
return dr_return_data(0, '素材['.$t['title'].'] 第'.$i.'个内容缺少封面图片');
|
||||
}
|
||||
$cache = [];
|
||||
$content = htmlspecialchars_decode($value['content_'.$i]);
|
||||
if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|png))\\2/i", $content, $imgs)) {
|
||||
foreach ($imgs[3] as $image) {
|
||||
if (!isset($cache[$image])) {
|
||||
$tmp = WRITEPATH.'temp/sync_'.md5($image).'.'.substr(strrchr($image, '.'), 1);;
|
||||
if (strpos($image, '/') === 0 && is_file(WEBPATH.$image)) {
|
||||
$file = file_get_contents(WEBPATH.$image);
|
||||
} else {
|
||||
$file = dr_catcher_data($image);
|
||||
}
|
||||
if ($file && file_put_contents($tmp, $file)) {
|
||||
$cache[$image] = 1;
|
||||
$rt = ihttp_request(
|
||||
'https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token='.$access_token,
|
||||
[
|
||||
'media' => '@' . $tmp
|
||||
]
|
||||
);
|
||||
// 更新到内容
|
||||
$rt['code'] && $content = str_replace($image, $rt['data']['url'], $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$rt = $this->get_file_media_id($access_token, 'thumb', $value['thumb_'.$i]);
|
||||
if (!$rt['code']) {
|
||||
$rt['msg'] = $value['thumb_'.$i].' - 附件上传失败:'.$rt['msg'];
|
||||
return $rt;
|
||||
}
|
||||
|
||||
$thumb_id = $rt['data']['media_id'];
|
||||
$param['articles'][] = [
|
||||
"title" => $value['title_'.$i],
|
||||
"thumb_media_id" => $thumb_id,
|
||||
"author" => $value['author_'.$i],
|
||||
"digest" => dr_strcut($value['description_'.$i], 50),
|
||||
"content" => $content,
|
||||
"show_cover_pic" => 1,
|
||||
"content_source_url" => html_entity_decode($value['url_'.$i])
|
||||
];
|
||||
}
|
||||
if (!count($param['articles'])) {
|
||||
return dr_return_data(0, '素材['.$t['title'].'] 资源信息为空无法同步');
|
||||
}
|
||||
$rt = wx_post_https_json_data($url, $param);
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
$media_id = $rt['data']['media_id'];
|
||||
if ($return) {
|
||||
return dr_return_data(1, $media_id);
|
||||
}
|
||||
} else {
|
||||
$media_id = $t['media_id'];
|
||||
}
|
||||
|
||||
if (!$t['publish_id']) {
|
||||
// 发布内容
|
||||
$rt = wx_post_https_json_data(
|
||||
'https://api.weixin.qq.com/cgi-bin/freepublish/submit?access_token='.$access_token,
|
||||
[
|
||||
'media_id' => $media_id
|
||||
]
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
$this->table(weixin_wxtable('content'))->update($t['id'], [
|
||||
'media_id' => $media_id
|
||||
]);
|
||||
return $rt;
|
||||
}
|
||||
// 存储
|
||||
$this->table(weixin_wxtable('content'))->update($t['id'], [
|
||||
'media_id' => $media_id,
|
||||
'publish_id' => $rt['data']['publish_id'],
|
||||
]);
|
||||
} else {
|
||||
// 查询结果
|
||||
$rt = wx_post_https_json_data(
|
||||
'https://api.weixin.qq.com/cgi-bin/freepublish/get?access_token='.$access_token,
|
||||
[
|
||||
'publish_id' => $t['publish_id']
|
||||
]
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
$this->table(weixin_wxtable('content'))->update($t['id'], [
|
||||
'status' => $rt['data']['publish_status'],
|
||||
'article_id' => $rt['data']['article_id']
|
||||
]);
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
}
|
||||
|
||||
// 高级群发
|
||||
public function sendall($groupid, $data)
|
||||
{
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
// 将内容转成为草稿箱
|
||||
$rs = $this->sync_content($rt['msg'], $data, 1);
|
||||
if (!$rs['code']) {
|
||||
return $rs;
|
||||
}
|
||||
|
||||
$param = [
|
||||
'msgtype' => 'mpnews',
|
||||
'mpnews' => [
|
||||
'media_id' => $rs['msg']
|
||||
],
|
||||
];
|
||||
|
||||
if ($groupid) {
|
||||
$param['filter'] = [
|
||||
'is_to_all' => false,
|
||||
'tag_id' => $groupid,
|
||||
];
|
||||
} else {
|
||||
$param['filter'] = [
|
||||
'is_to_all' => true,
|
||||
];
|
||||
}
|
||||
|
||||
$rt = wx_post_https_json_data(
|
||||
'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.$rt['msg'],
|
||||
$param
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
}
|
||||
|
||||
// 客服群发 文本内容
|
||||
public function send_for_text($groupid, $data)
|
||||
{
|
||||
|
||||
$param = [
|
||||
'msgtype' => 'text',
|
||||
'text' => [
|
||||
'content' => $data
|
||||
],
|
||||
];
|
||||
|
||||
if ($groupid) {
|
||||
if (strlen($groupid) > 5) {
|
||||
// 指定粉丝
|
||||
$user = [
|
||||
[
|
||||
'openid' => $groupid,
|
||||
]
|
||||
];
|
||||
} else {
|
||||
// 粉丝组
|
||||
$user = $this->table(weixin_wxtable('user'))->where('subscribe>0 and subscribe_time > '.(SYS_TIME - 3600*48))->where('`groupids` like "%\"'.$groupid.'\"%"')->getAll();
|
||||
}
|
||||
} else {
|
||||
// 全部粉丝
|
||||
$user = $this->table(weixin_wxtable('user'))->where('subscribe>0 and subscribe_time > '.(SYS_TIME - 3600*48))->getAll();
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
return dr_return_data(0, '48小时内互动的粉丝不存在');
|
||||
}
|
||||
|
||||
return $this->_save_send_data($user, $param);
|
||||
}
|
||||
|
||||
// 客服群发 内容模块
|
||||
public function send_for_module($dir, $ids) {
|
||||
|
||||
$data = $this->table_site($dir)->where_in('id', $ids)->getAll(9);
|
||||
if (!$data) {
|
||||
return dr_return_data(0, '模块内容不存在');
|
||||
}
|
||||
|
||||
$param = [
|
||||
'msgtype' => 'news',
|
||||
'news' => [
|
||||
'articles' => []
|
||||
],
|
||||
];
|
||||
foreach ($data as $t) {
|
||||
$param['news']['articles'][] = [
|
||||
"title" => $t['title'],
|
||||
"description" => $t['description'],
|
||||
"picurl" => dr_get_file($t['thumb'], true),
|
||||
"url" => dr_url_prefix($t['url'], $dir)
|
||||
];
|
||||
}
|
||||
|
||||
$user = $this->table(weixin_wxtable('user'))->where('subscribe>0 and subscribe_time > '.(SYS_TIME - 3600*48))->getAll();
|
||||
if (!$user) {
|
||||
return dr_return_data(0, '粉丝信息不存在');
|
||||
}
|
||||
return $this->_save_send_data($user, $param);
|
||||
|
||||
}
|
||||
|
||||
// 客服群发 内容素材
|
||||
public function send_for_content($groupid, $data)
|
||||
{
|
||||
|
||||
$param = [
|
||||
'msgtype' => 'mpnewsarticle',
|
||||
'mpnewsarticle' => [
|
||||
'article_id' => $data['article_id']
|
||||
],
|
||||
];
|
||||
|
||||
if ($groupid) {
|
||||
if (strlen($groupid) > 5) {
|
||||
// 指定粉丝
|
||||
$user = [
|
||||
[
|
||||
'openid' => $groupid,
|
||||
]
|
||||
];
|
||||
} else {
|
||||
// 粉丝组
|
||||
$user = $this->table(weixin_wxtable('user'))->where('groupid', $groupid)->where('subscribe>0 and subscribe_time > '.(SYS_TIME - 3600*48))->getAll();
|
||||
}
|
||||
} else {
|
||||
// 全部粉丝
|
||||
$user = $this->table(weixin_wxtable('user'))->where('subscribe>0 and subscribe_time > '.(SYS_TIME - 3600*48))->getAll();
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
return dr_return_data(0, '48小时内互动的粉丝不存在');
|
||||
} elseif (!$param) {
|
||||
return dr_return_data(0, '未知的tid类别信息:'.$data['tid']);
|
||||
}
|
||||
|
||||
return $this->_save_send_data($user, $param);
|
||||
}
|
||||
|
||||
// 存储客服消息发送记录表
|
||||
private function _save_send_data($user, $param) {
|
||||
|
||||
$id = (int)substr(SYS_TIME - rand(0, 9999), 0, 10);
|
||||
|
||||
foreach ($user as $t) {
|
||||
$rt = $this->table(weixin_wxtable('send'))->insert([
|
||||
'cid' => $id,
|
||||
'openid' => $t['openid'],
|
||||
'status' => 0,
|
||||
'content' => dr_array2string($param)
|
||||
]);
|
||||
if (!$rt['code']) {
|
||||
return $rt;
|
||||
}
|
||||
}
|
||||
|
||||
return dr_return_data($id, 'ok');
|
||||
}
|
||||
|
||||
// 存储客户端消息
|
||||
public function save_message($data)
|
||||
{
|
||||
|
||||
$rt = $this->table(weixin_wxtable('message'))->insert([
|
||||
'tid' => $data['MsgType'],
|
||||
'openid' => $data['FromUserName'],
|
||||
'nickname' => '',
|
||||
'headimgurl' => '',
|
||||
'status' => 0,
|
||||
'content' => dr_array2string($data),
|
||||
'inputtime' => $data['CreateTime'],
|
||||
]);
|
||||
if (!$rt['code']) {
|
||||
log_message('error', '微信消息存储失败:'.$rt['msg']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 更新统计数据
|
||||
public function update_count_fans() {
|
||||
|
||||
return $this->table(weixin_wxtable('count_fans'))->order_by('id desc')->getAll(10, 'date');
|
||||
|
||||
$seven_days = array(
|
||||
date('Ymd', strtotime('-1 days')),
|
||||
date('Ymd', strtotime('-2 days')),
|
||||
date('Ymd', strtotime('-3 days')),
|
||||
date('Ymd', strtotime('-4 days')),
|
||||
date('Ymd', strtotime('-5 days')),
|
||||
date('Ymd', strtotime('-6 days')),
|
||||
date('Ymd', strtotime('-7 days')),
|
||||
);
|
||||
|
||||
// 本周数据
|
||||
$week_stat_fans = $this->table(weixin_wxtable('count_fans'))->where_in('date', $seven_days)->getAll(0, 'date');
|
||||
$stat_update_yes = false;
|
||||
foreach ($seven_days as $sevens) {
|
||||
if (empty($week_stat_fans[$sevens]) || $week_stat_fans[$sevens]['cumulate'] <=0) {
|
||||
$stat_update_yes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($stat_update_yes)) {
|
||||
return $week_stat_fans;
|
||||
}
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if ($rt['code']) {
|
||||
$access_token = $rt['msg'];
|
||||
$url = 'https://api.weixin.qq.com/datacube/getusersummary?access_token='.$access_token;
|
||||
$rt = wx_post_https_json_data($url, [
|
||||
"begin_date" => date('Y-m-d', strtotime('-7 days')),
|
||||
"end_date" => date('Y-m-d', strtotime('-1 days')),
|
||||
]);
|
||||
if ($rt['code']) {
|
||||
$summary = $rt['data'];
|
||||
}
|
||||
|
||||
$url = 'https://api.weixin.qq.com/datacube/getusercumulate?access_token='.$access_token;
|
||||
$rt = wx_post_https_json_data($url, [
|
||||
"begin_date" => date('Y-m-d', strtotime('-7 days')),
|
||||
"end_date" => date('Y-m-d', strtotime('-1 days')),
|
||||
]);
|
||||
if ($rt['code']) {
|
||||
$cumulate = $rt['data'];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
if (!empty($summary['list'])) {
|
||||
foreach ($summary['list'] as $row) {
|
||||
$key = str_replace('-', '', $row['ref_date']);
|
||||
$result[$key]['new'] = intval($result[$key]['new']) + $row['new_user'];
|
||||
$result[$key]['cancel'] = intval($result[$key]['cancel']) + $row['cancel_user'];
|
||||
}
|
||||
}
|
||||
if (!empty($cumulate['list'])) {
|
||||
foreach ($cumulate['list'] as $row) {
|
||||
$key = str_replace('-', '', $row['ref_date']);
|
||||
$result[$key]['cumulate'] = $row['cumulate_user'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($result as $i => $t) {
|
||||
$this->table(weixin_wxtable('count_fans'))->replace([
|
||||
'new' => (int)$t['new'],
|
||||
'cancel' => (int)$t['cancel'],
|
||||
'cumulate' => (int)$t['cumulate'],
|
||||
'date' => $i,
|
||||
]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $week_stat_fans;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送微信通知模板
|
||||
*
|
||||
* $uid 会员id
|
||||
* $id 微信模板id
|
||||
* $data 通知内容
|
||||
* $url 详细地址
|
||||
* $color top颜色
|
||||
*/
|
||||
public function send_template($uid, $id, $data, $url = '', $color = '') {
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if (!$rt['code']) {
|
||||
return dr_return_data(0, $rt['msg']);
|
||||
}
|
||||
|
||||
if (is_array($uid)) {
|
||||
$error = [];
|
||||
foreach ($uid as $u) {
|
||||
$oauth = $this->db->table('member_oauth')->where('uid', $u)->where('oauth', 'wechat')->get()->getRowArray();
|
||||
if (!$oauth) {
|
||||
$error[] = 'uid('.$u.')未绑定账号';
|
||||
continue;
|
||||
}
|
||||
$rs = wx_post_https_json_data('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$rt['msg'], [
|
||||
'touser' => $oauth['oid'],
|
||||
'template_id' => $id,
|
||||
'url' => $url,
|
||||
'topcolor' => $color,
|
||||
'data' => $data,
|
||||
]);
|
||||
if (!$rs['code']) {
|
||||
$error[] = $rs['msg'];
|
||||
}
|
||||
}
|
||||
if (dr_count($error) == dr_count($uid)) {
|
||||
return dr_return_data(0, implode(';', $error));
|
||||
} else {
|
||||
return dr_return_data(1, '发送成功');
|
||||
}
|
||||
} else {
|
||||
$oauth = $this->db->table('member_oauth')->where('uid', $uid)->where('oauth', 'wechat')->get()->getRowArray();
|
||||
if (!$oauth) {
|
||||
return dr_return_data(0, 'uid('.$uid.')未绑定账号');
|
||||
}
|
||||
|
||||
return wx_post_https_json_data('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$rt['msg'], [
|
||||
'touser' => $oauth['oid'],
|
||||
'template_id' => $id,
|
||||
'url' => $url,
|
||||
'topcolor' => $color,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送微信订阅通知
|
||||
*
|
||||
* $uid 会员id
|
||||
* $id 所需下发的订阅模板id
|
||||
* $data 通知内容
|
||||
* $url 详细地址
|
||||
*/
|
||||
public function send_biz($uid, $id, $data, $url = '') {
|
||||
|
||||
$oauth = $this->db->table('member_oauth')->where('uid', $uid)->where('oauth', 'wechat')->get()->getRowArray();
|
||||
if (!$oauth) {
|
||||
return dr_return_data(0, 'uid('.$uid.')未绑定账号');
|
||||
}
|
||||
|
||||
$rt = weixin_get_access_token();
|
||||
if (!$rt['code']) {
|
||||
return dr_return_data(0, $rt['msg']);
|
||||
}
|
||||
|
||||
return wx_post_https_json_data('https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend?access_token='.$rt['msg'], [
|
||||
'touser' => $oauth['oid'],
|
||||
'template_id' => $id,
|
||||
'page' => $url,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
// 缓存
|
||||
public function cache($siteid = SITE_ID)
|
||||
{
|
||||
|
||||
$table = \Phpcmf\Service::M()->dbprefix('app_weixin');
|
||||
if (!\Phpcmf\Service::M()->is_table_exists($table)) {
|
||||
\Phpcmf\Service::M('table')->create_table(
|
||||
$table,
|
||||
[
|
||||
'id' => 'int(10) NOT NULL AUTO_INCREMENT COMMENT \'id\'',
|
||||
'name' => 'varchar(200) NOT NULL COMMENT \'公众号名称\'',
|
||||
],
|
||||
[
|
||||
'PRIMARY KEY (`id`)',
|
||||
],
|
||||
'多公众号表'
|
||||
);
|
||||
}
|
||||
|
||||
$mr = \Phpcmf\Service::M()->table('app_weixin')->get(1);
|
||||
if (!$mr) {
|
||||
\Phpcmf\Service::M()->table('app_weixin')->replace([
|
||||
'id' => 1,
|
||||
'name' => '默认公众号'
|
||||
]);
|
||||
}
|
||||
|
||||
$alls = $this->table('app_weixin')->getAll();
|
||||
$more_cache = [];
|
||||
foreach ($alls as $more) {
|
||||
$more_cache[$more['id']] = $more['name'];
|
||||
/////////////////////////
|
||||
$data = $this->table(weixin_wxtable('weixin', $more['id']))->getAll();
|
||||
|
||||
$cache = [];
|
||||
if ($data) {
|
||||
foreach ($data as $t) {
|
||||
$value = dr_string2array($t['value']);
|
||||
$cache[$t['name']] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$kws = [];
|
||||
$data = $this->table(weixin_wxtable('reply', $more['id']))->getAll();
|
||||
if ($data) {
|
||||
foreach ($data as $t) {
|
||||
$arr = explode(',', $t['keyword']);
|
||||
if ($arr) {
|
||||
foreach ($arr as $kw) {
|
||||
$kws[$kw] = $t['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
uksort($kws, function ($a, $b) {
|
||||
return strlen($b) - strlen($a);
|
||||
});
|
||||
}
|
||||
\Phpcmf\Service::L('cache')->set_file('weixin-kws'.($more['id'] > 1 ? '_more_'.$more['id'] : ''), $kws);
|
||||
|
||||
$table = $this->dbprefix(weixin_wxtable('template', $more['id']));
|
||||
if (!\Phpcmf\Service::M()->is_table_exists($table)) {
|
||||
\Phpcmf\Service::M('table')->create_table(
|
||||
$table,
|
||||
[
|
||||
'id' => 'int(10) NOT NULL AUTO_INCREMENT COMMENT \'id\'',
|
||||
'title' => 'varchar(200) NOT NULL COMMENT \'主题\'',
|
||||
'groupid' => 'int(10) NOT NULL COMMENT \'发送标签组\'',
|
||||
'counts' => 'int(10) NOT NULL COMMENT \'发送数\'',
|
||||
'content' => 'text NOT NULL COMMENT \'消息内容\'',
|
||||
'template' => 'varchar(200) NOT NULL COMMENT \'模板ID\'',
|
||||
'url' => 'varchar(200) NOT NULL COMMENT \'url\'',
|
||||
'color' => 'varchar(200) NOT NULL COMMENT \'主题颜色\'',
|
||||
'inputtime' => 'int(10) NOT NULL COMMENT \'录入时间\'',
|
||||
],
|
||||
[
|
||||
'PRIMARY KEY (`id`)',
|
||||
'KEY `inputtime` (`inputtime`)',
|
||||
],
|
||||
'微信模板消息记录表'
|
||||
);
|
||||
}
|
||||
|
||||
$table = $this->dbprefix(weixin_wxtable('user', $more['id']));
|
||||
\Phpcmf\Service::M()->query('UPDATE `'.$table.'` SET `subscribe`=`subscribe_time` where `subscribe`=1');
|
||||
|
||||
$table = $this->dbprefix(weixin_wxtable('content', $more['id']));
|
||||
$t = \Phpcmf\Service::M('table');
|
||||
$m = \Phpcmf\Service::M();
|
||||
if (!$m->is_field_exists($table, 'nums')) {
|
||||
$t->add_field($table, 'nums', 'tinyint(2)', 'DEFAULT \'0\'', '');
|
||||
}
|
||||
if (!$m->is_field_exists($table, 'status')) {
|
||||
$t->add_field($table, 'status', 'tinyint(2)', 'DEFAULT \'0\'', '');
|
||||
}
|
||||
if (!$m->is_field_exists($table, 'publish_id')) {
|
||||
$t->add_field($table, 'publish_id', 'varchar(255)', 'DEFAULT \'\'', '');
|
||||
}
|
||||
if (!$m->is_field_exists($table, 'article_id')) {
|
||||
$t->add_field($table, 'article_id', 'varchar(255)', 'DEFAULT \'\'', '');
|
||||
}
|
||||
|
||||
|
||||
\Phpcmf\Service::L('cache')->set_file('weixin'.($more['id'] > 1 ? '_more_'.$more['id'] : ''), $cache);
|
||||
/// ////////////////////////
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('cache')->set_file('app_weixin', count($more_cache) == 1 ? '' : $more_cache);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user