public function replyText(){
$data['content']=I('content');
$replyid=M('mp_reply_text' )->add($data);
if($replyid){
$mp = $this->mp;
$arr['keyword']=I('keyword');
$arr['reply_id'] = $replyid;
$arr['mp_id'] = $mp['id'];
$arr['type'] = 'text';
$ret = M('mp_rule')->add($arr);
if ($ret) {
$this->ajaxReturn(array('msg'=>'添加成功!','url'=>U('index')));
}else{
}
}else{
}
}
public function image(){
$this->display('replyimage');
}
public function replyImage(){
$keyword=I('post.keyword');
$media_id=I('post.media_id');
$url=I('post.url');
if(empty($keyword) || empty($url)){
$this->ajaxReturn(array('status'=>0,'msg'=>'必须输入关键字和选择图片'));
}
if(empty($media_id)){
$access_token=getAccess_token();
include APP_PATH . 'LaneWeChat/lanwechat.php';
$api = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$access_token&type=image";
$file=realpath('.'.$url);
$data['media']=Curl::addFile($file);
// var_dump($data);
// exit;
$ret=Curl::callWebServer($api,$data,'post',1,0);
//上传成功
if(isset($ret['media_id'])){
$media_id=$ret['media_id'];
$url=$ret['url'];
}else{
$ret['fail']='本地图片上传公众平台失败';
$this->ajaxReturn(array('status'=>1,'msg'=>$ret));
exit;
}
}
$data['media_id']=$media_id;
$data['url']=$url;
$reply_id=M('mp_reply_image')->add($data);
$mp=$this->mp;
$arr['mp_id']=$mp['id'];
$arr['type']='image';
$arr['keyword']=$keyword;
$arr['reply_id']=$reply_id;
$ret=M('mp_rule')->add($arr);
if($ret){
$this->ajaxReturn(array('msg'=>'添加成功!','url'=>('image')));
}
}
public function news(){
$this->display('replynews');
}
public function replynews(){
$data = array();
$url = I('post.url'); //图片路径
$file = realpath('.' . $url); //相对路径转绝对路径
$access_token = getAccess_token();
include APP_PATH .'LaneWeChat/lanewechat.php';
$url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$access_token&type=image";
$data['media'] = '@'.$file;
$ret = Curl::callWebServer($url,$data,'post',true,false);
if (isset($ret['media_id'])) {
$mp = $this->mp;
$mp_id = $mp['id'];
$data['picurl'] = $ret['url'];
$data['title'] = I('post.title');
$data['description'] = I('post.content');
$data['url'] = I('content_source_url');
$newsret = M('mp_reply_news')->add($data);
if ($newsret) {
$data['keyword'] = I('post.keyword');
$data['reply_id'] = $newsret;
$data['mp_id'] = $mp_id;
$data['type'] = 'news';
if ($mp['is_use'] == 1){
$data['status'] = 1;
}else{
$data['status'] = 0;
}
$ret = M('mp_rule')->add($data);
if ($ret) {
$this->ajaxReturn(array('msg'=>'添加成功!','url'=>('news')));
}else{
$this->ajaxReturn(array('msg'=>$ret));
}
}
}else{
$this->ajaxReturn(array('msg'=>$ret));
}
}
微信开发--消息回复(文本,图片,图文)
最新推荐文章于 2024-09-17 19:13:12 发布
3706

被折叠的 条评论
为什么被折叠?



