设置客服帐号的头像
@param string $kf_account 客户账号
@param string $image 头像文件位置
@return array
@throws Exceptions\InvalidResponseException
@throws Exceptions\LocalCacheException
173809
public function uploadHeadimg($kf_account, $image)
    {
        $url = "http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=ACCESS_TOKEN&kf_account={$kf_account}";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, ['media' => Tools::createCurlFile($image)]);
    }
320673
public static function output(&$image, $type = 'png', $filename = null, $quality = 100)
    {
        $type == 'jpg' && $type = 'jpeg';
        $imageFun = "image{$type}";
        if (is_null($filename)) { //输出到浏览器
            header("Content-type: image/{$type}");
            ($type == 'jpeg') ? $imageFun($image, null, $quality) : $imageFun($image);
        } else { //保存到文件
            ($type == 'jpeg') ? $imageFun($image, $filename, $quality) : $imageFun($image, $filename);
        }
        imagedestroy($image);
        exit();
    }
943931
private static function encode($image)
    {
        // 网址 ?

        // 本地路径 ? is_file file_exists()

        // base64 编码 ? not support

        // 文件内容 ?

        // 资源 ? is_resource

        // SplFileInfo ? instanceof SplFileInfo

        $content = Is::is_image($image, null, true);

        if ($content) {
            return $content;
        } else {
            throw new TencentAIException(90301);
        }
    }
115703
public function addKFAccount($account,$nickname,$password){
        $data=array(
            "kf_account" =>$account,
            "nickname" => $nickname,
            "password" => md5($password)
        );
        if (!$this->access_token && !$this->checkAuth()) return false;
        $result = $this->http_post(self::API_BASE_URL_PREFIX.self::CS_KF_ACCOUNT_ADD_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;
    }
1189113
public function addImage(string $image)
    {
        $url = self::ADD_IMAGE.$this->access_token;
        $this->curl->setOpt(CURLOPT_SAFE_UPLOAD, true);

        return Response::json($this->curl->post($url, [
            'media' => new \CURLFile($image),
        ]));
    }
321127
public function get($account, $action = '', $parameters = null, $acceptableContentTypes = null)
    {
        if (is_array($account)) {
            $tmp_results = array();
            foreach ($account as $accnt) {
                $result = $this->sendRequest('GET', $accnt, $action, $parameters, null, $acceptableContentTypes);
                if ($result === false) {
                    return false;
                }
                $tmp_results[ $accnt ] = $result;
            }
            
            return $tmp_results;
        }
        
        return $this->sendRequest('GET', $account, $action, $parameters, null, $acceptableContentTypes);
    }
1035713
public function get_kf_records($starttime, $endtime, $pageindex, $pagesize)
    {
        $url = self::API_DOMAIN . 'customservice/msgrecord/getrecord?access_token=' . $this->get_access_token();
        $xml = sprintf('{'.
                    '"endtime" : %s,'.
                    '"pageindex" : %s,'.
                    '"pagesize" : %s,'.
                    '"starttime" : %s}',
                    $endtime,
                    $pageindex,
                    $pagesize,
                    $starttime);
        $res = HttpCurl::post($url, $xml, 'json');
        // 异常处理: 获取时网络错误
        if ($res === false) {
            return Error::code('ERR_GET');
        }
        // 判断是否调用成功
        if (isset($res->recordlist)) {
            return array(null, $res->recordlist);
        } else {
            return array($res, null);
        }
    }
1232613
public function del_kf($kf_account)
    {
        $url = self::API_DOMAIN . 'customservice/kfaccount/del?access_token=' . $this->get_access_token() . '&kf_account=' . $kf_account;
        $res = HttpCurl::get($url, 'json');
        // 异常处理: 获取时网络错误
        if ($res === false) {
            return Error::code('ERR_GET');
        }        
        // 判断是否调用成功
        if ($res->errcode == 0) {
            return array(null, true);
        } else {
            return array($res, null);
        }
    }
1196016
private function imageUpload(AbstractLocalImage $image)
    {
        $imageClient = $this->getRokkaClient();
        $metadata = $this->callbacks->getMetadata($image);
        if (0 === \count($metadata)) {
            $metadata = null;
        }
        $content = $image->getContent();
        if (null !== $content) {
            $filename = $image->getFilename();
            if (null === $filename) {
                $filename = 'unknown';
            }
            $answer = $imageClient->uploadSourceImage(
                $content,
                $filename,
                '',
                $metadata
            );
            $sourceImages = $answer->getSourceImages();
            if (\count($sourceImages) > 0) {
                return $sourceImages[0];
            }
        }

        return null;
    }
1372442
public function selectMainImage(Image $image)
    {
        if (!$this->images->findImageByUUID($image->getMediaObjectId())) {
            throw new \InvalidArgumentException('You can not select a random image to be main, it has to be added to the item.');
        }

        $oldMainImage = $this->images->getMain();

        if (!isset($oldMainImage) || $oldMainImage->getMediaObjectId() !== $image->getMediaObjectId()) {
            $this->apply(
                $this->createMainImageSelectedEvent($image)
            );
        }
    }
828777
public function tableRecognition($image, $options=array(), $timeout=10000){
        $result = $this->tableRecognitionAsync($image);
        if(isset($result['error_code'])){
            return $result;
        }
        $requestId = $result['result'][0]['request_id'];
        $count = ceil($timeout / 1000);
        for($i=0; $i<$count; $i++){
            $result = $this->getTableRecognitionResult($requestId, $options);
            // 完成
            if($result['result']['ret_code'] == 3){ 
                break;
            }
            sleep(1);
        }
        return $result;
    }
1243338
public function update(string $account, string $nickname)
    {
        $params = [
            'kf_account' => $account,
            'nickname' => $nickname,
        ];

        return $this->httpPostJson('customservice/kfaccount/update', $params);
    }
4246
public static function getInfo(/*mixed*/ $image) {
    if(
      is_string($image) &&
      false !== ($info = getimagesizefromstring($image)) &&
      !!($width = $info[0]) && !!($height = $info[1])
    ) {
      $result = imagecreatefromstring($image);
    } else if(
      is_resource($image) &&
      !!($width = imagesx($image)) && !!($height = imagesy($image))
    ) {
      $result = $image;
    } else {
      return false;
    }
    return [
      'image' => $result,
      'width' => $width,
      'height' => $height
    ];
  }
489097
public function getColorPalette($image, $colorCount, $quality, $colorValue)
    {
        try {
            $source = new LocalSourceImageModel($image);
            $source->getLocalCopy();
        } catch (ImagerException $e) {
            return null;
        }

        $palette = ColorThief::getPalette($source->getFilePath(), $colorCount, $quality);

        ImagerService::cleanSession();

        return $colorValue === 'hex' ? $this->paletteToHex($palette) : $palette;
    }
1086306
public function addAccount($kf_account, $nickname)
    {
        $data = ['kf_account' => $kf_account, 'nickname' => $nickname];
        $url = "https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, $data);
    }
1033784
public function getAccountList()
    {
        $url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=ACCESS_TOKEN";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpGetForJson($url);
    }
14278
def send_image_message(self, user_id, media_id, kf_account=None):
        
        data = {
            "touser": user_id,
            "msgtype": "image",
            "image": {
                "media_id": media_id
            }
        }
        if kf_account is not None:
            data['customservice'] = {'kf_account': kf_account}
        return self.post(
            url="https://api.weixin.qq.com/cgi-bin/message/custom/send",
            data=data
        )