962 lines
36 KiB
PHP
962 lines
36 KiB
PHP
<?php
|
|
namespace app\admin\controller;
|
|
use app\common\controller\Admin;
|
|
use think\Request;
|
|
use think\Loader;
|
|
use think\Db;
|
|
//高级群发 || 素材管理 || 关注回复设置 || 菜单设置 || 模板消息
|
|
class Wxpushall extends Admin{
|
|
|
|
// 对应公众号管理
|
|
public function index(){
|
|
$id = input('id');
|
|
if(empty($id)){
|
|
return "错误";
|
|
}
|
|
$list = db('wechat_material_list')->where('wxid',$id)->order('id desc')->select();
|
|
$wxname = db('wxopen_account')->where('id',$id)->value('title');
|
|
//公众号列表
|
|
$wxlist = db('wxopen_account')->field('id,title')->select();
|
|
$this->assign('wxlist',$wxlist);
|
|
$this->assign('wxid',$id);
|
|
$this->assign('list',$list);
|
|
$this->setMeta($wxname);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function wxlist(){
|
|
$keyword = input('keyword');
|
|
if($keyword){
|
|
$list = db('wxopen_account')->where('title','like',"%{$keyword}%")->select();
|
|
}else{
|
|
$list = db('wxopen_account')->select();
|
|
}
|
|
$this->assign('list',$list);
|
|
$this->setMeta('公众号列表');
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 群发日志
|
|
public function wxpushhistory(){
|
|
$id = input('id');
|
|
$data = db('wxpushhistory')->where('wxid',$id)->order('id desc')->select();
|
|
$wxname = db('wxopen_account')->where('id',$id)->value('title');
|
|
$this->setMeta($wxname);
|
|
$this->assign('data',$data);
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 对应模板的素材列表
|
|
public function mdlist(){
|
|
$mid = input('mid');
|
|
$wxid = input('wxid');
|
|
$upwx = db('wechat_material_list')->where('id',$mid)->value('upwx');
|
|
$list = db('wechat_material')->where('mid',$mid)->order('id asc')->select();
|
|
$wxname = db('wxopen_account')->where('id',$wxid)->value('title');
|
|
$this->assign('upwx',$upwx);
|
|
$this->assign('list',$list);
|
|
$this->assign('mid',$mid);
|
|
$this->assign('wxid',$wxid);
|
|
$this->setMeta($wxname);
|
|
return $this->fetch();
|
|
}
|
|
// 重置上传对应模板的素材列表状态
|
|
public function mdlistreset()
|
|
{
|
|
$mid = input('mid');
|
|
$wxid = input('wxid');
|
|
$res = db('wechat_material_list')->where('id',$mid)->where('wxid',$wxid)->update(['upwx'=>0,'status'=>1]);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
}
|
|
|
|
// 上传图片返回地址
|
|
public function upimg(){
|
|
$imgurl = request()->file('img');
|
|
if($imgurl){
|
|
$path = ROOT_PATH . '/public';
|
|
$savename = DS .'advanced'.DS.date('Y').DS.date('m').DS.date('d').DS.md5(microtime(true));
|
|
$img = $imgurl->validate(['size'=>2048000])->move($path,$savename);
|
|
if($img){
|
|
$imageurl = config('web_site_url'). '/public'.$img->getSaveName();
|
|
compressedImage(ROOT_PATH. '/public'.$img->getSaveName(), ROOT_PATH. '/public'.$img->getSaveName(), 40);
|
|
exit(json_encode(array('status'=>1,'thumb_url'=>$imageurl)));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'error'=>'图片不能超过2mb')));
|
|
}
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// 添加栏目页面
|
|
public function addnavshow(){
|
|
$mid = input('mid');
|
|
$wxid = input('wxid');
|
|
if(empty($mid)){
|
|
$mid = 0;
|
|
}
|
|
$wxname = db('wxopen_account')->where('id',$wxid)->value('title');
|
|
$this->assign('wxid',$wxid);
|
|
$this->assign('mid',$mid);
|
|
$this->setMeta($wxname);
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 添加素材栏目
|
|
public function addnavs(){
|
|
$data = input('');
|
|
if($data){
|
|
// 第一次添加的栏目默认为封面
|
|
$data['show_cover_pic'] = $data['mid']==0?1:0;
|
|
$data['addtime'] = time();
|
|
// 栏目位置
|
|
if($data['mid']==0){
|
|
$data['index'] = 0;
|
|
db('wechat_material_list')->insert(array(
|
|
'imgurl'=>$data['thumb_url'],
|
|
'title'=>$data['title'],
|
|
'addtime'=>time(),
|
|
'upwx'=>0,
|
|
'wxid'=>$data['wxid'],
|
|
'top_url'=>$data['top_url']
|
|
));
|
|
$data['mid'] = db('wechat_material_list')->getLastInsID();
|
|
}else{
|
|
$index = db('wechat_material')->where('mid',$data['mid'])->order('id desc')->value('index');
|
|
$data['index'] = $index + 1;
|
|
}
|
|
//上传内容里的图片到微信 然后获取地址 在拼接到内容
|
|
import("Wechatpush.Wechatpush", EXTEND_PATH,'.php');
|
|
$wx_config = db('wxopen_account')->field('appid,appsecret')->where('id',$data['wxid'])->find();
|
|
$appid = $wx_config['appid'];
|
|
$secret= $wx_config['appsecret'];
|
|
$wx = new \Wechatpush($appid,$secret);
|
|
$botimg_path = parse_url($data['bot_url']);
|
|
$botimg = $botimg_path['path'];
|
|
$botimg = config('server_path').$botimg;
|
|
$wximgurl = $wx->getimg($botimg);
|
|
$topimgdiv = '';
|
|
if($data['top_url']){
|
|
$topimg_path = parse_url($data['top_url']);
|
|
$topimg = $topimg_path['path'];
|
|
$topimg = config('server_path').$topimg;
|
|
$topimg = $wx->getimg($topimg);
|
|
$topimgdiv = '<a href="'.$topimg.'"><img style="display:block;margin: 0 auto;" src="'.$topimg.'"></a>';
|
|
$data['wx_top_url'] = $topimg;
|
|
}
|
|
$data['wximgurl'] = $wximgurl;
|
|
$data['content'] = '<div style="width:100%;height:100%;z-index:999;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;">'.$topimgdiv.$data['content'].'<div><a href="'.$wximgurl.'"><img src="'.$wximgurl.'"></a>';
|
|
$res = db('wechat_material')->insert($data);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'添加成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'添加失败')));
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// 修改素材页面
|
|
public function editshow(){
|
|
$id = input('id');
|
|
$wxid = input('wxid');
|
|
if($id){
|
|
$i = db('wechat_material')->where('id',$id)->find();
|
|
$upwx = db('wechat_material_list')->where('id',$i['mid'])->value('upwx');
|
|
$wxname = db('wxopen_account')->where('id',$wxid)->value('title');
|
|
$this->assign('upwx',$upwx);
|
|
$this->assign('data',$i);
|
|
$this->setMeta($wxname);
|
|
return $this->fetch();
|
|
}
|
|
}
|
|
|
|
// 修改素材
|
|
public function edit(){
|
|
$data = input();
|
|
if($data){
|
|
$id = $data['id'];
|
|
unset($data['id']);
|
|
//上传内容里的图片到微信 然后获取地址 在拼接到内容
|
|
import("Wechatpush.Wechatpush", EXTEND_PATH,'.php');
|
|
$wx_config = db('wxopen_account')->field('appid,appsecret')->where('id',$data['wxid'])->find();
|
|
$appid = $wx_config['appid'];
|
|
$secret= $wx_config['appsecret'];
|
|
$wx = new \Wechatpush($appid,$secret);
|
|
$botimg_path = parse_url($data['bot_url']);
|
|
$botimg = $botimg_path['path'];
|
|
$botimg = config('server_path').$botimg;
|
|
$wximgurl = $wx->getimg($botimg);
|
|
$topimgdiv = '';
|
|
if($data['top_url']){
|
|
$topimg_path = parse_url($data['top_url']);
|
|
$topimg = $topimg_path['path'];
|
|
$topimg = config('server_path').$topimg;
|
|
$topimg = $wx->getimg($topimg);
|
|
$topimgdiv = '<a href="'.$topimg.'"><img style="display:block;margin: 0 auto;" src="'.$topimg.'"></a>';
|
|
$data['wx_top_url'] = $topimg;
|
|
}
|
|
$data['wximgurl'] = $wximgurl;
|
|
//替换原来的底部图片内容
|
|
$ybotimg = db('wechat_material')->where('id',$id)->value('wximgurl');
|
|
$data['content'] = str_replace($ybotimg,$wximgurl,$data['content']);
|
|
//替换原来的TOP插图
|
|
if($topimgdiv){
|
|
$ytopimg = db('wechat_material')->where('id',$id)->value('wx_top_url');
|
|
$data['content'] = str_replace($ytopimg,$topimg,$data['content']);
|
|
}
|
|
$data['content'] = '<div style="width:100%;height:100%;z-index:999;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;">'.$data['content'].'<div>';
|
|
$res = db('wechat_material')->where('id',$id)->update($data);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 删除素材
|
|
public function del(){
|
|
$id = input('id');
|
|
if($id){
|
|
$img_url = db('wechat_material')->field('thumb_url,bot_url')->where('id',$id)->find();
|
|
//删除图片
|
|
//@unlink(parseurl($img_url['thumb_url']));
|
|
//@unlink(parseurl($img_url['bot_url']));
|
|
$res = db('wechat_material')->delete($id);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 删除整个模板素材 同步删除到微信
|
|
public function delmd(){
|
|
$id = input('id');
|
|
if($id){
|
|
$list = db('wechat_material')->where('mid',$id)->select();
|
|
foreach($list as $k=>$v){
|
|
//@unlink(parseurl($v['thumb_url']));
|
|
//@unlink(parseurl($v['bot_url']));
|
|
db('wechat_material')->delete($v['id']);
|
|
}
|
|
$wxid = db('wechat_material_list')->where('id',$id)->value('wxid');
|
|
db('wechat_material_list')->delete($id);
|
|
$tcpurl = "http://127.0.0.1:9505";
|
|
$tcparr = array(
|
|
'id'=>$id,
|
|
'type'=>'delmd',
|
|
'wxid'=>$wxid
|
|
);
|
|
pushMessageToClient($tcpurl,json_encode($tcparr));
|
|
exit(json_encode(array('status'=>1,'reg'=>'删除成功')));
|
|
}
|
|
}
|
|
|
|
|
|
// 上传图片返回 图片 media_id 然后入库
|
|
public function upthumb($wx,$file,$wxid,$mid,$sid){
|
|
$file = parseurl($file);
|
|
$res = $wx->uploadImage($file);
|
|
// db('thumb_media_id')->insert(array(
|
|
// 'thumb_media_id'=>$res,
|
|
// 'wxid'=>$wxid,
|
|
// 'mid'=>$mid,
|
|
// 'sid'=>$sid
|
|
// ));
|
|
return $res;
|
|
}
|
|
|
|
// 返回素材media_id 然后入库
|
|
public function GetmaterialMediaid($wx,$data,$wxid,$mid){
|
|
$media_id = $wx->upMaterial($data);
|
|
if(!empty($media_id)){
|
|
db('media_id')->insert(array(
|
|
'media_id'=>$media_id,
|
|
'wxid'=>$wxid,
|
|
'mid'=>$mid
|
|
));
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// 把图文素材上传到公众号 原来是用swoole上传的
|
|
// public function upMaterial(){
|
|
// $mid = input('mid');
|
|
// if($mid){
|
|
// $wxid = db('wechat_material_list')->where('id',$mid)->value('wxid');
|
|
// $tcpurl = "http://127.0.0.1:9505";
|
|
// $tcparr = array(
|
|
// 'mid'=>$mid,
|
|
// 'type'=>'upMaterial',
|
|
// 'wxid'=>$wxid
|
|
// );
|
|
// pushMessageToClient($tcpurl,json_encode($tcparr));
|
|
// exit(json_encode(array('status'=>1,'reg'=>'成功,将同步到公众号')));
|
|
// }
|
|
// }
|
|
|
|
public function upMaterial(){
|
|
$mid = input('mid');
|
|
if($mid){
|
|
// 更新模板状态是否同步到公众号
|
|
db('wechat_material_list')->where('id',$mid)->update(['upwx'=>1]);
|
|
$material = db('wechat_material')->where('mid',$mid)->order('id asc')->select();
|
|
// 公众号
|
|
$wxid = db('wechat_material_list')->where('id',$mid)->value('wxid');
|
|
$wx_configs = db('wxopen_account')->where('id',$wxid)->find();
|
|
$appid = $wx_configs['appid'];
|
|
$secret= $wx_configs['appsecret'];
|
|
import("Wechatpush.Wechatpush", EXTEND_PATH,'.php');
|
|
$wx = new \Wechatpush($appid,$secret);
|
|
$data = array();
|
|
// 先上传图片拿到标识 拼接数据
|
|
$index = 0;
|
|
foreach($material as $k2=>$v2){
|
|
$data[$k2]['title'] = urlencode(mb_substr($v2['title'],0,60,'utf8'));
|
|
$data[$k2]['thumb_media_id'] = $this->upthumb($wx,$v2['thumb_url'],$wxid,$mid,$v2['id']);
|
|
$data[$k2]['show_cover_pic'] = $v2['show_cover_pic'];
|
|
$data[$k2]['content'] = urlencode(htmlspecialchars(str_replace("\"", "'", $v2['content'])));
|
|
$data[$k2]['content_source_url'] = $v2['content_source_url'];
|
|
db('wechat_material')->where('id',$v2['id'])->update(['index'=>$index]);
|
|
$index++;
|
|
}
|
|
$is = $this->GetmaterialMediaid($wx,$data,$wxid,$mid);
|
|
if($is==false){
|
|
exit(json_encode(array('status'=>2,'reg'=>'同步失败')));
|
|
}else{
|
|
db('wechat_material_list')->where('id',$mid)->update(['status'=>2]);
|
|
exit(json_encode(array('status'=>1,'reg'=>'同步公众号成功')));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 更新公众号素材 对应栏目
|
|
public function renewNews(){
|
|
$mid = input('mid');
|
|
$id = input('id');
|
|
$wxid = input('wxid');
|
|
$tcpurl = "http://127.0.0.1:9505";
|
|
$tcparr = array(
|
|
'id'=>$id,
|
|
'mid'=>$mid,
|
|
'type'=>'renewNews',
|
|
'wxid'=>$wxid
|
|
);
|
|
db('wechat_material_list')->where('id',$mid)->update(['status'=>1]);
|
|
pushMessageToClient($tcpurl,json_encode($tcparr));
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功,将同步到公众号')));
|
|
}
|
|
|
|
// 高级群页面
|
|
public function pushshow(){
|
|
$mid = input('mid');
|
|
$list_time = db('wechat_material_time')->where('mid',$mid)->order('id desc')->select();
|
|
$minfo = db('wechat_material_list')->field('wxid,status')->where('id',$mid)->find();
|
|
$this->assign('list_time',$list_time);
|
|
$this->assign('wxid',$minfo['wxid']);
|
|
$this->assign('status',$minfo['status']);
|
|
$this->assign('mid',$mid);
|
|
$this->setMeta('高级群发');
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 高级群发测试推送
|
|
public function ceshiPush(){
|
|
$data = input('');
|
|
if($data){
|
|
import("Wechatpush.Wechatpush", EXTEND_PATH,'.php');
|
|
$wxid = $data['wxid'];
|
|
if($wxid!=0){
|
|
$wx_config = db('wxopen_account')->field('appid,appsecret')->where('id',$wxid)->find();
|
|
$appid = $wx_config['appid'];
|
|
$secret= $wx_config['appsecret'];
|
|
$wx = new \Wechatpush($appid,$secret);
|
|
$media_id = db('media_id')->where(array(
|
|
'wxid'=>$wxid,
|
|
'mid'=>$data['mid']
|
|
))->value('media_id');
|
|
$openid = db('member_userapi')->where('uid',$data['cid'])->value('wxmpid');
|
|
$res = $wx->ceshiPush($openid,$media_id);
|
|
if($res=='发送成功'){
|
|
exit(json_encode(array('status'=>1,'reg'=>'推送成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>$res)));
|
|
}
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'未绑定公众号')));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 高级群发开始
|
|
public function advanced(){
|
|
$data = input('');
|
|
if($data){
|
|
// $is = db('wxpushhistory')->where('mid',$data['mid'])->value('id');
|
|
// if($is){
|
|
// exit(json_encode(array('status'=>2,'reg'=>'该公众号已经发过此素材不能在发')));
|
|
// }
|
|
$tcpurl = "http://127.0.0.1:9505";
|
|
$tcparr = array(
|
|
'mid'=>$data['mid'],
|
|
'type'=>'pushAll',
|
|
'wxid'=>$data['wxid'],
|
|
'pushtype'=>$data['pushtype']
|
|
);
|
|
if($data['intime']!=0){
|
|
//时间段内注册用户
|
|
$tcparr['intime'] = 86400 * $data['intime'];
|
|
}
|
|
pushMessageToClient($tcpurl,json_encode($tcparr));
|
|
exit(json_encode(array('status'=>1,'reg'=>'开始群发,耗时较久')));
|
|
}
|
|
}
|
|
// 高级群发定时推送
|
|
public function advancedtime(){
|
|
$data = input('');
|
|
if($data){
|
|
//var_dump($data);exit;
|
|
// $is = db('wxpushhistory')->where('mid',$data['mid'])->value('id');
|
|
// if($is){
|
|
// exit(json_encode(array('status'=>2,'reg'=>'该公众号已经发过此素材不能在发')));
|
|
// }
|
|
if($data['tasktime']<time()){
|
|
exit(json_encode(array('status'=>2,'reg'=>'时间不对')));
|
|
}
|
|
if($data['intime']=='2'){
|
|
$intimetext = '2天新用户';
|
|
}elseif($data['intime']=='5'){
|
|
$intimetext = '5天新用户';
|
|
}elseif($data['intime']=='7'){
|
|
$intimetext = '7天新用户';
|
|
}else{
|
|
$intimetext = '全部推送';
|
|
}
|
|
$log = array(
|
|
'mid'=>$data['mid'],
|
|
'addtime'=>time(),
|
|
'tktime'=>$data['time'],
|
|
'type'=>$intimetext
|
|
);
|
|
$logid = db('wechat_material_time')->insertGetId($log);
|
|
$tcpurl = "http://127.0.0.1:9505";
|
|
$tcparr = array(
|
|
'mid'=>$data['mid'],
|
|
'type'=>'time',
|
|
'wxid'=>$data['wxid'],
|
|
'pushtype'=>$data['pushtype'],
|
|
'tasktime'=>$data['tasktime'],
|
|
'logid'=>$logid
|
|
);
|
|
if($data['intime']!=0){
|
|
//时间段内注册用户
|
|
$tcparr['intime'] = 86400 * $data['intime'];
|
|
}
|
|
pushMessageToClient($tcpurl,json_encode($tcparr));
|
|
exit(json_encode(array('status'=>1,'reg'=>'定时成功')));
|
|
}
|
|
}
|
|
|
|
//删除高级群发定时
|
|
public function deltimer(){
|
|
$id = input('id');
|
|
if($id){
|
|
$r = db('wechat_material_time')->where('id',$id)->delete();
|
|
if($r){
|
|
exit(json_encode(array('status'=>1,'reg'=>'删除定时成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败请联系杨帅哥')));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 模板消息
|
|
public function template($id){
|
|
$d = db('template_message_material')->where('id',1)->find();
|
|
$wxname = db('wxopen_account')->where('id',$id)->value('title');
|
|
$this->assign('d',$d);
|
|
$this->assign('wxid',$id);
|
|
$this->setMeta('模板消息:'.$wxname);
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 保存素材
|
|
public function saveTemplate(){
|
|
$data = input('');
|
|
if($data){
|
|
$res = db('template_message_material')->where('id',1)->update($data);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'保存成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>$res)));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 模板消息单个发送
|
|
public function templateOne(){
|
|
$data = input('');
|
|
if($data){
|
|
import("Wechatpush.Wechatpush", EXTEND_PATH,'.php');
|
|
$wx_config = db('wxopen_account')->field('appid,appsecret,templateId')->where('id',$data['wxid'])->find();
|
|
if(!$wx_config['templateId']){
|
|
exit(json_encode(array('status'=>2,'reg'=>'该公众号没有绑定模板ID')));
|
|
}
|
|
$appid = $wx_config['appid'];
|
|
$secret= $wx_config['appsecret'];
|
|
$wx = new \Wechatpush($appid,$secret);
|
|
$openid[] = db('member_userapi')->where('uid',$data['cid'])->value('wxmpid');
|
|
$pushinfo = array(
|
|
'template'=>$wx_config['templateId'],
|
|
'link'=>$data['link'],
|
|
'title'=>$data['title'],
|
|
'keyword1'=>$data['keyword1'],
|
|
'keyword2'=>$data['keyword2'],
|
|
'remark'=>$data['remark'],
|
|
'color2'=>$data['colorkeyword1'],
|
|
'color3'=>$data['colorremark']
|
|
);
|
|
$res = $wx->pushTemplate($openid,$pushinfo);
|
|
if($res==1){
|
|
exit(json_encode(array('status'=>1,'reg'=>'推送成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>$res)));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 发送模板消息 需要进程来完成
|
|
public function templatePush(){
|
|
$data = input('');
|
|
if($data){
|
|
$templateId = db('wxopen_account')->where('id',$data['wxid'])->value('templateId');
|
|
if(!$templateId){
|
|
exit(json_encode(array('status'=>2,'reg'=>'该公众号没有绑定模板ID')));
|
|
}
|
|
$tcpurl = "http://127.0.0.1:9508";
|
|
// $tcparr = array(
|
|
// 'wxid'=>$data['wxid'],
|
|
// 'title'=>urlencode($data['title']),
|
|
// 'keyword1'=>urlencode($data['keyword1']),
|
|
// 'keyword2'=>$data['keyword2'],
|
|
// 'link'=>$data['link'],
|
|
// 'remark'=>urlencode($data['remark']),
|
|
// 'color2'=>$data['colorkeyword1'],
|
|
// 'color3'=>$data['colorremark']
|
|
// );
|
|
$tcparr=array(
|
|
'type'=>'all',
|
|
'wxid'=>$data['wxid'],
|
|
'color2'=>$data['colorkeyword1'],
|
|
'color3'=>$data['colorremark']
|
|
);
|
|
pushMessageToClient($tcpurl,urldecode(json_encode($tcparr)));
|
|
exit(json_encode(array('status'=>1,'reg'=>'开始发送模板消息,耗时较久')));
|
|
}
|
|
}
|
|
|
|
// 微信模板消息推送日志
|
|
public function templatehistory($id){
|
|
$data = db('template_history')->where('wxid',$id)->order('id desc')->select();
|
|
foreach($data as $k=>$v){
|
|
$data[$k]['tasktime'] = $this->timestr($v['tasktime']);
|
|
}
|
|
$wxname = db('wxopen_account')->where('id',$id)->value('title');
|
|
$this->assign('data',$data);
|
|
$this->assign('wxname',$wxname);
|
|
$this->setMeta('微信模板消息推送日志 '.$wxname);
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 秒数转时间格式 $t = 秒数
|
|
public function timestr($t){
|
|
$seconds = $t;
|
|
$hours = intval($seconds/3600);
|
|
$time = $hours."小时".gmdate('i分钟s秒', $seconds);
|
|
return $time;
|
|
}
|
|
|
|
|
|
//关注回复
|
|
public function reply(){
|
|
$wxid = input("id");
|
|
$list = db('wxreply_message')->where('wxid',$wxid)->order('id asc')->select();
|
|
|
|
$this->assign('list',$list);
|
|
$this->assign('wxid',$wxid);
|
|
$this->setMeta('关注回复设置');
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 添加关注回复素材
|
|
public function addreply(){
|
|
$wxid = input('wxid');
|
|
$data = input('');
|
|
if(isset($data['Title'])){
|
|
$res = db('wxreply_message')->insert($data);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'添加成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
}else{
|
|
$this->assign('wxid',$wxid);
|
|
$this->setMeta('关注回复素材添加');
|
|
return $this->fetch();
|
|
}
|
|
|
|
}
|
|
|
|
//设置选择关注回复的图文列表
|
|
public function setreplist(){
|
|
$rlist = input('rlist');
|
|
$nlist = input('nlist');
|
|
$rlist = explode(',',$rlist);
|
|
$nlist = explode(',',$nlist);
|
|
foreach($rlist as $k=>$v){
|
|
db('wxreply_message')->where('id',$v)->update(['status'=>1]);
|
|
}
|
|
foreach($nlist as $k=>$v){
|
|
db('wxreply_message')->where('id',$v)->update(['status'=>0]);
|
|
}
|
|
exit(json_encode(array('status'=>1,'reg'=>'设置成功')));
|
|
}
|
|
|
|
// 删除关注回复素材
|
|
public function delreply(){
|
|
$id = input('id');
|
|
if($id){
|
|
$img = db('wxreply_message')->where('id',$id)->value('PicUrl');
|
|
$res = db('wxreply_message')->where('id',$id)->delete();
|
|
if($res){
|
|
@unlink(parseurl($img));
|
|
exit(json_encode(array('status'=>1,'reg'=>'删除成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>1,'reg'=>'失败')));
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// 编辑关注回复素材
|
|
public function replyedit(){
|
|
$id = input('id');
|
|
$data = input('');
|
|
if(isset($data['Title'])){
|
|
$id = $data['id'];
|
|
unset($data['id']);
|
|
$res = db('wxreply_message')->where('id',$id)->update($data);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
}else{
|
|
$data = db('wxreply_message')->where('id',$id)->find();
|
|
$this->assign('data',$data);
|
|
$this->setMeta('编辑');
|
|
return $this->fetch();
|
|
}
|
|
}
|
|
|
|
// 微信公众号菜单栏设置
|
|
public function menu(){
|
|
$wxid = input('id');
|
|
$wxname = db('wxopen_account')->where('id',$wxid)->value('title');
|
|
$data = db('wechat_menu')->where('wxid',$wxid)->value('nav');
|
|
if($data){
|
|
$init = 1;
|
|
}else{
|
|
$init = 0;
|
|
$data = 0;
|
|
}
|
|
//公众号列表
|
|
$wxlist = db('wxopen_account')->field('id,title')->select();
|
|
$this->assign('wxlist',$wxlist);
|
|
$this->assign('wxid',$wxid);
|
|
$this->assign('init',$init);
|
|
$this->assign('data',$data);
|
|
$this->assign('wxname',$wxname);
|
|
$this->setMeta('公众号菜单');
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 保存菜单
|
|
public function addmenu(){
|
|
$data = input('menu');
|
|
$wxid = input('wxid');
|
|
$data = str_replace('null,','',$data);
|
|
|
|
// $list = json_decode($data);
|
|
// foreach ($list->menu->button as $k => $v) {
|
|
// if (!empty($v->key)) {
|
|
// unset($v->url);
|
|
// $v->type = 'click';
|
|
// }
|
|
// if ($v->sub_button) {
|
|
// foreach ($v->sub_button as $i => $j) {
|
|
// if (!empty($j->key)) {
|
|
// unset($j->url);
|
|
// $j->type = 'click';
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
// $data = json_encode($list);
|
|
$is = db('wechat_menu')->where('wxid',$wxid)->value('id');
|
|
if($is){
|
|
$res = db('wechat_menu')->where('wxid',$wxid)->update(['nav'=>$data]);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
}else{
|
|
$arr = array(
|
|
'wxid'=>$wxid,
|
|
'nav'=>$data
|
|
);
|
|
$res = db('wechat_menu')->insert($arr);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//重置菜单
|
|
public function resetmenu(){
|
|
$wxid = input('wxid');
|
|
if($wxid){
|
|
$r = db('wechat_menu')->where('wxid',$wxid)->delete();
|
|
if($r){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'无需重置')));
|
|
}
|
|
}
|
|
}
|
|
|
|
//同步菜单到公众号
|
|
public function addWxMenu(){
|
|
$wxid = input('wxid');
|
|
if($wxid){
|
|
$nav = db('wechat_menu')->where('wxid',$wxid)->value('nav');
|
|
$nav = json_decode($nav,true);
|
|
$data = array();
|
|
$data = $nav['menu'];
|
|
//遍历里面的菜单名称需要url转码
|
|
foreach($nav['menu'] as $k=>$v){
|
|
foreach($v as $k2=>$v2){
|
|
$data[$k][$k2]['name'] = urlencode($v2['name']);
|
|
if(isset($data[$k][$k2]['kay'])){
|
|
$data[$k][$k2]['kay'] = urlencode($v2['kay']);
|
|
}
|
|
if($v2['sub_button']){
|
|
foreach($v2['sub_button'] as $k3=>$v3){
|
|
$data[$k][$k2]['sub_button'][$k3]['name'] = urlencode($v3['name']);
|
|
if(isset($data[$k][$k2]['sub_button'][$k3]['key'])){
|
|
$data[$k][$k2]['sub_button'][$k3]['key'] = urlencode($v3['key']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
import("Wechatpush.Wechatpush", EXTEND_PATH,'.php');
|
|
$wx_config = db('wxopen_account')->field('appid,appsecret')->where('id',$wxid)->find();
|
|
$appid = $wx_config['appid'];
|
|
$secret= $wx_config['appsecret'];
|
|
$wx = new \Wechatpush($appid,$secret);
|
|
$res = $wx->wechatnav($data);
|
|
$res = json_decode($res,true);
|
|
if($res['errcode']=='0'){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败','code'=>$res['errcode'])));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function menu_text(){
|
|
$wxid = input('id');
|
|
$wxname = db('wxopen_account')->where('id',$wxid)->value('title');
|
|
$data = db('wechat_menu_text')->where('wxid',$wxid)->select();
|
|
if ($data) {
|
|
}
|
|
$this->assign('wxid',$wxid);
|
|
$this->assign('data',$data);
|
|
$this->assign('wxname',$wxname);
|
|
$this->setMeta('菜单回复');
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function add_menu_text(){
|
|
$wxid = input('wxid');
|
|
if (IS_POST) {
|
|
$data = input('post.');
|
|
if (!$data['name']) {
|
|
exit(json_encode(array('status'=>2,'reg'=>'标题不能为空')));
|
|
}
|
|
if (!$data['text']) {
|
|
exit(json_encode(array('status'=>2,'reg'=>'内容不能为空')));
|
|
}
|
|
$res = db('wechat_menu_text')->insert($data);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
} else {
|
|
$this->assign('wxid',$wxid);
|
|
$this->setMeta('新增菜单回复');
|
|
return $this->fetch();
|
|
}
|
|
}
|
|
|
|
public function edit_menu_text(){
|
|
$id = input('id');
|
|
$data = db('wechat_menu_text')->where('id',$id)->find();
|
|
if (IS_POST) {
|
|
$data = input('post.');
|
|
if (!$data['name']) {
|
|
exit(json_encode(array('status'=>2,'reg'=>'标题不能为空')));
|
|
}
|
|
if (!$data['text']) {
|
|
exit(json_encode(array('status'=>2,'reg'=>'内容不能为空')));
|
|
}
|
|
$res = db('wechat_menu_text')->update($data);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
} else {
|
|
$this->assign('data',$data);
|
|
$this->setMeta('更新菜单回复');
|
|
return $this->fetch();
|
|
}
|
|
}
|
|
|
|
// 删除
|
|
public function del_menu_text(){
|
|
$id = input('id');
|
|
if($id){
|
|
$res = db('wechat_menu_text')->delete($id);
|
|
if($res){
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}else{
|
|
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
|
}
|
|
}
|
|
}
|
|
|
|
//复制高级群发素材到其他公众号
|
|
public function copyadvanced(){
|
|
$data = input('');
|
|
$list = explode(',',$data['wxlist']);
|
|
$one = db('wechat_material_list')->where('id',$data['dataid'])->find();
|
|
$datalist = db('wechat_material')->where('mid',$data['dataid'])->order('id asc')->select();
|
|
foreach($list as $k=>$v){
|
|
$mid = db('wechat_material_list')->insertGetId(array(
|
|
'imgurl'=>$one['imgurl'],
|
|
'title'=>$one['title'],
|
|
'addtime'=>time(),
|
|
'wxid'=>$v
|
|
));
|
|
if($mid){
|
|
foreach($datalist as $k2=>$v2){
|
|
db('wechat_material')->insert(array(
|
|
'title'=>$v2['title'],
|
|
'author'=>$v2['author'],
|
|
'show_cover_pic'=>$v2['show_cover_pic'],
|
|
'content'=>$v2['content'],
|
|
'content_source_url'=>$v2['content_source_url'],
|
|
'addtime'=>time(),
|
|
'mid'=>$mid,
|
|
'thumb_url'=>$v2['thumb_url'],
|
|
'index'=>$v2['index'],
|
|
'wxid'=>$v,
|
|
'bot_url'=>$v2['bot_url'],
|
|
'wximgurl'=>$v2['wximgurl']
|
|
));
|
|
}
|
|
}
|
|
}
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}
|
|
|
|
//复制菜单到其他公众号
|
|
public function copymenu(){
|
|
$data = input('');
|
|
$list = explode(',',$data['wxlist']);
|
|
$menu = db('wechat_menu')->where('wxid',$data['wxid'])->find();
|
|
$text = db('wechat_menu_text')->where('wxid',$data['wxid'])->order('id asc')->find();
|
|
foreach($list as $k=>$v){
|
|
$is = db('wechat_menu')->where('wxid',$v)->find();
|
|
if($is){
|
|
db('wechat_menu')->where('wxid',$v)->update(array(
|
|
'nav'=>$menu['nav']
|
|
));
|
|
if($text){
|
|
db('wechat_menu_text')->where('wxid',$v)->update(array(
|
|
'name'=>$text['name'],
|
|
'text'=>$text['text']
|
|
));
|
|
}
|
|
}else{
|
|
db('wechat_menu')->insert(array(
|
|
'wxid'=>$v,
|
|
'nav'=>$menu['nav']
|
|
));
|
|
if($text){
|
|
db('wechat_menu_text')->insert(array(
|
|
'wxid'=>$v,
|
|
'name'=>$text['name'],
|
|
'text'=>$text['text']
|
|
));
|
|
}
|
|
}
|
|
}
|
|
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
|
}
|
|
|
|
|
|
//字节转Emoji表情
|
|
public function bytes_to_emoji($cp){
|
|
if ($cp > 0x10000){ # 4 bytes
|
|
return chr(0xF0 | (($cp & 0x1C0000) >> 18)).chr(0x80 | (($cp & 0x3F000) >> 12)).chr(0x80 | (($cp & 0xFC0) >> 6)).chr(0x80 | ($cp & 0x3F));
|
|
}else if ($cp > 0x800){ # 3 bytes
|
|
return chr(0xE0 | (($cp & 0xF000) >> 12)).chr(0x80 | (($cp & 0xFC0) >> 6)).chr(0x80 | ($cp & 0x3F));
|
|
}else if ($cp > 0x80){ # 2 bytes
|
|
return chr(0xC0 | (($cp & 0x7C0) >> 6)).chr(0x80 | ($cp & 0x3F));
|
|
}else{ # 1 byte
|
|
return chr($cp);
|
|
}
|
|
}
|
|
|
|
|
|
public function img_mid()
|
|
{
|
|
// $list = db('wxopen_account')->select();
|
|
// foreach ($list as $k => $v) {
|
|
// $appid = $v['appid'];
|
|
// $secret= $v['appsecret'];
|
|
// import("Wechatpush.Wechatpush", EXTEND_PATH,'.php');
|
|
// $wx = new \Wechatpush($appid,$secret);
|
|
// $res = $wx->uploadImage('mid.jpg');
|
|
// db('wxopen_account')->where(array('id'=>$v['id']))->update(['midimg'=>$res]);
|
|
// // var_dump($res);
|
|
// }
|
|
}
|
|
} |