<?php
//上传图片接口
public function upload(){
$token = '1613533445ca5dbeebca668abbeb58ac';

$file = "https://image.jewelryhunt.net/zhaowu/20220112/21041ac8a6829bb8d24212bae728bfe7.jpg"; $url = 'http://api.kingdee.com/jdy/basedata/image_upload?access_token='.$token;
$type = getimagesize($file);//取得图片的大小,类型等
$content = file_get_contents($file);
$file_content = chunk_split(base64_encode($content));//base64编码

switch($type[2]){//判读图片类型
case 1:$img_type="gif";break;
case 2:$img_type="jpg";break;
case 3:$img_type="png";break;
}
$b64 = 'data:image/'.$img_type.';base64,'.$file_content;//合成图片的base64编码 $params['filename'] = $file;
$params['basestring'] = $b64;

$header = array('Content-Type:application/json','charset:utf-8','groupName:ns-v7g15','accountId:1626231450425742965');

$result = $this->curl_request($url,json_encode($params),'POST',$header);

$ret = json_decode($result,true);
if ($ret['success']== 1){
return $ret['data']['url'];
}else{
return '上传图片失败';
}
}