/** * 修改客服帐号 * @param string $account 客服帐号(可忽略后缀) * @param string $nickname 昵称 * @param string $password 登录密码(未加密) * @return boolean true表示成功 * @throws ApiException */ public function update($account, $nickname, $password) { $json = array('kf_account' => $this->addPostfix($account), 'nickname' => urlencode($nickname), 'password' => md5($password)); $url = $this->url . '/update?access_token=' . $this->accessToken; $httpClient = new HttpClient($url); $httpClient->setBody(urldecode(json_encode($json))); $httpClient->post(); return $this->checkErrcode($httpClient); }
/** * 设置用户备注名 * @param string $openId 用户openid * @param string $remark 备注名,小于30字符 * @return boolean 设置成功返回true * @throws ApiException */ public function setRemark($openId, $remark) { $url = $this->url . '/info/updateremark?access_token=' . $this->accessToken; $json = array('openid' => $openId, 'remark' => urlencode($remark)); $httpClient = new HttpClient($url); $httpClient->setBody(urldecode(json_encode($json))); $httpClient->post(); $result = $httpClient->jsonToArray(); if (isset($result['errcode']) && $result['errcode'] == 0) { return true; } else { throw ApiException::throws(ApiException::ERROR_JSON_ERROR_CODE, 'response: ' . $httpClient->getResponse()); } }
/** * 移动用户分组 * @param string $openidList 用户openid * @param string $toGroupId 目标分组id * @return boolean true表示成功 * @throws ApiException */ public function moveUser($openidList, $toGroupId) { $json = array('openid' => $openidList, 'to_groupid' => intval($toGroupId)); $httpClient = new HttpClient($this->url . '/members/update?access_token=' . $this->accessToken); $httpClient->setBody(json_encode($json)); $httpClient->post(); $result = $httpClient->jsonToArray(); if (isset($result['errcode']) && $result['errcode'] == 0) { //errcode!=0已在checkErrcode检验 return true; } else { throw ApiException::throws(ApiException::ERROR_JSON_ERROR_CODE, 'response: ' . $httpClient->getResponse()); } return false; }
/** * 测试个性化菜单 * @param string $userId 用户openId或微信号 * @param boolean $assocArray 可选,false则直接返回API的结果(默认true返回解析后的数组) * @return string/array 查询后的结果 */ public function test($userId, $assocArray = true) { $url = $this->url . '/trymatch?access_token=' . $this->accessToken; $httpClient = new HttpClient($url); $httpClient->setBody(json_encode(array('user_id' => $userId))); $httpClient->post(); if ($httpClient->getStatus() != 200 || $httpClient->getResponse() == '') { throw ApiException::throws(ApiException::HTTP_ERROR_CODE, 'status code: ' . $httpClient->getStatus()); return false; } if (!$assocArray) { //直接返回API接口的结果 return $httpClient->getResponse(); } $result = $httpClient->jsonToArray(); return $result; }
private function sendToTarget($jsonArr) { $url = $this->url . $this->accessToken; $httpClient = new HttpClient($url); $httpClient->setBody(urldecode(json_encode($jsonArr))); $httpClient->post(); $result = $httpClient->jsonToArray(); if (isset($result['errcode']) && $result['errcode'] == 0) { return true; } else { throw ApiException::throws(ApiException::ERROR_JSON_ERROR_CODE, 'response: ' . $httpClient->getResponse()); } //never return false; }