🆕 【开放平台】接入小程序认证(年审)相关接口,同时增加公共的文件上传方法

This commit is contained in:
天朝红雨
2024-01-12 20:01:42 +08:00
committed by GitHub
parent d957896ac1
commit 774579186c
39 changed files with 1353 additions and 270 deletions

View File

@@ -12,12 +12,14 @@ import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.CommonUploadParam;
import me.chanjar.weixin.common.bean.ToJson;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.common.executor.CommonUploadRequestExecutor;
import me.chanjar.weixin.common.service.WxImgProcService;
import me.chanjar.weixin.common.service.WxOcrService;
import me.chanjar.weixin.common.util.DataUtils;
@@ -237,6 +239,12 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
return this.post(url, obj.toJson());
}
@Override
public String upload(String url, CommonUploadParam param) throws WxErrorException {
RequestExecutor<String, CommonUploadParam> executor = CommonUploadRequestExecutor.create(getRequestHttp());
return this.execute(executor, url, param);
}
@Override
public String post(String url, JsonObject jsonObject) throws WxErrorException {
return this.post(url, jsonObject.toString());
@@ -378,7 +386,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
@JsonDeserialize
public void setMultiConfigs(Map<String, WxMaConfig> configs, String defaultMiniappId) {
// 防止覆盖配置
if(this.configMap != null) {
if (this.configMap != null) {
this.configMap.putAll(configs);
} else {
this.configMap = Maps.newHashMap(configs);
@@ -689,7 +697,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
}
@Override
public WxMaExpressDeliveryReturnService getWxMaExpressDeliveryReturnService(){
public WxMaExpressDeliveryReturnService getWxMaExpressDeliveryReturnService() {
return this.wxMaExpressDeliveryReturnService;
}
}

View File

@@ -3,12 +3,12 @@ package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaMediaService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.CommonUploadParam;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import java.io.File;
@@ -38,8 +38,10 @@ public class WxMaMediaServiceImpl implements WxMaMediaService {
@Override
public WxMediaUploadResult uploadMedia(String mediaType, File file) throws WxErrorException {
// return this.wxMaService.execute(MediaUploadRequestExecutor.create(this.wxMaService.getRequestHttp()), url, file);
String url = String.format(MEDIA_UPLOAD_URL, mediaType);
return this.wxMaService.execute(MediaUploadRequestExecutor.create(this.wxMaService.getRequestHttp()), url, file);
String result = wxMaService.upload(url, CommonUploadParam.fromFile("media", file));
return WxMediaUploadResult.fromJson(result);
}
@Override