【问题标题】:Can not send Captcha image through nusoap webservice无法通过 nusoap webservice 发送验证码图像
【发布时间】:2015-09-07 10:53:04
【问题描述】:

我正在通过我编写的 createCaptcha 函数创建一个 Captcha 会话。 在网络服务中,我调用此函数来创建验证码会话和图像,然后我想发送验证码图像或通过网络服务显示创建的验证码图像,用户可以通过网络服务发送它的值,但我面临错误。 实际上,当我通过 Firefox 附加组件soap_client 对其进行测试时,我得到了一个编码结果,而不是指向该图像的链接。

知道我哪里错了吗?

验证码功能码:

<?php
session_start();

function createcaptcha($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefromjpeg($imgname);

    /* See if it failed */
    if(!$im)
    {
        /* Create a black image */
        $code=rand(1000,9999);
        $_SESSION["code"]=$code;
        $im = imagecreatetruecolor(50, 24);
        $bg = imagecolorallocate($im, 22, 86, 165);
        $fg = imagecolorallocate($im, 255, 255, 255);
        imagefill($im, 0, 0, $bg);
        /* Output an captcha code */
        imagestring($im, 5, 5, 5,  $code, $fg);
    }

    return $im;
}  

GetCaptcha 肥皂类:

session_start();
include_once('captcha.php');

class getCaptcha extends DBM
{
    public function getcaptcha()
    {
        //creating and generating captcha image and code
        $img = createcaptcha('captcha.png');


        //encoding to base64
        //$base64 = base64_encode($img);

        $path = $img;
        $type = pathinfo($path, PATHINFO_EXTENSION);
        $data = file_get_contents($path);
        $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);

        $save = "/captchafile/captcha.png";
        imagepng($base64, $save);


        $captcha=$save;

        $this->strResult = "";


            $this->strResult.="<captcha>";
            $this->strResult.="<captcha>$captcha</captcha>";
            $this->strResult.="</captcha>";


    }


    function __toString()
    {
        if($this->strResult!=""){
            return $this->strResult;
        }
        return "";
    }


}

【问题讨论】:

    标签: php web-services nusoap simplecaptcha


    【解决方案1】:

    您需要为您的imagepng() 函数提供另一个参数来保存图片,然后使用Get_file_content() 函数获取图像文件的内容,然后将其编码为base64 以通过webservicexml 格式发送。

    include_once('captcha.php');
    
    class getCaptcha extends DBM
    {
        public function getcaptcha($dump)
        {
            //creating and generating captcha image and code
            $img = createcaptcha("Captcha.png");
    
            imagepng($img,"Captcha.png");
            imagedestroy($img);
    
            $captchafile = file_get_contents('./Captcha.png');
    
            //encoding to base64
            $base64 = base64_encode($captchafile);
    
    
            $captcha=$base64;
    
            $this->strResult = "";
    
    
                $this->strResult.="<captcha>";
                $this->strResult.="<captcha>$captcha</captcha>";
                $this->strResult.="</captcha>";
    
    
        }
    
    
        function __toString()
        {
            if($this->strResult!=""){
                return $this->strResult;
            }
            return "";
        }
    
    
    }
    

    【讨论】:

    • 非常感谢。解决了我的问题。我没想过编码它..!
    猜你喜欢
    • 2012-05-26
    • 1970-01-01
    • 2020-09-29
    • 2021-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 2020-05-20
    相关资源
    最近更新 更多