微信掃描帶引數的二維碼關注公眾號自動分組
阿新 • • 發佈:2019-01-06
今天學習了建立帶引數的二維碼並建立標籤,掃描帶引數的二維碼後自動分組到所在的標籤中。
首先,先建立帶引數的二維碼,程式碼如下:
public function qrcodeAdd(){ if(IS_GET){ $this->display('qrcode_add'); }else{ $mp = getCurrentMp(); $data = I('post.'); $data['mp_id'] = $mp['id']; $id = M('qrcode')->add($data); include APP_PATH . 'LaneWeChat/lanewechat.php'; $ret = Popularize::createTicket($data['qr_type'],$data['expire'],$data['scene_str']); // dump($ret); // exit; if(isset($ret['ticket'])){ $ticket = $ret['ticket']; $qrcodefile = Popularize::getQrcode($ticket); $ret['src'] = $qrcodefile; $ret['create_time'] = time(); // dump($ret); // exit; $model = M('qrcode')->where("id = $id")->save($ret); $this->ajaxReturn(array('status'=>1,'msg'=>'ok','url'=>U('index'))); }else{ $this->ajaxReturn(array('status'=>0,'msg'=>$ret)); } } }
生成二維碼同時建立標籤
public function createTag($tagname=""){ $mp = getCurrentMp(); //查庫,是否有,沒有建立,把tag和tag_id寫到庫中 $where['mp_id'] = $mp['id']; $where['tag'] = $tagname; $data = M("tags")->where($where)->find(); if(empty($data)){ $api="https://api.weixin.qq.com/cgi-bin/tags/create?access_token=".getAccess_token(); $arr = array(); $arr['tag']['name']=$tagname; $json = json_encode($arr,JSON_UNESCAPED_UNICODE); // echo $json; // exit; include APP_PATH . 'LaneWeChat/lanewechat.php'; $ret = \LaneWeChat\Core\Curl::callWebServer($api,$json,'POST'); if($ret['tag']){ $row['mp_id']=$mp['id']; $row['tag_id']=$ret['tag']['id']; $row['tag']=$ret['tag']['name']; M('tags')->add($row); } } }
將粉絲分標籤
然後上傳伺服器,關注會自動回覆分組。//給粉絲打標籤 public function OpenidTag(){ $openid = ""; //獲取access_token $accessToken = getAccess_token(); include APP_PATH . 'LaneWeChat/lanewechat.php'; $api = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=$accessToken"; $arr = array(); $arr['openid_list'] = $openid; $arr['tagid'] = 102; $arr = json_encode($arr,JSON_UNESCAPED_UNICODE); // echo $arr; // exit; $ret = Curl::callWebServer($api,$arr,'post'); print_r($ret); }