🎨 优化部分代码

This commit is contained in:
Binary Wang 2021-01-27 22:43:07 +08:00
parent c4a87961af
commit 6811bffa18
21 changed files with 142 additions and 131 deletions

View File

@ -14,6 +14,11 @@ import com.thoughtworks.xstream.security.WildcardTypePermission;
import java.io.Writer; import java.io.Writer;
/**
* The type X stream initializer.
*
* @author Daniel Qian
*/
public class XStreamInitializer { public class XStreamInitializer {
private static final XppDriver XPP_DRIVER = new XppDriver() { private static final XppDriver XPP_DRIVER = new XppDriver() {
@Override @Override
@ -45,6 +50,11 @@ public class XStreamInitializer {
} }
}; };
/**
* Gets instance.
*
* @return the instance
*/
public static XStream getInstance() { public static XStream getInstance() {
XStream xstream = new XStream(new PureJavaReflectionProvider(), XPP_DRIVER) { XStream xstream = new XStream(new PureJavaReflectionProvider(), XPP_DRIVER) {
// only register the converters we need; other converters generate a private access warning in the console on Java9+... // only register the converters we need; other converters generate a private access warning in the console on Java9+...

View File

@ -5,12 +5,17 @@ import me.chanjar.weixin.common.error.WxErrorException;
/** /**
* 小程序插件管理 API * 小程序插件管理 API
* <p> *
* 详情请见https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/plugin-management/pluginManager.applyPlugin.html * 详情请见https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/plugin-management/pluginManager.applyPlugin.html
* 或者https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Plug-ins_Management.html * 或者https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Plug-ins_Management.html
*
* @author ArBing
*/ */
public interface WxMaPluginService { public interface WxMaPluginService {
/**
* The constant PLUGIN_URL.
*/
String PLUGIN_URL = "https://api.weixin.qq.com/wxa/plugin"; String PLUGIN_URL = "https://api.weixin.qq.com/wxa/plugin";
/** /**
@ -25,8 +30,8 @@ public interface WxMaPluginService {
/** /**
* 查询已添加的插件 * 查询已添加的插件
* *
* @return * @return plugin list
* @throws WxErrorException * @throws WxErrorException the wx error exception
*/ */
WxMaPluginListResult getPluginList() throws WxErrorException; WxMaPluginListResult getPluginList() throws WxErrorException;
@ -34,7 +39,7 @@ public interface WxMaPluginService {
* 删除已添加的插件 * 删除已添加的插件
* *
* @param pluginAppId 插件 appId * @param pluginAppId 插件 appId
* @throws WxErrorException * @throws WxErrorException the wx error exception
*/ */
void unbindPlugin(String pluginAppId) throws WxErrorException; void unbindPlugin(String pluginAppId) throws WxErrorException;
@ -43,7 +48,7 @@ public interface WxMaPluginService {
* *
* @param pluginAppId 插件 appid * @param pluginAppId 插件 appid
* @param userVersion 升级至版本号要求此插件版本支持快速更新 * @param userVersion 升级至版本号要求此插件版本支持快速更新
* @throws WxErrorException * @throws WxErrorException the wx error exception
*/ */
void updatePlugin(String pluginAppId, String userVersion) throws WxErrorException; void updatePlugin(String pluginAppId, String userVersion) throws WxErrorException;

View File

@ -18,6 +18,7 @@ public interface WxMaRunService {
* @param sessionKey 会话密钥 * @param sessionKey 会话密钥
* @param encryptedData 消息密文 * @param encryptedData 消息密文
* @param ivStr 加密算法的初始向量 * @param ivStr 加密算法的初始向量
* @return the run step info
*/ */
List<WxMaRunStepInfo> getRunStepInfo(String sessionKey, String encryptedData, String ivStr); List<WxMaRunStepInfo> getRunStepInfo(String sessionKey, String encryptedData, String ivStr);

View File

@ -2,16 +2,11 @@ package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaAnalysisService; import cn.binarywang.wx.miniapp.api.WxMaAnalysisService;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.analysis.WxMaRetainInfo; import cn.binarywang.wx.miniapp.bean.analysis.*;
import cn.binarywang.wx.miniapp.bean.analysis.WxMaSummaryTrend;
import cn.binarywang.wx.miniapp.bean.analysis.WxMaUserPortrait;
import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitDistribution;
import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitPage;
import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitTrend;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
@ -24,10 +19,9 @@ import java.util.List;
* @author <a href="https://github.com/charmingoh">Charming</a> * @author <a href="https://github.com/charmingoh">Charming</a>
* @since 2018-04-28 * @since 2018-04-28
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaAnalysisServiceImpl implements WxMaAnalysisService { public class WxMaAnalysisServiceImpl implements WxMaAnalysisService {
private final WxMaService service;
private WxMaService wxMaService;
@Override @Override
public List<WxMaSummaryTrend> getDailySummaryTrend(Date beginDate, Date endDate) throws WxErrorException { public List<WxMaSummaryTrend> getDailySummaryTrend(Date beginDate, Date endDate) throws WxErrorException {
@ -59,7 +53,7 @@ public class WxMaAnalysisServiceImpl implements WxMaAnalysisService {
@Override @Override
public WxMaVisitDistribution getVisitDistribution(Date beginDate, Date endDate) throws WxErrorException { public WxMaVisitDistribution getVisitDistribution(Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.wxMaService.post(GET_VISIT_DISTRIBUTION_URL, toJson(beginDate, endDate)); String responseContent = this.service.post(GET_VISIT_DISTRIBUTION_URL, toJson(beginDate, endDate));
return WxMaVisitDistribution.fromJson(responseContent); return WxMaVisitDistribution.fromJson(responseContent);
} }
@ -87,12 +81,12 @@ public class WxMaAnalysisServiceImpl implements WxMaAnalysisService {
@Override @Override
public WxMaUserPortrait getUserPortrait(Date beginDate, Date endDate) throws WxErrorException { public WxMaUserPortrait getUserPortrait(Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.wxMaService.post(GET_USER_PORTRAIT_URL, toJson(beginDate, endDate)); String responseContent = this.service.post(GET_USER_PORTRAIT_URL, toJson(beginDate, endDate));
return WxMaUserPortrait.fromJson(responseContent); return WxMaUserPortrait.fromJson(responseContent);
} }
private WxMaRetainInfo getRetainInfo(Date beginDate, Date endDate, String url) throws WxErrorException { private WxMaRetainInfo getRetainInfo(Date beginDate, Date endDate, String url) throws WxErrorException {
String responseContent = this.wxMaService.post(url, toJson(beginDate, endDate)); String responseContent = this.service.post(url, toJson(beginDate, endDate));
return WxMaRetainInfo.fromJson(responseContent); return WxMaRetainInfo.fromJson(responseContent);
} }
@ -105,7 +99,7 @@ public class WxMaAnalysisServiceImpl implements WxMaAnalysisService {
* @return List 类型的数据 * @return List 类型的数据
*/ */
private <T> List<T> getAnalysisResultAsList(String url, Date beginDate, Date endDate, Type returnType) throws WxErrorException { private <T> List<T> getAnalysisResultAsList(String url, Date beginDate, Date endDate, Type returnType) throws WxErrorException {
String responseContent = this.wxMaService.post(url, toJson(beginDate, endDate)); String responseContent = this.service.post(url, toJson(beginDate, endDate));
JsonObject response = GsonParser.parse(responseContent); JsonObject response = GsonParser.parse(responseContent);
boolean hasList = response.has("list"); boolean hasList = response.has("list");
if (hasList) { if (hasList) {

View File

@ -31,7 +31,6 @@ import java.util.*;
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxMaCloudServiceImpl implements WxMaCloudService { public class WxMaCloudServiceImpl implements WxMaCloudService {
private final WxMaService wxMaService; private final WxMaService wxMaService;
@Override @Override

View File

@ -9,6 +9,7 @@ import java.nio.file.Path;
import java.util.List; import java.util.List;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -32,30 +33,29 @@ import me.chanjar.weixin.common.util.json.GsonHelper;
* @author <a href="https://github.com/charmingoh">Charming</a> * @author <a href="https://github.com/charmingoh">Charming</a>
* @since 2018-04-26 20:00 * @since 2018-04-26 20:00
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaCodeServiceImpl implements WxMaCodeService { public class WxMaCodeServiceImpl implements WxMaCodeService {
private final WxMaService service;
private WxMaService wxMaService;
@Override @Override
public void commit(WxMaCodeCommitRequest commitRequest) throws WxErrorException { public void commit(WxMaCodeCommitRequest commitRequest) throws WxErrorException {
this.wxMaService.post(COMMIT_URL, commitRequest.toJson()); this.service.post(COMMIT_URL, commitRequest.toJson());
} }
@Override @Override
public byte[] getQrCode(String path) throws WxErrorException { public byte[] getQrCode(String path) throws WxErrorException {
String appId = this.wxMaService.getWxMaConfig().getAppid(); String appId = this.service.getWxMaConfig().getAppid();
Path qrCodeFilePath = null; Path qrCodeFilePath = null;
try { try {
RequestExecutor<File, String> executor = BaseMediaDownloadRequestExecutor RequestExecutor<File, String> executor = BaseMediaDownloadRequestExecutor
.create(this.wxMaService.getRequestHttp(), Files.createTempDirectory("wxjava-ma-" + appId).toFile()); .create(this.service.getRequestHttp(), Files.createTempDirectory("wxjava-ma-" + appId).toFile());
final StringBuilder url = new StringBuilder(GET_QRCODE_URL); final StringBuilder url = new StringBuilder(GET_QRCODE_URL);
if (StringUtils.isNotBlank(path)) { if (StringUtils.isNotBlank(path)) {
url.append("?path=").append(URLEncoder.encode(path, StandardCharsets.UTF_8.name())); url.append("?path=").append(URLEncoder.encode(path, StandardCharsets.UTF_8.name()));
} }
qrCodeFilePath = this.wxMaService.execute(executor, url.toString(), null).toPath(); qrCodeFilePath = this.service.execute(executor, url.toString(), null).toPath();
return Files.readAllBytes(qrCodeFilePath); return Files.readAllBytes(qrCodeFilePath);
} catch (IOException e) { } catch (IOException e) {
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e); throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
@ -72,7 +72,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
@Override @Override
public List<WxMaCategory> getCategory() throws WxErrorException { public List<WxMaCategory> getCategory() throws WxErrorException {
String responseContent = this.wxMaService.get(GET_CATEGORY_URL, null); String responseContent = this.service.get(GET_CATEGORY_URL, null);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
boolean hasCategoryList = jsonObject.has("category_list"); boolean hasCategoryList = jsonObject.has("category_list");
if (hasCategoryList) { if (hasCategoryList) {
@ -86,7 +86,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
@Override @Override
public List<String> getPage() throws WxErrorException { public List<String> getPage() throws WxErrorException {
String responseContent = this.wxMaService.get(GET_PAGE_URL, null); String responseContent = this.service.get(GET_PAGE_URL, null);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
boolean hasPageList = jsonObject.has("page_list"); boolean hasPageList = jsonObject.has("page_list");
if (hasPageList) { if (hasPageList) {
@ -100,7 +100,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
@Override @Override
public long submitAudit(WxMaCodeSubmitAuditRequest auditRequest) throws WxErrorException { public long submitAudit(WxMaCodeSubmitAuditRequest auditRequest) throws WxErrorException {
String responseContent = this.wxMaService.post(SUBMIT_AUDIT_URL, auditRequest.toJson()); String responseContent = this.service.post(SUBMIT_AUDIT_URL, auditRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
return GsonHelper.getLong(jsonObject, "auditid"); return GsonHelper.getLong(jsonObject, "auditid");
} }
@ -109,36 +109,36 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
public WxMaCodeAuditStatus getAuditStatus(long auditId) throws WxErrorException { public WxMaCodeAuditStatus getAuditStatus(long auditId) throws WxErrorException {
JsonObject param = new JsonObject(); JsonObject param = new JsonObject();
param.addProperty("auditid", auditId); param.addProperty("auditid", auditId);
String responseContent = this.wxMaService.post(GET_AUDIT_STATUS_URL, param.toString()); String responseContent = this.service.post(GET_AUDIT_STATUS_URL, param.toString());
return WxMaCodeAuditStatus.fromJson(responseContent); return WxMaCodeAuditStatus.fromJson(responseContent);
} }
@Override @Override
public WxMaCodeAuditStatus getLatestAuditStatus() throws WxErrorException { public WxMaCodeAuditStatus getLatestAuditStatus() throws WxErrorException {
String responseContent = this.wxMaService.get(GET_LATEST_AUDIT_STATUS_URL, null); String responseContent = this.service.get(GET_LATEST_AUDIT_STATUS_URL, null);
return WxMaCodeAuditStatus.fromJson(responseContent); return WxMaCodeAuditStatus.fromJson(responseContent);
} }
@Override @Override
public void release() throws WxErrorException { public void release() throws WxErrorException {
this.wxMaService.post(RELEASE_URL, "{}"); this.service.post(RELEASE_URL, "{}");
} }
@Override @Override
public void changeVisitStatus(String action) throws WxErrorException { public void changeVisitStatus(String action) throws WxErrorException {
JsonObject param = new JsonObject(); JsonObject param = new JsonObject();
param.addProperty("action", action); param.addProperty("action", action);
this.wxMaService.post(CHANGE_VISIT_STATUS_URL, param.toString()); this.service.post(CHANGE_VISIT_STATUS_URL, param.toString());
} }
@Override @Override
public void revertCodeRelease() throws WxErrorException { public void revertCodeRelease() throws WxErrorException {
this.wxMaService.get(REVERT_CODE_RELEASE_URL, null); this.service.get(REVERT_CODE_RELEASE_URL, null);
} }
@Override @Override
public WxMaCodeVersionDistribution getSupportVersion() throws WxErrorException { public WxMaCodeVersionDistribution getSupportVersion() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_SUPPORT_VERSION_URL, "{}"); String responseContent = this.service.post(GET_SUPPORT_VERSION_URL, "{}");
return WxMaCodeVersionDistribution.fromJson(responseContent); return WxMaCodeVersionDistribution.fromJson(responseContent);
} }
@ -146,11 +146,11 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
public void setSupportVersion(String version) throws WxErrorException { public void setSupportVersion(String version) throws WxErrorException {
JsonObject param = new JsonObject(); JsonObject param = new JsonObject();
param.addProperty("version", version); param.addProperty("version", version);
this.wxMaService.post(SET_SUPPORT_VERSION_URL, param.toString()); this.service.post(SET_SUPPORT_VERSION_URL, param.toString());
} }
@Override @Override
public void undoCodeAudit() throws WxErrorException { public void undoCodeAudit() throws WxErrorException {
this.wxMaService.get(UNDO_CODE_AUDIT_URL, null); this.service.get(UNDO_CODE_AUDIT_URL, null);
} }
} }

View File

@ -9,7 +9,7 @@ import cn.binarywang.wx.miniapp.bean.express.WxMaExpressPrinter;
import cn.binarywang.wx.miniapp.bean.express.request.*; import cn.binarywang.wx.miniapp.bean.express.request.*;
import cn.binarywang.wx.miniapp.bean.express.result.WxMaExpressOrderInfoResult; import cn.binarywang.wx.miniapp.bean.express.result.WxMaExpressOrderInfoResult;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import java.util.HashMap; import java.util.HashMap;
@ -20,49 +20,48 @@ import java.util.Map;
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a> * @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2019-11-26 * @since 2019-11-26
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaExpressServiceImpl implements WxMaExpressService { public class WxMaExpressServiceImpl implements WxMaExpressService {
private final WxMaService service;
private WxMaService wxMaService;
@Override @Override
public List<WxMaExpressDelivery> getAllDelivery() throws WxErrorException { public List<WxMaExpressDelivery> getAllDelivery() throws WxErrorException {
String responseContent = this.wxMaService.get(ALL_DELIVERY_URL, null); String responseContent = this.service.get(ALL_DELIVERY_URL, null);
return WxMaExpressDelivery.fromJson(responseContent); return WxMaExpressDelivery.fromJson(responseContent);
} }
@Override @Override
public List<WxMaExpressAccount> getAllAccount() throws WxErrorException { public List<WxMaExpressAccount> getAllAccount() throws WxErrorException {
String responseContent = this.wxMaService.get(ALL_ACCOUNT_URL, null); String responseContent = this.service.get(ALL_ACCOUNT_URL, null);
return WxMaExpressAccount.fromJsonList(responseContent); return WxMaExpressAccount.fromJsonList(responseContent);
} }
@Override @Override
public void bindAccount(WxMaExpressBindAccountRequest wxMaExpressBindAccountRequest) throws WxErrorException { public void bindAccount(WxMaExpressBindAccountRequest wxMaExpressBindAccountRequest) throws WxErrorException {
this.wxMaService.post(BIND_ACCOUNT_URL,wxMaExpressBindAccountRequest.toJson()); this.service.post(BIND_ACCOUNT_URL, wxMaExpressBindAccountRequest.toJson());
} }
@Override @Override
public Integer getQuota(WxMaExpressBindAccountRequest wxMaExpressBindAccountRequest) throws WxErrorException { public Integer getQuota(WxMaExpressBindAccountRequest wxMaExpressBindAccountRequest) throws WxErrorException {
String responseContent = this.wxMaService.post(GET_QUOTA_URL,wxMaExpressBindAccountRequest.toJson()); String responseContent = this.service.post(GET_QUOTA_URL, wxMaExpressBindAccountRequest.toJson());
WxMaExpressAccount account = WxMaExpressAccount.fromJson(responseContent); WxMaExpressAccount account = WxMaExpressAccount.fromJson(responseContent);
return account.getQuotaNum(); return account.getQuotaNum();
} }
@Override @Override
public void updatePrinter(WxMaExpressPrinterUpdateRequest wxMaExpressPrinterUpdateRequest) throws WxErrorException { public void updatePrinter(WxMaExpressPrinterUpdateRequest wxMaExpressPrinterUpdateRequest) throws WxErrorException {
this.wxMaService.post(UPDATE_PRINTER_URL,wxMaExpressPrinterUpdateRequest.toJson()); this.service.post(UPDATE_PRINTER_URL, wxMaExpressPrinterUpdateRequest.toJson());
} }
@Override @Override
public WxMaExpressPrinter getPrinter() throws WxErrorException { public WxMaExpressPrinter getPrinter() throws WxErrorException {
String responseContent = this.wxMaService.get(GET_PRINTER_URL, null); String responseContent = this.service.get(GET_PRINTER_URL, null);
return WxMaExpressPrinter.fromJson(responseContent); return WxMaExpressPrinter.fromJson(responseContent);
} }
@Override @Override
public WxMaExpressOrderInfoResult addOrder(WxMaExpressAddOrderRequest wxMaExpressAddOrderRequest) throws WxErrorException { public WxMaExpressOrderInfoResult addOrder(WxMaExpressAddOrderRequest wxMaExpressAddOrderRequest) throws WxErrorException {
String responseContent = this.wxMaService.post(ADD_ORDER_URL,wxMaExpressAddOrderRequest.toJson()); String responseContent = this.service.post(ADD_ORDER_URL, wxMaExpressAddOrderRequest.toJson());
return WxMaExpressOrderInfoResult.fromJson(responseContent); return WxMaExpressOrderInfoResult.fromJson(responseContent);
} }
@ -70,29 +69,29 @@ public class WxMaExpressServiceImpl implements WxMaExpressService {
public List<WxMaExpressOrderInfoResult> batchGetOrder(List<WxMaExpressGetOrderRequest> requests) throws WxErrorException { public List<WxMaExpressOrderInfoResult> batchGetOrder(List<WxMaExpressGetOrderRequest> requests) throws WxErrorException {
Map<String, Object> param = new HashMap<>(1); Map<String, Object> param = new HashMap<>(1);
param.put("order_list", requests); param.put("order_list", requests);
String responseContent = this.wxMaService.post(BATCH_GET_ORDER_URL, WxMaGsonBuilder.create().toJson(param)); String responseContent = this.service.post(BATCH_GET_ORDER_URL, WxMaGsonBuilder.create().toJson(param));
return WxMaExpressOrderInfoResult.toList(responseContent); return WxMaExpressOrderInfoResult.toList(responseContent);
} }
@Override @Override
public void cancelOrder(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException { public void cancelOrder(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException {
this.wxMaService.post(CANCEL_ORDER_URL,wxMaExpressGetOrderRequest.toJson()); this.service.post(CANCEL_ORDER_URL, wxMaExpressGetOrderRequest.toJson());
} }
@Override @Override
public WxMaExpressOrderInfoResult getOrder(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException { public WxMaExpressOrderInfoResult getOrder(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException {
String responseContent = this.wxMaService.post(GET_ORDER_URL,wxMaExpressGetOrderRequest.toJson()); String responseContent = this.service.post(GET_ORDER_URL, wxMaExpressGetOrderRequest.toJson());
return WxMaExpressOrderInfoResult.fromJson(responseContent); return WxMaExpressOrderInfoResult.fromJson(responseContent);
} }
@Override @Override
public WxMaExpressPath getPath(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException { public WxMaExpressPath getPath(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException {
String responseContent = this.wxMaService.post(GET_PATH_URL,wxMaExpressGetOrderRequest.toJson()); String responseContent = this.service.post(GET_PATH_URL, wxMaExpressGetOrderRequest.toJson());
return WxMaExpressPath.fromJson(responseContent); return WxMaExpressPath.fromJson(responseContent);
} }
@Override @Override
public void testUpdateOrder(WxMaExpressTestUpdateOrderRequest wxMaExpressTestUpdateOrderRequest) throws WxErrorException { public void testUpdateOrder(WxMaExpressTestUpdateOrderRequest wxMaExpressTestUpdateOrderRequest) throws WxErrorException {
this.wxMaService.post(TEST_UPDATE_ORDER_URL,wxMaExpressTestUpdateOrderRequest.toJson()); this.service.post(TEST_UPDATE_ORDER_URL, wxMaExpressTestUpdateOrderRequest.toJson());
} }
} }

View File

@ -3,7 +3,7 @@ package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaJsapiService; import cn.binarywang.wx.miniapp.api.WxMaJsapiService;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.RandomUtils; import me.chanjar.weixin.common.util.RandomUtils;
@ -19,11 +19,9 @@ import java.util.concurrent.locks.Lock;
* *
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaJsapiServiceImpl implements WxMaJsapiService { public class WxMaJsapiServiceImpl implements WxMaJsapiService {
private final WxMaService service;
private WxMaService wxMaService;
@Override @Override
public String getCardApiTicket() throws WxErrorException { public String getCardApiTicket() throws WxErrorException {
@ -34,25 +32,25 @@ public class WxMaJsapiServiceImpl implements WxMaJsapiService {
public String getCardApiTicket(boolean forceRefresh) throws WxErrorException { public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
if (forceRefresh) { if (forceRefresh) {
this.wxMaService.getWxMaConfig().expireCardApiTicket(); this.service.getWxMaConfig().expireCardApiTicket();
} }
if (this.wxMaService.getWxMaConfig().isCardApiTicketExpired()) { if (this.service.getWxMaConfig().isCardApiTicketExpired()) {
Lock lock = this.wxMaService.getWxMaConfig().getCardApiTicketLock(); Lock lock = this.service.getWxMaConfig().getCardApiTicketLock();
lock.lock(); lock.lock();
try { try {
if (this.wxMaService.getWxMaConfig().isCardApiTicketExpired()) { if (this.service.getWxMaConfig().isCardApiTicketExpired()) {
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=wx_card", null); String responseContent = this.service.get(GET_JSAPI_TICKET_URL + "?type=wx_card", null);
JsonObject tmpJsonObject = GsonParser.parse(responseContent); JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String jsapiTicket = tmpJsonObject.get("ticket").getAsString(); String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxMaService.getWxMaConfig().updateCardApiTicket(jsapiTicket, expiresInSeconds); this.service.getWxMaConfig().updateCardApiTicket(jsapiTicket, expiresInSeconds);
} }
} finally { } finally {
lock.unlock(); lock.unlock();
} }
} }
return this.wxMaService.getWxMaConfig().getCardApiTicket(); return this.service.getWxMaConfig().getCardApiTicket();
} }
@Override @Override
@ -62,24 +60,24 @@ public class WxMaJsapiServiceImpl implements WxMaJsapiService {
@Override @Override
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException { public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
Lock lock = this.wxMaService.getWxMaConfig().getJsapiTicketLock(); Lock lock = this.service.getWxMaConfig().getJsapiTicketLock();
lock.lock(); lock.lock();
try { try {
if (forceRefresh) { if (forceRefresh) {
this.wxMaService.getWxMaConfig().expireJsapiTicket(); this.service.getWxMaConfig().expireJsapiTicket();
} }
if (this.wxMaService.getWxMaConfig().isJsapiTicketExpired()) { if (this.service.getWxMaConfig().isJsapiTicketExpired()) {
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=jsapi", null); String responseContent = this.service.get(GET_JSAPI_TICKET_URL + "?type=jsapi", null);
JsonObject tmpJsonObject = GsonParser.parse(responseContent); JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String jsapiTicket = tmpJsonObject.get("ticket").getAsString(); String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxMaService.getWxMaConfig().updateJsapiTicket(jsapiTicket, expiresInSeconds); this.service.getWxMaConfig().updateJsapiTicket(jsapiTicket, expiresInSeconds);
} }
} finally { } finally {
lock.unlock(); lock.unlock();
} }
return this.wxMaService.getWxMaConfig().getJsapiTicket(); return this.service.getWxMaConfig().getJsapiTicket();
} }
@Override @Override
@ -91,7 +89,7 @@ public class WxMaJsapiServiceImpl implements WxMaJsapiService {
"noncestr=" + randomStr, "timestamp=" + timestamp, "url=" + url); "noncestr=" + randomStr, "timestamp=" + timestamp, "url=" + url);
return WxJsapiSignature return WxJsapiSignature
.builder() .builder()
.appId(this.wxMaService.getWxMaConfig().getAppid()) .appId(this.service.getWxMaConfig().getAppid())
.timestamp(timestamp) .timestamp(timestamp)
.nonceStr(randomStr) .nonceStr(randomStr)
.url(url) .url(url)

View File

@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
@ -25,7 +26,7 @@ import java.util.Map;
* *
* @author <a href="https://github.com/lipengjun92">lipengjun (939961241@qq.com)</a> * @author <a href="https://github.com/lipengjun92">lipengjun (939961241@qq.com)</a>
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService { public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
private final WxMaService wxMaService; private final WxMaService wxMaService;

View File

@ -7,6 +7,7 @@ import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
@ -26,7 +27,7 @@ import java.util.Map;
* @author <a href="https://github.com/yjwang3300300">yjwang</a> * @author <a href="https://github.com/yjwang3300300">yjwang</a>
*/ */
@Slf4j @Slf4j
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaLiveServiceImpl implements WxMaLiveService { public class WxMaLiveServiceImpl implements WxMaLiveService {
private static final String ERR_CODE = "errcode"; private static final String ERR_CODE = "errcode";
private static final String ROOM_ID = "roomId"; private static final String ROOM_ID = "roomId";

View File

@ -3,6 +3,7 @@ package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaMediaService; import cn.binarywang.wx.miniapp.api.WxMaMediaService;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -20,7 +21,7 @@ import java.util.UUID;
/** /**
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaMediaServiceImpl implements WxMaMediaService { public class WxMaMediaServiceImpl implements WxMaMediaService {
private final WxMaService wxMaService; private final WxMaService wxMaService;

View File

@ -7,6 +7,7 @@ import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -15,19 +16,19 @@ import me.chanjar.weixin.common.util.json.GsonParser;
/** /**
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaMsgServiceImpl implements WxMaMsgService { public class WxMaMsgServiceImpl implements WxMaMsgService {
private final WxMaService wxMaService; private final WxMaService service;
@Override @Override
public boolean sendKefuMsg(WxMaKefuMessage message) throws WxErrorException { public boolean sendKefuMsg(WxMaKefuMessage message) throws WxErrorException {
String responseContent = this.wxMaService.post(KEFU_MESSAGE_SEND_URL, message.toJson()); String responseContent = this.service.post(KEFU_MESSAGE_SEND_URL, message.toJson());
return responseContent != null; return responseContent != null;
} }
@Override @Override
public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException { public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException {
String responseContent = this.wxMaService.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson()); String responseContent = this.service.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@ -36,7 +37,7 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
@Override @Override
public void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException { public void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException {
String responseContent = this.wxMaService.post(UNIFORM_MSG_SEND_URL, uniformMessage.toJson()); String responseContent = this.service.post(UNIFORM_MSG_SEND_URL, uniformMessage.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@ -45,13 +46,13 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
@Override @Override
public JsonObject createUpdatableMessageActivityId() throws WxErrorException { public JsonObject createUpdatableMessageActivityId() throws WxErrorException {
final String responseContent = this.wxMaService.get(ACTIVITY_ID_CREATE_URL, null); final String responseContent = this.service.get(ACTIVITY_ID_CREATE_URL, null);
return GsonParser.parse(responseContent); return GsonParser.parse(responseContent);
} }
@Override @Override
public void setUpdatableMsg(WxMaUpdatableMsg msg) throws WxErrorException { public void setUpdatableMsg(WxMaUpdatableMsg msg) throws WxErrorException {
this.wxMaService.post(UPDATABLE_MSG_SEND_URL, WxMaGsonBuilder.create().toJson(msg)); this.service.post(UPDATABLE_MSG_SEND_URL, WxMaGsonBuilder.create().toJson(msg));
} }
} }

View File

@ -33,7 +33,7 @@ public class WxMaOcrServiceImpl implements WxOcrService {
private static final String COMM = "https://api.weixin.qq.com/cv/ocr/comm?img_url=%s"; private static final String COMM = "https://api.weixin.qq.com/cv/ocr/comm?img_url=%s";
private static final String FILE_COMM = "https://api.weixin.qq.com/cv/ocr/comm"; private static final String FILE_COMM = "https://api.weixin.qq.com/cv/ocr/comm";
private final WxMaService mainService; private final WxMaService service;
@Override @Override
public WxOcrIdCardResult idCard(String imgUrl) throws WxErrorException { public WxOcrIdCardResult idCard(String imgUrl) throws WxErrorException {
@ -43,13 +43,13 @@ public class WxMaOcrServiceImpl implements WxOcrService {
// ignore cannot happen // ignore cannot happen
} }
final String result = this.mainService.post(String.format(IDCARD, imgUrl), (String) null); final String result = this.service.post(String.format(IDCARD, imgUrl), (String) null);
return WxOcrIdCardResult.fromJson(result); return WxOcrIdCardResult.fromJson(result);
} }
@Override @Override
public WxOcrIdCardResult idCard(File imgFile) throws WxErrorException { public WxOcrIdCardResult idCard(File imgFile) throws WxErrorException {
String result = this.mainService.execute(OcrDiscernRequestExecutor.create(this.mainService.getRequestHttp()), String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILEIDCARD, imgFile); FILEIDCARD, imgFile);
return WxOcrIdCardResult.fromJson(result); return WxOcrIdCardResult.fromJson(result);
} }
@ -62,13 +62,13 @@ public class WxMaOcrServiceImpl implements WxOcrService {
// ignore cannot happen // ignore cannot happen
} }
final String result = this.mainService.post(String.format(BANK_CARD, imgUrl), (String) null); final String result = this.service.post(String.format(BANK_CARD, imgUrl), (String) null);
return WxOcrBankCardResult.fromJson(result); return WxOcrBankCardResult.fromJson(result);
} }
@Override @Override
public WxOcrBankCardResult bankCard(File imgFile) throws WxErrorException { public WxOcrBankCardResult bankCard(File imgFile) throws WxErrorException {
String result = this.mainService.execute(OcrDiscernRequestExecutor.create(this.mainService.getRequestHttp()), String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_BANK_CARD, imgFile); FILE_BANK_CARD, imgFile);
return WxOcrBankCardResult.fromJson(result); return WxOcrBankCardResult.fromJson(result);
} }
@ -81,13 +81,13 @@ public class WxMaOcrServiceImpl implements WxOcrService {
// ignore cannot happen // ignore cannot happen
} }
final String result = this.mainService.post(String.format(DRIVING, imgUrl), (String) null); final String result = this.service.post(String.format(DRIVING, imgUrl), (String) null);
return WxOcrDrivingResult.fromJson(result); return WxOcrDrivingResult.fromJson(result);
} }
@Override @Override
public WxOcrDrivingResult driving(File imgFile) throws WxErrorException { public WxOcrDrivingResult driving(File imgFile) throws WxErrorException {
String result = this.mainService.execute(OcrDiscernRequestExecutor.create(this.mainService.getRequestHttp()), String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_DRIVING, imgFile); FILE_DRIVING, imgFile);
return WxOcrDrivingResult.fromJson(result); return WxOcrDrivingResult.fromJson(result);
} }
@ -100,13 +100,13 @@ public class WxMaOcrServiceImpl implements WxOcrService {
// ignore cannot happen // ignore cannot happen
} }
final String result = this.mainService.post(String.format(DRIVING_LICENSE, imgUrl), (String) null); final String result = this.service.post(String.format(DRIVING_LICENSE, imgUrl), (String) null);
return WxOcrDrivingLicenseResult.fromJson(result); return WxOcrDrivingLicenseResult.fromJson(result);
} }
@Override @Override
public WxOcrDrivingLicenseResult drivingLicense(File imgFile) throws WxErrorException { public WxOcrDrivingLicenseResult drivingLicense(File imgFile) throws WxErrorException {
String result = this.mainService.execute(OcrDiscernRequestExecutor.create(this.mainService.getRequestHttp()), String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_DRIVING_LICENSE, imgFile); FILE_DRIVING_LICENSE, imgFile);
return WxOcrDrivingLicenseResult.fromJson(result); return WxOcrDrivingLicenseResult.fromJson(result);
} }
@ -119,13 +119,13 @@ public class WxMaOcrServiceImpl implements WxOcrService {
// ignore cannot happen // ignore cannot happen
} }
final String result = this.mainService.post(String.format(BIZ_LICENSE, imgUrl), (String) null); final String result = this.service.post(String.format(BIZ_LICENSE, imgUrl), (String) null);
return WxOcrBizLicenseResult.fromJson(result); return WxOcrBizLicenseResult.fromJson(result);
} }
@Override @Override
public WxOcrBizLicenseResult bizLicense(File imgFile) throws WxErrorException { public WxOcrBizLicenseResult bizLicense(File imgFile) throws WxErrorException {
String result = this.mainService.execute(OcrDiscernRequestExecutor.create(this.mainService.getRequestHttp()), String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_BIZ_LICENSE, imgFile); FILE_BIZ_LICENSE, imgFile);
return WxOcrBizLicenseResult.fromJson(result); return WxOcrBizLicenseResult.fromJson(result);
} }
@ -138,13 +138,13 @@ public class WxMaOcrServiceImpl implements WxOcrService {
// ignore cannot happen // ignore cannot happen
} }
final String result = this.mainService.post(String.format(COMM, imgUrl), (String) null); final String result = this.service.post(String.format(COMM, imgUrl), (String) null);
return WxOcrCommResult.fromJson(result); return WxOcrCommResult.fromJson(result);
} }
@Override @Override
public WxOcrCommResult comm(File imgFile) throws WxErrorException { public WxOcrCommResult comm(File imgFile) throws WxErrorException {
String result = this.mainService.execute(OcrDiscernRequestExecutor.create(this.mainService.getRequestHttp()), String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_COMM, imgFile); FILE_COMM, imgFile);
return WxOcrCommResult.fromJson(result); return WxOcrCommResult.fromJson(result);
} }

View File

@ -12,7 +12,7 @@ import java.util.Map;
@AllArgsConstructor @AllArgsConstructor
public class WxMaPluginServiceImpl implements WxMaPluginService { public class WxMaPluginServiceImpl implements WxMaPluginService {
private WxMaService wxMaService; private final WxMaService service;
@Override @Override
public void applyPlugin(String pluginAppId, String reason) throws WxErrorException { public void applyPlugin(String pluginAppId, String reason) throws WxErrorException {
@ -20,21 +20,21 @@ public class WxMaPluginServiceImpl implements WxMaPluginService {
"plugin_appid", pluginAppId, "plugin_appid", pluginAppId,
"reason", reason); "reason", reason);
this.wxMaService.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params)); this.service.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params));
} }
@Override @Override
public WxMaPluginListResult getPluginList() throws WxErrorException { public WxMaPluginListResult getPluginList() throws WxErrorException {
Map<String, String> params = ImmutableMap.of("action", "list"); Map<String, String> params = ImmutableMap.of("action", "list");
String responseContent = this.wxMaService.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params)); String responseContent = this.service.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params));
return WxMaPluginListResult.fromJson(responseContent); return WxMaPluginListResult.fromJson(responseContent);
} }
@Override @Override
public void unbindPlugin(String pluginAppId) throws WxErrorException { public void unbindPlugin(String pluginAppId) throws WxErrorException {
Map<String, String> params = ImmutableMap.of("action", "unbind", "plugin_appid", pluginAppId); Map<String, String> params = ImmutableMap.of("action", "unbind", "plugin_appid", pluginAppId);
this.wxMaService.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params)); this.service.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params));
} }
@Override @Override
@ -43,6 +43,6 @@ public class WxMaPluginServiceImpl implements WxMaPluginService {
"plugin_appid", pluginAppId, "plugin_appid", pluginAppId,
"user_version", userVersion); "user_version", userVersion);
this.wxMaService.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params)); this.service.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params));
} }
} }

View File

@ -9,6 +9,7 @@ import cn.binarywang.wx.miniapp.bean.WxaCodeUnlimit;
import cn.binarywang.wx.miniapp.executor.QrcodeBytesRequestExecutor; import cn.binarywang.wx.miniapp.executor.QrcodeBytesRequestExecutor;
import cn.binarywang.wx.miniapp.executor.QrcodeRequestExecutor; import cn.binarywang.wx.miniapp.executor.QrcodeRequestExecutor;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import java.io.File; import java.io.File;
@ -16,18 +17,18 @@ import java.io.File;
/** /**
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { public class WxMaQrcodeServiceImpl implements WxMaQrcodeService {
private WxMaService wxMaService; private final WxMaService service;
@Override @Override
public byte[] createQrcodeBytes(String path, int width) throws WxErrorException { public byte[] createQrcodeBytes(String path, int width) throws WxErrorException {
return this.wxMaService.execute(QrcodeBytesRequestExecutor.create(this.wxMaService.getRequestHttp()), CREATE_QRCODE_URL, new WxMaQrcode(path, width)); return this.service.execute(QrcodeBytesRequestExecutor.create(this.service.getRequestHttp()), CREATE_QRCODE_URL, new WxMaQrcode(path, width));
} }
@Override @Override
public File createQrcode(String path, int width) throws WxErrorException { public File createQrcode(String path, int width) throws WxErrorException {
return this.wxMaService.execute(QrcodeRequestExecutor.create(this.wxMaService.getRequestHttp()), CREATE_QRCODE_URL, new WxMaQrcode(path, width)); return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp()), CREATE_QRCODE_URL, new WxMaQrcode(path, width));
} }
@Override @Override
@ -38,7 +39,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService {
@Override @Override
public byte[] createWxaCodeBytes(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) public byte[] createWxaCodeBytes(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline)
throws WxErrorException { throws WxErrorException {
return this.wxMaService.execute(QrcodeBytesRequestExecutor.create(this.wxMaService.getRequestHttp()), GET_WXACODE_URL, WxaCode.builder() return this.service.execute(QrcodeBytesRequestExecutor.create(this.service.getRequestHttp()), GET_WXACODE_URL, WxaCode.builder()
.path(path) .path(path)
.width(width) .width(width)
.autoColor(autoColor) .autoColor(autoColor)
@ -50,7 +51,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService {
@Override @Override
public File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) public File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline)
throws WxErrorException { throws WxErrorException {
return this.wxMaService.execute(QrcodeRequestExecutor.create(this.wxMaService.getRequestHttp()), GET_WXACODE_URL, WxaCode.builder() return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp()), GET_WXACODE_URL, WxaCode.builder()
.path(path) .path(path)
.width(width) .width(width)
.autoColor(autoColor) .autoColor(autoColor)
@ -72,7 +73,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService {
@Override @Override
public byte[] createWxaCodeUnlimitBytes(String scene, String page, int width, boolean autoColor, public byte[] createWxaCodeUnlimitBytes(String scene, String page, int width, boolean autoColor,
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException { WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException {
return this.wxMaService.execute(QrcodeBytesRequestExecutor.create(this.wxMaService.getRequestHttp()), return this.service.execute(QrcodeBytesRequestExecutor.create(this.service.getRequestHttp()),
GET_WXACODE_UNLIMIT_URL, GET_WXACODE_UNLIMIT_URL,
this.buildWxaCodeUnlimit(scene, page, width, autoColor, lineColor, isHyaline)); this.buildWxaCodeUnlimit(scene, page, width, autoColor, lineColor, isHyaline));
} }
@ -80,7 +81,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService {
@Override @Override
public File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor, public File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor,
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException { WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException {
return this.wxMaService.execute(QrcodeRequestExecutor.create(this.wxMaService.getRequestHttp()), return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp()),
GET_WXACODE_UNLIMIT_URL, GET_WXACODE_UNLIMIT_URL,
this.buildWxaCodeUnlimit(scene, page, width, autoColor, lineColor, isHyaline)); this.buildWxaCodeUnlimit(scene, page, width, autoColor, lineColor, isHyaline));
} }
@ -105,7 +106,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService {
@Override @Override
public File createQrcode(String path, int width, String filePath) throws WxErrorException { public File createQrcode(String path, int width, String filePath) throws WxErrorException {
return this.wxMaService.execute(QrcodeRequestExecutor.create(this.wxMaService.getRequestHttp(), filePath), CREATE_QRCODE_URL, new WxMaQrcode(path, width)); return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp(), filePath), CREATE_QRCODE_URL, new WxMaQrcode(path, width));
} }
@Override @Override
@ -116,7 +117,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService {
@Override @Override
public File createWxaCode(String path, int width, String filePath, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) public File createWxaCode(String path, int width, String filePath, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline)
throws WxErrorException { throws WxErrorException {
return this.wxMaService.execute(QrcodeRequestExecutor.create(this.wxMaService.getRequestHttp(), filePath), GET_WXACODE_URL, WxaCode.builder() return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp(), filePath), GET_WXACODE_URL, WxaCode.builder()
.path(path) .path(path)
.width(width) .width(width)
.autoColor(autoColor) .autoColor(autoColor)
@ -138,7 +139,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService {
@Override @Override
public File createWxaCodeUnlimit(String scene, String page, String filePath, int width, boolean autoColor, public File createWxaCodeUnlimit(String scene, String page, String filePath, int width, boolean autoColor,
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException { WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException {
return this.wxMaService.execute(QrcodeRequestExecutor.create(this.wxMaService.getRequestHttp(), filePath), return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp(), filePath),
GET_WXACODE_UNLIMIT_URL, GET_WXACODE_UNLIMIT_URL,
this.buildWxaCodeUnlimit(scene, page, width, autoColor, lineColor, isHyaline)); this.buildWxaCodeUnlimit(scene, page, width, autoColor, lineColor, isHyaline));
} }

View File

@ -7,18 +7,18 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaRunStepInfo; import cn.binarywang.wx.miniapp.bean.WxMaRunStepInfo;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
/** /**
* <pre> * <pre>
*
* Created by Binary Wang on 2018/11/4. * Created by Binary Wang on 2018/11/4.
* </pre> * </pre>
* *
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaRunServiceImpl implements WxMaRunService { public class WxMaRunServiceImpl implements WxMaRunService {
private WxMaService service; private final WxMaService service;
@Override @Override
public List<WxMaRunStepInfo> getRunStepInfo(String sessionKey, String encryptedData, String ivStr) { public List<WxMaRunStepInfo> getRunStepInfo(String sessionKey, String encryptedData, String ivStr) {

View File

@ -4,7 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaSecCheckService;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult; import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -23,9 +23,9 @@ import java.net.URL;
* *
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaSecCheckServiceImpl implements WxMaSecCheckService { public class WxMaSecCheckServiceImpl implements WxMaSecCheckService {
private WxMaService service; private final WxMaService service;
@Override @Override
public boolean checkImage(File file) throws WxErrorException { public boolean checkImage(File file) throws WxErrorException {

View File

@ -4,7 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaSettingService; import cn.binarywang.wx.miniapp.api.WxMaSettingService;
import cn.binarywang.wx.miniapp.bean.WxMaDomainAction; import cn.binarywang.wx.miniapp.bean.WxMaDomainAction;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import java.util.HashMap; import java.util.HashMap;
@ -14,9 +14,9 @@ import java.util.Map;
* @author <a href="https://github.com/charmingoh">Charming</a> * @author <a href="https://github.com/charmingoh">Charming</a>
* @since 2018-04-27 15:46 * @since 2018-04-27 15:46
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaSettingServiceImpl implements WxMaSettingService { public class WxMaSettingServiceImpl implements WxMaSettingService {
private WxMaService wxMaService; private final WxMaService wxMaService;
@Override @Override
public WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException { public WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException {

View File

@ -4,14 +4,14 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShareService; import cn.binarywang.wx.miniapp.api.WxMaShareService;
import cn.binarywang.wx.miniapp.bean.WxMaShareInfo; import cn.binarywang.wx.miniapp.bean.WxMaShareInfo;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
/** /**
* @author zhfish * @author zhfish
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaShareServiceImpl implements WxMaShareService { public class WxMaShareServiceImpl implements WxMaShareService {
private WxMaService service; private final WxMaService service;
@Override @Override
public WxMaShareInfo getShareInfo(String sessionKey, String encryptedData, String ivStr) { public WxMaShareInfo getShareInfo(String sessionKey, String encryptedData, String ivStr) {

View File

@ -7,7 +7,7 @@ import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -19,9 +19,9 @@ import java.util.List;
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2019-12-15 * @date 2019-12-15
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaSubscribeServiceImpl implements WxMaSubscribeService { public class WxMaSubscribeServiceImpl implements WxMaSubscribeService {
private WxMaService wxMaService; private final WxMaService wxMaService;
@Override @Override
public WxMaPubTemplateTitleListResult getPubTemplateTitleList(String[] ids, int start, int limit) throws WxErrorException { public WxMaPubTemplateTitleListResult getPubTemplateTitleList(String[] ids, int start, int limit) throws WxErrorException {

View File

@ -9,7 +9,7 @@ import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.SignUtils; import me.chanjar.weixin.common.util.SignUtils;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
@ -19,9 +19,9 @@ import java.util.Map;
/** /**
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
@AllArgsConstructor @RequiredArgsConstructor
public class WxMaUserServiceImpl implements WxMaUserService { public class WxMaUserServiceImpl implements WxMaUserService {
private WxMaService service; private final WxMaService service;
@Override @Override
public WxMaJscode2SessionResult getSessionInfo(String jsCode) throws WxErrorException { public WxMaJscode2SessionResult getSessionInfo(String jsCode) throws WxErrorException {