场景说明:
该接口一般是结合口碑开店或商户会员卡产品使用,需要将商户需要使用的图片或视频上传支付宝服务器,生成对应的图片ID,然后调用对应的接口配置相应的图片。
一、文档地址
官方文档地址:[url]https://docs.open.alipay.com/api_3/alipay.offline.material.image.upload[/url]
二、开发前准备工作
调用步骤:[url]https://openclub.alipay.com/read.php?tid=12194&fid=69[/url]
注意事项:1、支持沙箱测试;2、不需签约,但需要添加功能;3、支持第三方调用。
注:应用中没有对应的图片上传功能,该功能的添加是根据对应产品添加,如口碑开店、商户会员卡等。
三、接口调用请求示例
1、参数说明
(1)image_type:目前只支持bmp,png,jpeg,jpg,gif 5个类型
(2)image_name:图片/视频名称
(3)image_content:图片/视频二进制内容,图片/视频大小不能超过5M
该参数是设置图片文件的路径,Windows请填写绝对路径,不支持相对路径;Linux支持相对路径。
2、JAVA版本请求示例
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.URL ,AlipayConfig.APPID,AlipayConfig.RSA_PRIVATE_KEY,"json",AlipayConfig.CHARSET,AlipayConfig.ALIPAY_PUBLIC_KEY,"RSA2"); AlipayOfflineMaterialImageUploadRequest request = new AlipayOfflineMaterialImageUploadRequest(); request.setImageType("jpg"); //图片类型,当前支持bmp,png,jpeg,jpg,gif 5个类型 request.setImageName("煜雨"); FileItem ImageContent = new FileItem("C:/Users/Public/Pictures/Sample Pictures/122.jpg");//图片文件路径,Windows请填写绝对路径,不支持相对路径;Linux支持相对路径 request.setImageContent(ImageContent); //request.setImagePid("2088021822217233"); AlipayOfflineMaterialImageUploadResponse response = alipayClient.execute(request); //alipayResponse.getImageId() 获取图片资源ID //alipayResponse.getImageUrl() 获取图片访问链接 if(response.isSuccess()){ System.out.println("调用成功"); } else { System.out.println("调用失败"); } System.out.println(response.getBody());
响应参数:
调用成功{"alipay_offline_material_image_upload_response":{"code":"10000","msg":"Success","image_id":"-BQdFtaWQ5G9C-pu8bf4ogAAACMAAQED","image_url":"https:\/\/oalipay-dl-django.alicdn.com\/rest\/1.0\/image?fileIds=-BQdFtaWQ5G9C-pu8bf4ogAAACMAAQED&zoom=original"},"sign":"o6YTatnaar6KAq2qhGEUYCYRXrNfmZ68TksdxlSOhf0Ar1XGM0HUEzkM6X7vfgihDSUh0alWFQZLmKmkYhPSNzvwLWXpDV9qO1ps8+3RNgi+LdfVSl2NA3Okdvxk/ovM9ibx2kvatlUhFyrcSPswPLJDdEcowgFDiaQm3aFhysG8t0Y5nBDHbyTWL5SQ1cC3yPD0AfPzRX5QnxW8fxlxtQMCJCiI+vf9yvq2oQpjpTprkvp0Zj2Jx3/09Lc4UTk/TjjcyJQVqMZFBQxUaayGk+GiP7+eRGyuA0gxFlzfIkkcCpkI6HfgkRJXkeUQgvdhOImv/EURTOmWpsJ0EcptUQ=="}
3、PHP版本请求示例
include_once './config.php'; //引入config中配置的APPID和密钥信息require_once 'AopSdk.php'; //引入SDK$aop->method='alipay.offline.material.image.upload';$request = new AlipayOfflineMaterialImageUploadRequest ();$request->setImageType("jpg");$request->setImageName("煜雨");$cc='C:/Users/Public/Pictures/Sample Pictures/122.jpg';$request->setImageContent("@".$cc);$result = $aop->execute ($request);//var_dump($result);echo json_encode($result,JSON_UNESCAPED_UNICODE);//打印完整的响应参数信息
响应参数:
{"alipay_offline_material_image_upload_response":{"code":"10000","msg":"Success","image_id":"xal969tURAqgeC6EdqejGAAAACMAAQED","image_url":"https:\/\/oalipay-dl-django.alicdn.com\/rest\/1.0\/image?fileIds=xal969tURAqgeC6EdqejGAAAACMAAQED&zoom=original"},"sign":"V6T9rHtF6+IjyU1W7L2LSqXuQBqRLsSFarZl2QO5rUm+3nYo++qpUrIMH43mEnW6e27YC3JaP2ySO0IdeygjzmZrlMDOJE\/DUd+t58wfyEEHftnSdd6ZvLriY7zau2LAZaEQ2AQrZdAP1u6igFYqeb\/6O8bGiH75HEreUFvxT19lng+3zAK8vspeLyYuizFUDQNGKAiK9DMFXj0FsmihtCXK8BTJeafFpXuBVhFNOLlnbOwnr4OP5y\/QXevabE9b8t6Q40rgzKm3LvdFIuyWzNj2YjZTGqC4vIosfIkJ2detXTD0c4SQaS4Nj1CmzkUsTrbn3TUY3prYFHud8PGjwA=="}
4、.NET版本请求示例
IAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", "RSA2", config.alipay_public_key, config.charset, false); AlipayOfflineMaterialImageUploadRequest request= new AlipayOfflineMaterialImageUploadRequest() ; request.ImageType = "jpg"; request.ImageName = "煜雨测试1"; FileItem ImageContent = new Aop.Api.Util.FileItem("C:/Users/Public/Pictures/Sample Pictures/122.jpg"); request.ImageContent = ImageContent; AlipayOfflineMaterialImageUploadResponse response=client.Execute(request); Console.WriteLine(response.Body);
响应参数:
{"alipay_offline_material_image_upload_response":{"code":"10000","msg":"Success","image_id":"4RhwiJKoTfiUkLQS9lVtXgAAACMAAQQD","image_url":"https://oalipay-dl-django.alicdn.com/rest/1.0/image?fileIds=4RhwiJKoTfiUkLQS9lVtXgAAACMAAQQD&zoom=original"},"sign":"O+TLANRVwF5xrj1YupbmHPRZfoRSu3YrYHEWkJ3+U3Q2qTu0eNOvN/8hHRLedkP9sX5Lvg8y3pA0sIDRYWu5BP6Y3OYTovs0n7eXIGyuoF7HSk1CYEwEiFsXWtMzgd31iVO7v3g0pafQipnL6+NT5B1inw1uNrN7gVIvXBcNZex/iXry1wiiOSFMhOTEe/5K7OpzCmfTldT7uTQkOa3BgQdWpolYQe3SJjV6eORRucNDV/5mWZkmXrRKj5s8QZGUApfwgGadnKue+YE4qz8oNsEn9gBVGoQSLZx3kbkHVqC7O2YeQyPOpKYW5P4ou1PAEIL3Bqtcv0k0Xc8+0tsfMw=="}
四、常见问题
1.Q:调用图片上传接口出现“ISV权限不足,建议在开发者中心检查对应功能是否已经添加”,如何处理?
A:在应用中添加【口碑开店】的应用功能即可。
2.Q:image_type参数都可以设置什么格式?
A:当前支持bmp,png,jpeg,jpg,gif 5个类型。
3.Q:image_content参数是否可以设置相对路径?
A:该参数是设置图片文件的路径,Windows请填写绝对路径,不支持相对路径;Linux支持相对路径。
如果大家在测试过程中遇到问题欢迎在帖子下方追问,请按照标准方式提问
标准方式:使用环境(沙箱还是正式环境)+ appid+请求时间(大概时间方便查日志必填)+请求参数+报错截图