🆕 #2252 【小程序】增加自定义组件之图片上传接口
This commit is contained in:
@@ -426,6 +426,13 @@ public interface WxMaService extends WxService {
|
||||
*/
|
||||
WxMaShopCatService getShopCatService();
|
||||
|
||||
/**
|
||||
* 小程序交易组件-接入商品前必需接口-上传图片
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
WxMaShopImgService getShopImgService();
|
||||
|
||||
/**
|
||||
* 获取小程序 URL Link服务接口
|
||||
*
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 小程序交易组件-接入商品前必需接口
|
||||
*
|
||||
* @author liming1019
|
||||
*/
|
||||
public interface WxMaShopImgService {
|
||||
/**
|
||||
* 上传图片
|
||||
*
|
||||
* @return WxMinishopImageUploadCustomizeResult
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException;
|
||||
}
|
||||
@@ -68,6 +68,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
private final WxMaShopRegisterService shopRegisterService = new WxMaShopRegisterServiceImpl(this);
|
||||
private final WxMaShopAccountService shopAccountService = new WxMaShopAccountServiceImpl(this);
|
||||
private final WxMaShopCatService shopCatService = new WxMaShopCatServiceImpl(this);
|
||||
private final WxMaShopImgService shopImgService = new WxMaShopImgServiceImpl(this);
|
||||
private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this);
|
||||
private final WxMaReimburseInvoiceService reimburseInvoiceService = new WxMaReimburseInvoiceServiceImpl(this);
|
||||
private Map<String, WxMaConfig> configMap;
|
||||
@@ -534,6 +535,11 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
return this.shopCatService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShopImgService getShopImgService() {
|
||||
return this.shopImgService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaLinkService getLinkService() {
|
||||
return this.linkService;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaShopImgService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.MinishopUploadRequestCustomizeExecutor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Img.IMG_UPLOAD;
|
||||
|
||||
/**
|
||||
* @author liming1019
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class WxMaShopImgServiceImpl implements WxMaShopImgService {
|
||||
private final WxMaService service;
|
||||
|
||||
@Override
|
||||
public WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException {
|
||||
WxMinishopImageUploadCustomizeResult result = this.service.execute(
|
||||
MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp()), IMG_UPLOAD, file);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -337,6 +337,10 @@ public class WxMaApiUrlConstants {
|
||||
interface Cat {
|
||||
String GET_CAT = "https://api.weixin.qq.com/shop/cat/get";
|
||||
}
|
||||
|
||||
interface Img {
|
||||
String IMG_UPLOAD = "https://api.weixin.qq.com/shop/img/upload";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.test.ApiTestModule;
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author liming1019
|
||||
*/
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMaShopImgServiceImplTest {
|
||||
|
||||
@Inject
|
||||
private WxMaService wxService;
|
||||
|
||||
@Test
|
||||
public void testUploadImg() throws WxErrorException {
|
||||
File file = new File("/Users/liming/Desktop/test.jpeg");
|
||||
WxMinishopImageUploadCustomizeResult result = wxService.getShopImgService().uploadImg(file);
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user