回复图片
public function addImage(){
if(IS_GET){
$this->display('replyimage');
}else{
$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);
// dump($ret);
// exit;
if (isset($ret['media_id'])) {
$mp = $this->mp;
$mp_id = $mp['id'];
$data['url'] = $url;
$data['media_id'] = $ret['media_id'];
$imgret = M('mp_reply_image')->add($data);
if ($imgret) {
$data['keyword'] = I('post.keyword');
$data['reply_id'] = $imgret;
$data['mp_id'] = $mp_id;
$data['type'] = 'image';
if ($mp['is_use'] == 1){
$data['status'] = 1;
}else{
$data['status'] = 0;
}
$ret = M('mp_rule')->add($data);
if ($ret) {
$this->ajaxReturn(array('status'=>1,'msg'=>'添加成功!'));
}else{
$this->ajaxReturn(array('status'=>1,'msg'=>$ret));
}
}
}else{
$this->ajaxReturn(array('msg'=>$ret));
}
}
}
回复图文
public function addNews(){
if(IS_GET){
$this->display();
}else{
$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('status'=>1,'msg'=>'添加成功!'));
}else{
$this->ajaxReturn(array('status'=>1,'msg'=>$ret));
}
}
}else{
$this->ajaxReturn(array('msg'=>$ret));
}
}
}