上传客服头像

@param string $account //完整客服账号，格式为：账号前缀@公众号微信号，账号前缀最多10个字符，必须是英文或者数字字符
@param string $imgfile //头像文件完整路径,如：'D:\user.jpg'。头像文件必须JPG格式，像素建议640*640
@return boolean|array
成功返回结果
{
"errcode": 0,
"errmsg": "ok",
}
328886
public function setKFHeadImg($account,$imgfile){
        if (!$this->access_token && !$this->checkAuth()) return false;
        $result = $this->http_post(self::API_BASE_URL_PREFIX.self::CS_KF_ACCOUNT_UPLOAD_HEADIMG_URL.'access_token='.$this->access_token.'&kf_account='.$account,array('media'=>'@'.$imgfile),true);
        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;
    }
1335801
public function deleteAccount(array $account)
    {
        $result = $this->wechat->httpRaw(self::WECHAT_ACCOUNT_DELETE_PREFIX, $account, [
            'access_token' => $this->wechat->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok';
    }
620979
public function sendPreview($account,$title,$summary,$content,$photoid,$srcurl='') {
		$send_snoopy = new Snoopy;
		$submit = "https://mp.weixin.qq.com/cgi-bin/operate_appmsg?sub=preview&t=ajax-appmsg-preview";
		$send_snoopy->set_submit_normal();
		$send_snoopy->rawheaders['Cookie']= $this->cookie;
		$send_snoopy->referer = 'https://mp.weixin.qq.com/cgi-bin/operate_appmsg?sub=edit&t=wxm-appmsgs-edit-new&type=10&subtype=3&lang=zh_CN';
		$post = array(
				'AppMsgId'=>'',
				'ajax'=>1,
				'content0'=>$content,
				'count'=>1,
				'digest0'=>$summary,
				'error'=>'false',
				'fileid0'=>$photoid,
				'preusername'=>$account,
				'sourceurl0'=>$srcurl,
				'title0'=>$title,
		);
		$post['token'] = $this->_token;
		$send_snoopy->submit($submit,$post);
		$tmp = $send_snoopy->results;
		$this->log('sendpreview:'.$tmp);
		$json = json_decode($tmp,true);
		return $json;
	}
842304
public function save($imgname, $type = null, $quality=80,$interlace = true){
        if(empty($this->img)) $this->throwError('没有可以被保存的图像资源');

        //自动获取图像类型
        if(is_null($type)){
            $type = $this->info['type'];
        } else {
            $type = strtolower($type);
        }

        //保存图像
        if('jpeg' == $type || 'jpg' == $type){
            //JPEG图像设置隔行扫描
            imageinterlace($this->img, $interlace);
            imagejpeg($this->img, $imgname,$quality);
        }elseif('gif' == $type && !empty($this->gif)){
            $this->gif->save($imgname);
        }else{
            $fun  =   'image'.$type;
            $fun($this->img, $imgname);
        }
    }
557690
protected
    function parseAccount(
        AccountInterface $account
    ) {
        if ($account) {
            $data = [];
            $data['id'] = $account->getId();
            $data['name'] = $account->getName();
            $data['phone'] = $account->getMainPhone();
            $data['email'] = $account->getMainEmail();
            $data['url'] = $account->getMainUrl();

            // get main contact
            if ($account->getMainContact()) {
                $data['contact'] = $account->getMainContact()->getFullName();
            }

            /* @var Address $accountAddress */
            $accountAddress = $account->getMainAddress();
            if ($accountAddress) {
                $data['address']['street'] = $accountAddress->getStreet();
                $data['address']['number'] = $accountAddress->getNumber();
                $data['address']['zip'] = $accountAddress->getZip();
                $data['address']['city'] = $accountAddress->getCity();
                $data['address']['country'] = $accountAddress->getCountry()->getName();
            }

            return $data;
        } else {
            return null;
        }
    }
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);
    }
785766
public function getUrl($account, $key) {

    $url['url'] = $this->psl['text/filter']->t('otpauth://totp/&account?secret=&key',
                    array('&account' => $account, '&key' => $key)
                  );

    $url['qr']  = $this->psl['text/filter']->t('https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/&account?secret=&key',
                    array('&account' => $account, '&key' => $key)
                  );

    return $url;
  }
1209352
public function uploadimg($file)
    {
        if (!$file) {
            $this->setError('参数缺失');

            return false;
        }

        if (!file_exists($file)) {
            $this->setError('文件路径不正确');

            return false;
        }

        $data          = [];
        $data['media'] = '@' . realpath($file);

        $node = 'uploadimg';

        $res = $this->_post($node, $data, false);

        return $res;
    }
564076
public function deleteConnectToken($account = null, $params)
    {
        if (is_string($params)) {
            $params = array('token' => $params);
        } else {
            $params = $this->checkFilterParams($params, array('token'), array('token'));
            if ($params === false) {
                throw new \InvalidArgumentException("params array contains invalid parameters or misses required parameters");
            }
        }

        return $this->lastRequest->delete($account, 'connect_tokens/' . $params[ 'token' ]);
    }
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();
    }
743277
public function open($imgname){
        //检测图像文件
        if(!is_file($imgname)) $this->throwError('不存在的图像文件');

        //获取图像信息
        $info = getimagesize($imgname);

        //检测图像合法性
        if(false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))){
            $this->throwError('非法图像文件');
        }

        //设置图像信息
        $this->info = array(
            'width'  => $info[0],
            'height' => $info[1],
            'type'   => image_type_to_extension($info[2], false),
            'mime'   => $info['mime'],
        );

        //销毁已存在的图像
        empty($this->img) || imagedestroy($this->img);

        //打开图像
//        if('gif' == $this->info['type']){         //注意暂时不支持gif格式的图片
//            $class  =    'Think\\Image\\Driver\\GIF';
//            $this->gif = new $class($imgname);
//            $this->img = imagecreatefromstring($this->gif->image());
//        } else {
            $fun = "imagecreatefrom{$this->info['type']}";
            $this->img = $fun($imgname);
//        }
    }
200306
public function signOn(array $account)
    {
        $cacheItemPool = $this->getCacheItemPool();
        $virtualUserId = md5(json_encode($account) . mt_srand() . time());
        $cacheItemPool->save(new Item('sso-' . $virtualUserId, $account, false));

        set_cookie('ssid', $virtualUserId);
    }
876501
public function watermark($img, $outPath = '', $pos = '', $waterImg = '', $alpha = '', $text = '')
    {
        // 验证原图像 和 是否已有错误
        if (false === $this->_checkImage($img) || $this->hasError()) {
            return $this;
        }

        $imgInfo = pathinfo($img);
        $imgType = $this->_handleImageType($imgInfo['extension']);
        $outPath = $outPath ?: ($this->waterOptions['path'] ?: \dirname($img));
        $pos = $pos ?: $this->waterOptions['pos'];
        $alpha = $alpha ?: $this->waterOptions['alpha'];
        $waterImg = $waterImg ?: $this->waterOptions['img'];
        $waterImgType = $resWaterImg = null;

        list($imgWidth, $imgHeight) = getimagesize($img);

        if ($waterImg) {

            // 验证水印图像
            if (false === $this->_checkImage($waterImg)) {
                return $this;
            }

            $waterImgType = $this->_handleImageType(pathinfo($waterImg, PATHINFO_EXTENSION));
            list($waterWidth, $waterHeight) = getimagesize($waterImg);

            if ($imgHeight < $waterHeight || $imgWidth < $waterWidth) {
                $this->_error = 'The image is too small.';

                return $this;
            }

            // create water image resource
            $resWaterImg = \call_user_func("imagecreatefrom{$waterImgType}", $waterImg);
        } else {
            //水印文字
            $text = $text ?: $this->waterOptions['text'];

            if (!is_file($this->waterOptions['fontFile'])) {
                throw new InvalidConfigException('请配置正确的水印文字资源路径');
            }

            if (!$text || \strlen($this->waterOptions['fontColor']) !== 6) {
                throw new InvalidConfigException('The watermark font color length must equal to 6.');
            }

            $textInfo = imagettfbbox($this->waterOptions['fontSize'], 0, $this->waterOptions['fontFile'], $text);
            $waterWidth = $textInfo[2] - $textInfo[6];
            $waterHeight = $textInfo[3] - $textInfo[7];
        }

        // create image resource 建立原图资源
        $method = "imagecreatefrom{$imgType}";
        $resImg = $method($img);

        //水印位置处理
        list($x, $y) = $this->_calcWaterCoords($pos, $imgWidth, $waterWidth, $imgHeight, $waterHeight);

        if ($waterImg && $resWaterImg && $waterImgType) {

            // is png image. 'IMAGETYPE_PNG' === 3
            if ($waterImgType === self::IMAGE_PNG) {
                imagecopy($resImg, $resWaterImg, $x, $y, 0, 0, $waterWidth, $waterHeight);
            } else {
                imagecopymerge($resImg, $resWaterImg, $x, $y, 0, 0, $waterWidth, $waterHeight, $alpha);
            }
        } else {
            $r = hexdec(substr($this->waterOptions['fontColor'], 0, 2));
            $g = hexdec(substr($this->waterOptions['fontColor'], 2, 2));
            $b = hexdec(substr($this->waterOptions['fontColor'], 4, 2));
            $color = imagecolorallocate($resImg, $r, $g, $b);
            $charset = 'UTF-8';

            imagettftext(
                $resImg, $this->waterOptions['fontSize'], 0, $x, $y,
                $color, $this->waterOptions['fontFile'], iconv($charset, 'utf-8', $text)
            );
        }

        if (!Directory::create($outPath)) {
            $this->_error = 'Failed to create the output directory path!. OUT-PATH: ' . $outPath;

            return $this;
        }

        $outFile = $outPath . '/' . $imgInfo['basename'];

        if ($imgType === self::IMAGE_JPEG) {
            imagejpeg($resImg, $outFile, $this->waterOptions['quality']);
        } elseif ($imgType === self::IMAGE_PNG) {
            imagepng($resImg, $outFile, ceil($this->waterOptions['quality'] / 10));
        } else {
            \call_user_func("image{$imgType}", $resImg, $outFile);
        }

        imagedestroy($resImg);

        $this->working = [
            'raw' => $img,
            'out' => $outFile,
        ];

        $this->_result['workWater']['rawFile'] = $img;
        $this->_result['workWater']['outFile'] = $outFile;

        return $this;
    }
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)]);
    }
189516
public function cardUpload_img($file)
    {
        if (!$file) {
            $this->setError('参数缺失');

            return false;
        }

        $node = 'uploadimg';

        $name        = 'media'; // 设置上传文件键名 固定为media
        $filename    = $file['name']; // 设置上传文件名
        $filetype    = $file['type'];
        $filecontent = file_get_contents($file['tmp_name']); // 读取临时文件里 上传文件的信息
        $key         = "name=\"{$name}\"; filename=\"{$filename}\"\r\nContent-Type: {$filetype}\r\n"; // curl设置上传文件的一种方法.

        $param       = [];
        $param[$key] = $filecontent;

        $res = $this->_post($node, $param, false);

        return $res;
    }
70589
public static function getInstance($cloudId, Account $account)
    {
        $signer = new PandaSigner();
        $signer->setCloudId($cloudId);
        $signer->setAccount($account);

        return $signer;
    }
777556
public function showAction(Request $request, Account $account)
    {
        $this->get('white_october_breadcrumbs')
            ->addItem('Home',
                $this->get('router')->generate('_homepage')
            )
            ->addItem('Accounts',
                $this->get('router')->generate('phospr_account')
            )
        ;

        $treePath = $this->get('phospr.account_handler')
            ->getTreePath($account)
        ;

        foreach ($treePath as $node) {
            if ($node->getLvl()) {
                $this->get('white_october_breadcrumbs')
                    ->addItem($node->getName(),
                        $this->get('router')->generate('phospr_account_show', array(
                            'path' => $node->getPath()
                    )))
                ;
            }
        }

        $calculatedBalance = 0;

        foreach ($account->getPostings() as $posting) {
            $calculatedBalance += $posting->getAmount();

            $posting->setCalculatedBalance($calculatedBalance);
        }

        $journal = $this->get('phospr.journal_handler')->createJournal();

        $form = $this->createForm(new SimpleJournalType(), $journal);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->get('doctrine')->getManager();

            $amount  = $form->getData()->getCreditAmount();
            $amount -= $form->getData()->getDebitAmount();

            $ph = $this->get('phospr.posting_handler');

            $form->getData()->addPosting($ph->createPosting($account, $amount));
            $form->getData()->addPosting($ph->createPosting(
                $form->getData()->getOffsetAccount(),
                -1*$amount
            ));

            $em->persist($form->getData());
            $em->flush();

            return $this->redirect($this->generateUrl(
                'phospr_account_show', array('path' => $account->getPath())
            ));
        }

        return array(
            'account' => $account,
            'form'    => $form->createView(),
        );
    }