Browse Source

公众号类:
1. 增加方法 批量移动用户分组
2. 修改方法 创建二维码。支持创建使用字符串id的永久二维码

binsee 10 years ago
parent
commit
db5080b222
3 changed files with 34 additions and 4 deletions
  1. 1 0
      README.md
  2. 32 4
      wechat.class.php
  3. 1 0
      wiki/官方API类库.md

+ 1 - 0
README.md

@@ -181,6 +181,7 @@ const EVENT_CARD_USER_DEL = 'user_del_card';        //卡券 - 用户删除卡
  *  createGroup($name) 新增自定分组 
  *  updateGroup($groupid,$name) 更改分组名称 
  *  updateGroupMembers($groupid,$openid) 移动用户分组  
+ *  batchUpdateGroupMembers($groupid,$openid_list) 批量移动用户分组 
  *  sendCustomMessage($data) 发送客服消息  
  *  getOauthRedirect($callback,$state,$scope) 获取网页授权oAuth跳转地址  
  *  getOauthAccessToken() 通过回调的code获取网页授权access_token  

+ 32 - 4
wechat.class.php

@@ -93,6 +93,7 @@ class Wechat
 	const GROUP_CREATE_URL='/groups/create?';
 	const GROUP_UPDATE_URL='/groups/update?';
 	const GROUP_MEMBER_UPDATE_URL='/groups/members/update?';
+	const GROUP_MEMBER_BATCHUPDATE_URL='/groups/members/batchupdate?';
 	const CUSTOM_SEND_URL='/message/custom/send?';
 	const MEDIA_UPLOADNEWS_URL = '/media/uploadnews?';
 	const MASS_SEND_URL = '/message/mass/send?';
@@ -1721,17 +1722,18 @@ class Wechat
 
 	/**
 	 * 创建二维码ticket
-	 * @param int $scene_id 自定义追踪id
-	 * @param int $type 0:临时二维码;1:永久二维码(此时expire参数无效)
+	 * @param int|string $scene_id 自定义追踪id,临时二维码只能用数值型
+	 * @param int $type 0:临时二维码;1:永久二维码(此时expire参数无效);2:永久二维码(此时expire参数无效)
 	 * @param int $expire 临时二维码有效期,最大为1800秒
 	 * @return array('ticket'=>'qrcode字串','expire_seconds'=>1800,'url'=>'二维码图片解析后的地址')
 	 */
 	public function getQRCode($scene_id,$type=0,$expire=1800){
 		if (!$this->access_token && !$this->checkAuth()) return false;
+		$type = ($type && is_string($scene_id))?2:$type;
 		$data = array(
-			'action_name'=>$type?"QR_LIMIT_SCENE":"QR_SCENE",
+			'action_name'=>$type?($type == 2?"QR_LIMIT_STR_SCENE":"QR_LIMIT_SCENE"):"QR_SCENE",
 			'expire_seconds'=>$expire,
-			'action_info'=>array('scene'=>array('scene_id'=>$scene_id))
+			'action_info'=>array('scene'=>($type == 2?array('scene_str'=>$scene_id):array('scene_id'=>$scene_id)))
 		);
 		if ($type == 1) {
 			unset($data['expire_seconds']);
@@ -2002,6 +2004,32 @@ class Wechat
 	}
 
 	/**
+	 * 批量移动用户分组
+	 * @param int $groupid 分组id
+	 * @param string $openid_list 用户openid数组,一次不能超过50个
+	 * @return boolean|array
+	 */
+	public function batchUpdateGroupMembers($groupid,$openid_list){
+		if (!$this->access_token && !$this->checkAuth()) return false;
+		$data = array(
+				'openid_list'=>$openid_list,
+				'to_groupid'=>$groupid
+		);
+		$result = $this->http_post(self::API_URL_PREFIX.self::GROUP_MEMBER_BATCHUPDATE_URL.'access_token='.$this->access_token,self::json_encode($data));
+		if ($result)
+		{
+			$json = json_decode($result,true);
+			if (!$json || !empty($json['errcode'])) {
+				$this->errCode = $json['errcode'];
+				$this->errMsg = $json['errmsg'];
+				return false;
+			}
+			return $json;
+		}
+		return false;
+	}
+
+	/**
 	 * 发送客服消息
 	 * @param array $data 消息结构{"touser":"OPENID","msgtype":"news","news":{...}}
 	 * @return boolean|array

+ 1 - 0
wiki/官方API类库.md

@@ -150,6 +150,7 @@ const EVENT_CARD_USER_DEL = 'user_del_card';        //卡券 - 用户删除卡
  *  createGroup($name) 新增自定分组 
  *  updateGroup($groupid,$name) 更改分组名称 
  *  updateGroupMembers($groupid,$openid) 移动用户分组  
+ *  batchUpdateGroupMembers($groupid,$openid_list) 批量移动用户分组 
  *  sendCustomMessage($data) 发送客服消息  
  *  getOauthRedirect($callback,$state,$scope) 获取网页授权oAuth跳转地址  
  *  getOauthAccessToken() 通过回调的code获取网页授权access_token