|
|
@ -1,11 +1,9 @@ |
|
|
|
package com.epmet.wxapi.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.wxapi.constant.WxMaCodeConstant; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeAuditStatus; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeAuditStatusReq; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeCommitReq; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeSubmitAuditRequest; |
|
|
@ -13,16 +11,12 @@ import com.epmet.wxapi.result.*; |
|
|
|
import com.epmet.wxapi.service.WxMaCodeService; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.google.gson.GsonBuilder; |
|
|
|
import io.micrometer.core.instrument.util.JsonUtils; |
|
|
|
import lombok.Data; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -37,11 +31,29 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
private static final String ERR_MSG = "errmsg"; |
|
|
|
|
|
|
|
@Override |
|
|
|
public WxResult commit(String accessToken, WxMaCodeCommitReq commitRequest) throws WxErrorException { |
|
|
|
public WxResult<List<WxMaTemplateResult>> getTemplateList(String accessToken) { |
|
|
|
WxResult<List<WxMaTemplateResult>> result = new WxResult<>(); |
|
|
|
String url = WxMaCodeConstant.COMMIT_URL + "?" + "access_token=" + accessToken; |
|
|
|
Result<String> templateListResult = HttpClientManager.getInstance().sendGet(url, null); |
|
|
|
if (!templateListResult.success()) { |
|
|
|
result.setErrorCode(templateListResult.getCode()); |
|
|
|
result.setErrorMsg(templateListResult.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
Gson gson = new Gson(); |
|
|
|
WxMaTemplateListResult templateList = new Gson().fromJson(templateListResult.getData(), WxMaTemplateListResult.class); |
|
|
|
result.setErrorCode(templateList.getErrCode()); |
|
|
|
result.setErrorMsg(templateList.getErrMsg()); |
|
|
|
result.setData(templateList.getTemplateList()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public WxResult commit(String accessToken, WxMaCodeCommitReq commitRequest) { |
|
|
|
WxResult result = new WxResult(); |
|
|
|
String url = WxMaCodeConstant.COMMIT_URL + "?" + "access_token=" + accessToken; |
|
|
|
Result<String> commitResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(commitRequest)); |
|
|
|
if(!commitResult.success()) { |
|
|
|
if (!commitResult.success()) { |
|
|
|
result.setErrorCode(commitResult.getCode()); |
|
|
|
result.setErrorMsg(commitResult.getMsg()); |
|
|
|
return result; |
|
|
@ -53,7 +65,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public WxResult getQrCode(String accessToken, String path) throws WxErrorException{ |
|
|
|
public WxResult getQrCode(String accessToken, String path) { |
|
|
|
WxResult<Byte[]> result = new WxResult<>(); |
|
|
|
StringBuilder url = new StringBuilder(WxMaCodeConstant.GET_QRCODE_URL).append("?access_token").append(accessToken); |
|
|
|
if (StringUtils.isNotBlank(path)) { |
|
|
@ -64,7 +76,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
} |
|
|
|
} |
|
|
|
Result<Byte[]> qrCodeResult = HttpClientManager.getInstance().sendGetFile(url.toString(), null); |
|
|
|
if(!qrCodeResult.success()) { |
|
|
|
if (!qrCodeResult.success()) { |
|
|
|
result.setErrorCode(qrCodeResult.getCode()); |
|
|
|
result.setErrorMsg(qrCodeResult.getMsg()); |
|
|
|
return result; |
|
|
@ -80,7 +92,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
WxResult<List<WxMaCategoryResult>> result = new WxResult<>(); |
|
|
|
String url = WxMaCodeConstant.GET_CATEGORY_URL + "?" + "access_token=" + accessToken; |
|
|
|
Result<String> getCategoryResult = HttpClientManager.getInstance().sendGet(url, null); |
|
|
|
if(!getCategoryResult.success()) { |
|
|
|
if (!getCategoryResult.success()) { |
|
|
|
result.setErrorCode(getCategoryResult.getCode()); |
|
|
|
result.setErrorMsg(getCategoryResult.getMsg()); |
|
|
|
return result; |
|
|
@ -97,7 +109,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
WxResult<List<String>> result = new WxResult<>(); |
|
|
|
String url = WxMaCodeConstant.GET_PAGE_URL + "?" + "access_token=" + accessToken; |
|
|
|
Result<String> getPageResult = HttpClientManager.getInstance().sendGet(url, null); |
|
|
|
if(!getPageResult.success()) { |
|
|
|
if (!getPageResult.success()) { |
|
|
|
result.setErrorCode(getPageResult.getCode()); |
|
|
|
result.setErrorMsg(getPageResult.getMsg()); |
|
|
|
return result; |
|
|
@ -110,11 +122,11 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public WxResult submitAudit(String accessToken, WxMaCodeSubmitAuditRequest auditRequest) { |
|
|
|
WxResult result = new WxResult(); |
|
|
|
public WxResult<String> submitAudit(String accessToken, WxMaCodeSubmitAuditRequest auditRequest) { |
|
|
|
WxResult<String> result = new WxResult<>(); |
|
|
|
String url = WxMaCodeConstant.SUBMIT_AUDIT_URL + "?" + "access_token=" + accessToken; |
|
|
|
Result<String> submitResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(auditRequest)); |
|
|
|
if(!submitResult.success()) { |
|
|
|
if (!submitResult.success()) { |
|
|
|
result.setErrorCode(submitResult.getCode()); |
|
|
|
result.setErrorMsg(submitResult.getMsg()); |
|
|
|
return result; |
|
|
@ -122,20 +134,26 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(submitResult.getData()); |
|
|
|
result.setErrorCode(jsonObject.getInteger(ERR_CODE)); |
|
|
|
result.setErrorMsg(jsonObject.getString(ERR_MSG)); |
|
|
|
result.setData(jsonObject.getString("auditid")); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public WxResult getAuditStatus(String accessToken, WxMaCodeAuditStatusReq request) { |
|
|
|
public WxResult<WxMaAuditStatusResult> getAuditStatus(String accessToken, WxMaCodeAuditStatusReq request) { |
|
|
|
WxResult<WxMaAuditStatusResult> result = new WxResult<>(); |
|
|
|
String url = WxMaCodeConstant.COMMIT_URL + "?" + "access_token=" + accessToken; |
|
|
|
Result<String> statusResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(request)); |
|
|
|
if(!statusResult.success()) { |
|
|
|
if (!statusResult.success()) { |
|
|
|
result.setErrorCode(statusResult.getCode()); |
|
|
|
result.setErrorMsg(statusResult.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
WxMaAuditStatusResult auditStatusResult = JSONObject.parseObject(statusResult.getData(), WxMaAuditStatusResult.class); |
|
|
|
if (!auditStatusResult.success()){ |
|
|
|
result.setErrorCode(auditStatusResult.getErrcode()); |
|
|
|
result.setErrorMsg(auditStatusResult.getErrmsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
result.ok(auditStatusResult); |
|
|
|
return result; |
|
|
|
} |
|
|
@ -145,7 +163,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
WxResult result = new WxResult(); |
|
|
|
String url = WxMaCodeConstant.RELEASE_URL + "?" + "access_token=" + accessToken; |
|
|
|
Result<String> releaseResult = HttpClientManager.getInstance().sendPostByJSON(url, null); |
|
|
|
if(!releaseResult.success()) { |
|
|
|
if (!releaseResult.success()) { |
|
|
|
result.setErrorCode(releaseResult.getCode()); |
|
|
|
result.setErrorMsg(releaseResult.getMsg()); |
|
|
|
return result; |
|
|
@ -161,7 +179,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
WxResult result = new WxResult(); |
|
|
|
String url = WxMaCodeConstant.UNDO_CODE_AUDIT_URL + "?" + "access_token=" + accessToken; |
|
|
|
Result<String> undoResult = HttpClientManager.getInstance().sendGet(url, null); |
|
|
|
if(!undoResult.success()) { |
|
|
|
if (!undoResult.success()) { |
|
|
|
result.setErrorCode(undoResult.getCode()); |
|
|
|
result.setErrorMsg(undoResult.getMsg()); |
|
|
|
return result; |
|
|
@ -184,6 +202,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
|
WxMaCodeSubmitAuditRequest request = new WxMaCodeSubmitAuditRequest(); |
|
|
|
request.setVersionDesc("aasdf"); |
|
|
|
} |
|
|
|
|
|
|
|
private String toJson(Object object) { |
|
|
|
GsonBuilder gsonBuilder = new GsonBuilder(); |
|
|
|
gsonBuilder.setPrettyPrinting(); |
|
|
|