批量给用户打标签的接口如下。
https:// api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=ACCESS_TOKEN
接口运行时,提交POST数据的例子如下。
{ "openid_list":[ "oiPuduGV7gJ_MOSfAWpVmhhgXh-U", "oiPuduBAk2wcGe8QH955kbDZctOg" ], "tagid":103}
请求参数说明如表6-5所示。
表6-5 给用户打标签请求的参数说明
该接口的核心代码实现如下。
1 $access_token = "-4fPq655nSH7ruHqEIIAxVyDpbRZFL4yPudfMuVhcin5PorYwWiTL7RZNuNlsS w_z_MDK5HCd4IKP0VpPBSLID41kWMOKvT1OBXvgt2UjeG1hZhdBuTF9DpG0XcMAG35ZAVjAIALMH"; 2 3 $data = '{ 4 "openid_list":[ 5 "oiPuduJnJSC0D3Eet7_i2IJwj-5k", 6 "oiPuduBAk2wcGe8QH955kbDZctOg" 7 ], 8 "tagid":103 9 }';10 $url = "https:// api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token= $access_token";11 $result = https_request($url, $data);12 var_dump($result);13 14 function https_request($url, $data = null)15 {16 $curl = curl_init;17 curl_setopt($curl, CURLOPT_URL, $url);18 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);19 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);20 if (!empty($data)){21 curl_setopt($curl, CURLOPT_POST, 1);22 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);23 }24 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);25 $output = curl_exec($curl);26 curl_close($curl);27 return $output;28 }
上述代码执行后,返回的结果如下。
{"errcode": 0, "errmsg": "ok"}