微信二次开发给粉丝创建标签、打标签

 //创建标签
	    public function createTag($tagname=''){
        $mp=$this->mp;
        $tagname="121";
        //检查数据库中是否有,没有把tag_id和tag写到库中
        $where['mp_id']=$mp['id'];
        $where['tag']=$tagname;
        $data=M('tags')->where($where)->find();
         // dump($data);
	    // exit;
        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=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);
                echo "创建标签成功";
            }else{
            	echo "创建标签失败";
            }

        }
     }

创建标签之后为粉丝打标签

//给粉丝打标签
	public function openidTag(){
		$openid = "oIpD80lfam7GJBpIFW695u77tnvA";
		//给粉丝打标签	
        $api = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=" . getAccess_token();
		
		 $arr['openid_list'] = array($openid);
       $arr['tagid'] = 103;
       $json = json_encode($arr);
		// echo $json;
		// exit;
		 include APP_PATH . 'LaneWeChat/lanewechat.php';
       $ret = \LaneWeChat\Core\Curl::callWebServer($api,$json,'POST');
       print_r($ret);
   
	}

你可能感兴趣的:(微信二次开发给粉丝创建标签、打标签)