|
@ -1,11 +1,9 @@ |
|
|
package com.epmet.wxapi.service.impl; |
|
|
package com.epmet.wxapi.service.impl; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.wxapi.constant.WxMaCodeConstant; |
|
|
import com.epmet.wxapi.constant.WxMaCodeConstant; |
|
|
import com.epmet.wxapi.param.WxMaCodeAuditStatus; |
|
|
|
|
|
import com.epmet.wxapi.param.WxMaCodeAuditStatusReq; |
|
|
import com.epmet.wxapi.param.WxMaCodeAuditStatusReq; |
|
|
import com.epmet.wxapi.param.WxMaCodeCommitReq; |
|
|
import com.epmet.wxapi.param.WxMaCodeCommitReq; |
|
|
import com.epmet.wxapi.param.WxMaCodeSubmitAuditRequest; |
|
|
import com.epmet.wxapi.param.WxMaCodeSubmitAuditRequest; |
|
@ -13,16 +11,12 @@ import com.epmet.wxapi.result.*; |
|
|
import com.epmet.wxapi.service.WxMaCodeService; |
|
|
import com.epmet.wxapi.service.WxMaCodeService; |
|
|
import com.google.gson.Gson; |
|
|
import com.google.gson.Gson; |
|
|
import com.google.gson.GsonBuilder; |
|
|
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.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
import java.io.UnsupportedEncodingException; |
|
|
import java.net.URLEncoder; |
|
|
import java.net.URLEncoder; |
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -37,7 +31,25 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
private static final String ERR_MSG = "errmsg"; |
|
|
private static final String ERR_MSG = "errmsg"; |
|
|
|
|
|
|
|
|
@Override |
|
|
@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(); |
|
|
WxResult result = new WxResult(); |
|
|
String url = WxMaCodeConstant.COMMIT_URL + "?" + "access_token=" + accessToken; |
|
|
String url = WxMaCodeConstant.COMMIT_URL + "?" + "access_token=" + accessToken; |
|
|
Result<String> commitResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(commitRequest)); |
|
|
Result<String> commitResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(commitRequest)); |
|
@ -53,7 +65,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WxResult getQrCode(String accessToken, String path) throws WxErrorException{ |
|
|
public WxResult getQrCode(String accessToken, String path) { |
|
|
WxResult<Byte[]> result = new WxResult<>(); |
|
|
WxResult<Byte[]> result = new WxResult<>(); |
|
|
StringBuilder url = new StringBuilder(WxMaCodeConstant.GET_QRCODE_URL).append("?access_token").append(accessToken); |
|
|
StringBuilder url = new StringBuilder(WxMaCodeConstant.GET_QRCODE_URL).append("?access_token").append(accessToken); |
|
|
if (StringUtils.isNotBlank(path)) { |
|
|
if (StringUtils.isNotBlank(path)) { |
|
@ -110,8 +122,8 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WxResult submitAudit(String accessToken, WxMaCodeSubmitAuditRequest auditRequest) { |
|
|
public WxResult<String> submitAudit(String accessToken, WxMaCodeSubmitAuditRequest auditRequest) { |
|
|
WxResult result = new WxResult(); |
|
|
WxResult<String> result = new WxResult<>(); |
|
|
String url = WxMaCodeConstant.SUBMIT_AUDIT_URL + "?" + "access_token=" + accessToken; |
|
|
String url = WxMaCodeConstant.SUBMIT_AUDIT_URL + "?" + "access_token=" + accessToken; |
|
|
Result<String> submitResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(auditRequest)); |
|
|
Result<String> submitResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(auditRequest)); |
|
|
if (!submitResult.success()) { |
|
|
if (!submitResult.success()) { |
|
@ -122,11 +134,12 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
JSONObject jsonObject = JSONObject.parseObject(submitResult.getData()); |
|
|
JSONObject jsonObject = JSONObject.parseObject(submitResult.getData()); |
|
|
result.setErrorCode(jsonObject.getInteger(ERR_CODE)); |
|
|
result.setErrorCode(jsonObject.getInteger(ERR_CODE)); |
|
|
result.setErrorMsg(jsonObject.getString(ERR_MSG)); |
|
|
result.setErrorMsg(jsonObject.getString(ERR_MSG)); |
|
|
|
|
|
result.setData(jsonObject.getString("auditid")); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WxResult getAuditStatus(String accessToken, WxMaCodeAuditStatusReq request) { |
|
|
public WxResult<WxMaAuditStatusResult> getAuditStatus(String accessToken, WxMaCodeAuditStatusReq request) { |
|
|
WxResult<WxMaAuditStatusResult> result = new WxResult<>(); |
|
|
WxResult<WxMaAuditStatusResult> result = new WxResult<>(); |
|
|
String url = WxMaCodeConstant.COMMIT_URL + "?" + "access_token=" + accessToken; |
|
|
String url = WxMaCodeConstant.COMMIT_URL + "?" + "access_token=" + accessToken; |
|
|
Result<String> statusResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(request)); |
|
|
Result<String> statusResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(request)); |
|
@ -136,6 +149,11 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
WxMaAuditStatusResult auditStatusResult = JSONObject.parseObject(statusResult.getData(), WxMaAuditStatusResult.class); |
|
|
WxMaAuditStatusResult auditStatusResult = JSONObject.parseObject(statusResult.getData(), WxMaAuditStatusResult.class); |
|
|
|
|
|
if (!auditStatusResult.success()){ |
|
|
|
|
|
result.setErrorCode(auditStatusResult.getErrcode()); |
|
|
|
|
|
result.setErrorMsg(auditStatusResult.getErrmsg()); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
result.ok(auditStatusResult); |
|
|
result.ok(auditStatusResult); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
@ -184,6 +202,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { |
|
|
WxMaCodeSubmitAuditRequest request = new WxMaCodeSubmitAuditRequest(); |
|
|
WxMaCodeSubmitAuditRequest request = new WxMaCodeSubmitAuditRequest(); |
|
|
request.setVersionDesc("aasdf"); |
|
|
request.setVersionDesc("aasdf"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String toJson(Object object) { |
|
|
private String toJson(Object object) { |
|
|
GsonBuilder gsonBuilder = new GsonBuilder(); |
|
|
GsonBuilder gsonBuilder = new GsonBuilder(); |
|
|
gsonBuilder.setPrettyPrinting(); |
|
|
gsonBuilder.setPrettyPrinting(); |
|
|