微信公众号创建带参数的二维码,为扫带参数二维码的粉丝打标签

1.创建带参数的二维码:①微信接口
http请求方式:POST(请使用https协议)
https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN

POST数据示例:

{   "tag" : {     "name" : "广东"//标签名   } }

返回说明(正常时返回的json数据包示例)

{   "tag":{ "id":134,//标签id "name":"广东"   } }

2.为扫带参数的二维码的粉丝打标签

接口调用请求说明

http请求方式:POST(请使用https协议)
https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=ACCESS_TOKEN

POST数据例子正确返回:

{   "openid_list" : [//粉丝列表    
"ocYxcuAEy30bX0NXmGn4ypqx3tI0",    
"ocYxcuBt0mRugKZ7tGAHPnUaOW7Y"   ],   
"tagid" : 134 }
代码如下:
public function qrcodeAdd(){
		if(IS_GET){
			$this->display('qrcode_add');
		}else{
			$data = I('post.');
			// print_r($data);
			// exit;
			$scene_str = $data['scene_str'];
			$expire = $data['expire'];
			// echo $expire;
			// exit;
			$type = $data['qr_type'];
			// echo $type;
			// exit;
			$this->createtag($scene_str);
			$mp = getCurrentMp();
			$data['mp_id'] = $mp['id'];
			$id = M('mp_qrcode')->add($data);
			$ret = Popularize::createTicket($type,$expire,$scene_str);
			// print_r($ret);
			if(isset($ret['ticket'])){
				$temp = Popularize::getQrcode($ret['ticket']);
				// echo $temp;
				// exit;
				$ret['src'] = str_replace("./" , "/",$temp);
				$ret['create_time'] = time();
				$result = M('mp_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=""){
		// $tagname = "国庆";
		$mp = getCurrentMp();
		$mp_id = $mp['id'];
		$where['mp_id'] = $mp_id;
		$where['tag'] = $tagname;
		$ret = M('mp_tags')->where($where)->select();
		// print_R($ret);
		// exit;
		
		// print_r($data);
		// exit;
		
		if(empty($ret)){
			$access_token = getAccess_token();
			$queryurl = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token=$access_token";
			$arr['tag']['name'] = $tagname; 
			$data = json_encode($arr,JSON_UNESCAPED_UNICODE);
			$result = Curl::callWebServer($queryurl, $data, 'POST');
			// print_r($result);
			// exit;
			if(isset($result['tag']['id'])){
				$arr1['tag_id'] = $result['tag']['id'];
				$arr1['tag'] = $result['tag']['name'];
				$arr1['mp_id'] = $mp_id;
				$temp = M('mp_tags')->add($arr1);
			}
		}
	}

你可能感兴趣的:(微信)