Web Services 如何从Web服务下载PHP的base64映像?

xriantvc  于 2022-11-15  发布在  PHP
关注(0)|答案(1)|浏览(146)

我承认我在这个问题上遇到了很多麻烦(我对PHP和SOAP了解不多)。
我必须通过提供商的Web服务(SOAP)获得电子商务产品图片。
如下图所示,产品图片转换为base64。
Example for a product picture
我需要检索所有的图片上传到我的网站上的文件夹中,并在CSV文件中写入每张图片的路径。
下面的代码允许我检索通过Web服务发送给我的所有产品。我使用函数RecupEtatStock()恢复所有产品,然后,在循环的帮助下,对于每个产品,我使用函数RecupPhotoProduct()搜索是否存在图像。

$wsdl       = "https://sinex-saas.com/B00UWSUG9Z34TN22/Services/WebServiceStandard.asmx?WSDL"; 
    $client     = new SoapClient($wsdl);
    $password   = "????";
    $username   = "????";
    $reffab     = 4;
    $codefab    = 2;
    $i          = 0;
    $fp         = fopen(plugin_dir_path(__FILE__).'file.csv', 'w+');
        
    $dataRecupererEtatStock     = RecupEtatStock($username, $password, $client);

    foreach ($dataRecupererEtatStock as $fields) {
        $dataRecupPhotoProduit  = RecupPhotoProduit($username, $password, $client, $fields->CodeFab, $fields->RefFab, $i);
        $fields->image          = $dataRecupPhotoProduit;

        fputcsv($fp, get_object_vars($fields));
        $i+=1;
    }
    fclose($fp);

下面是RecupPhotoProduct()函数的外观。如果没有图片,函数返回null,否则它检索保存_image()函数返回的内容。

function RecupPhotoProduit($pUsername, $pPassword, $pClient, $pCodeFab, $pReffab, $pi) {
        $optionsRecupererPhotoProduit = array(
            'user'      => $pUsername,
            'password'  => $pPassword,
            'codeFab'   => $pCodeFab,
            'refFab'    => $pReffab,
        );

        $responseRecupererPhotoProduit = $pClient->RecupererPhotoProduit($optionsRecupererPhotoProduit);
            
        $array = get_object_vars($responseRecupererPhotoProduit);
        if(empty($array)) {
            $responseRecupererPhotoProduit = null;
        } else {
            $responseRecupererPhotoProduit = $responseRecupererPhotoProduit->RecupererPhotoProduitResult;
            $responseRecupererPhotoProduit = save_image($responseRecupererPhotoProduit, $pi);
        }

        return $responseRecupererPhotoProduit;

    }

上面的函数允许我从这个XML结果中检索“RetrievePhotoProductResult”中的字符串:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
    <RecupererPhotoProduitResponse xmlns="http://tempuri.org/">
        <RecupererPhotoProduitResult>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACEAJoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMB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MyKHA/Q/wAh+ddHWD4p0a/1fT0GmXiWt5ESUd03KwI6H05wcj0rWjPklcadmcNrcW/WlhcAxS221lJID5J4PseRSW09zZtYrb3Tw2VoCDbquRJGeMMTz8p6fWqkFn4iiviPEgWS7UGNHjUKrp25HXJ6H1FXNvOeOecsevbJ+vQ+hrsVpK5ZcXX9Vjt74taQT3Cu32OJX2h1HRZGPRsZORxVj+3yLm2iFkTbyRlpp9w/cnjaNvVsnPI6YrPCLjjpj3zgf+zL+opGjOfuKfYPxz2+jdvep9nEa02LT+JNVFjdG1tIILxZGW28xt8bIMfO+OQeuVHSm3Opajdais4vZFhERiNuwyjM3RyeufTHrVQqM5JA77iSfof6Gp4og3AQH+HZnGfVf6imoRWwilY20dtfWdvbjyovNLiMMcEk5bP+1nmuvt7YSSLCQP3xEYHTIP3sf8B3H8K5W6h1F1d9JTzL5cNCHUHc2cZx6joR7V0/g/QdftH+3eIr6Ke4KnbFHGAFJxzn2GR/wI8VNSooxaE3Y7GiiiuEgKKKKACiiigAooooAKKKKACiiigDlfFaq1xDkZ+Tkeo5rmJFCeYcZKhj83fBA5+oPNFFd9H4EWtiYIDLs5/1rJnPPyrkH6jpn061EVUoG2jmNWx2+Y4I+nf60UVoMQgLkjqN5z7r3/EdasxKvzAqCAyJg9we34dqKKTA19EQRa9tGTmQjLcnhW5+tdjRRXHX+IiW4UUUViIKKKKACiiigD//2Q==</RecupererPhotoProduitResult>
    </RecupererPhotoProduitResponse>
</soap:Body>
</soap:Envelope>

因此,在本例中,MIME64编码文本为:

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACEAJoDASIAAhEBAxEB/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ftH+3eIr6Ke4KnbFHGAFJxzn2GR/wI8VNSooxaE3Y7GiiiuEgKKKKACiiigAooooAKKKKACiiigDlfFaq1xDkZ+Tkeo5rmJFCeYcZKhj83fBA5+oPNFFd9H4EWtiYIDLs5/1rJnPPyrkH6jpn061EVUoG2jmNWx2+Y4I+nf60UVoMQgLkjqN5z7r3/EdasxKvzAqCAyJg9we34dqKKTA19EQRa9tGTmQjLcnhW5+tdjRRXHX+IiW4UUUViIKKKKACiiigD//2Q==

这就是我的保存_image()函数的样子,它从前面的XML的“RetrievePhotoProductResult”部分解码base64图像,并将其上传到我的WordPress插件目录。

function save_image( $base64_img, $title ) {
        $base64_img     = str_replace('data:image/png;base64,', '', $base64_img);
        $base64_img     = str_replace(' ', '+', $base64_img);
        $data           = base64_decode($base64_img);
        $file           = plugin_dir_path(__FILE__) . $title . '.png';

        return file_put_contents($file, $data);
    }

但我的问题是,图片在我的目录下下载得很好。但是,我打不开它们。
例如,如果我尝试用Paint打开它们,得到的结果如下(无论我是否用Paint打开图像,结果都是一样的。我认为问题出在base64编码上):
画图程序无法读取该文件。该文件不是有效的位图文件或其格式当前不受支持。
如果我想从我的电子商务网站访问一个图像,我有一个简单的白色出现:
I have a simple white dot that appears
下面是base64字符串解码后的样子:
the base64 string
你知道如何通过php网络服务下载base64映像吗?

5q4ezhmt

5q4ezhmt1#

<?php
 $encode = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACEAJoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEG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eo5rmJFCeYcZKhj83fBA5+oPNFFd9H4EWtiYIDLs5/1rJnPPyrkH6jpn061EVUoG2jmNWx2+Y4I+nf60UVoMQgLkjqN5z7r3/EdasxKvzAqCAyJg9we34dqKKTA19EQRa9tGTmQjLcnhW5+tdjRRXHX+IiW4UUUViIKKKKACiiigD//2Q==";
 $decode = base64_decode($encode);
 $size = getImageSizeFromString($decode);
 var_dump($size);
 if (empty($size['mime']) || strpos($size['mime'], 'image/') !== 0) {
    die('Base64 value is not a valid image');
  }

  $ext = substr($size['mime'], 6);
  $img_file = "filename.{$ext}";
  file_put_contents($img_file, $decode);

echo $ext;
?>

这将对所有有效图像起作用。

相关问题