mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🆕 #2198 【小程序】增加根据提交信息数据获取用户安全等级的接口
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.safety.request.WxMaUserSafetyRiskRankRequest;
|
||||
import cn.binarywang.wx.miniapp.bean.safety.response.WxMaUserSafetyRiskRankResponse;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 小程序安全风控相关接口
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/azouever">azouever</a>
|
||||
*/
|
||||
public interface WxMaSafetyRiskControlService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 根据提交的用户信息数据获取用户的安全等级,无需用户授权
|
||||
* 文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/safety-control-capability/riskControl.getUserRiskRank.html
|
||||
* </pre>
|
||||
*
|
||||
* @param wxMaUserSafetyRiskRankRequest 获取用户安全等级请求
|
||||
* @throws WxErrorException 通用异常
|
||||
*/
|
||||
WxMaUserSafetyRiskRankResponse getUserRiskRank(WxMaUserSafetyRiskRankRequest wxMaUserSafetyRiskRankRequest) throws WxErrorException;
|
||||
|
||||
}
|
||||
@@ -484,4 +484,12 @@ public interface WxMaService extends WxService {
|
||||
*/
|
||||
WxMaImmediateDeliveryService getWxMaImmediateDeliveryService();
|
||||
|
||||
|
||||
/**
|
||||
* 小程序安全风控相关接口服务
|
||||
*
|
||||
* @return safetyRiskControl service
|
||||
*/
|
||||
WxMaSafetyRiskControlService getSafetyRiskControlService();
|
||||
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
private final WxMaDeviceSubscribeService deviceSubscribeService = new WxMaDeviceSubscribeServiceImpl(this);
|
||||
private final WxMaMarketingService marketingService = new WxMaMarketingServiceImpl(this);
|
||||
private final WxMaImmediateDeliveryService immediateDeliveryService = new WxMaImmediateDeliveryServiceImpl(this);
|
||||
private final WxMaSafetyRiskControlService safetyRiskControlService = new WxMaSafetyRiskControlServiceImpl(this);
|
||||
private Map<String, WxMaConfig> configMap;
|
||||
private int retrySleepMillis = 1000;
|
||||
private int maxRetryTimes = 5;
|
||||
@@ -587,4 +588,8 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
public WxMaImmediateDeliveryService getWxMaImmediateDeliveryService() {
|
||||
return this.immediateDeliveryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaSafetyRiskControlService getSafetyRiskControlService(){ return this.safetyRiskControlService; }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaSafetyRiskControlService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.safety.request.WxMaUserSafetyRiskRankRequest;
|
||||
import cn.binarywang.wx.miniapp.bean.safety.response.WxMaUserSafetyRiskRankResponse;
|
||||
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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.util.json.GsonParser;
|
||||
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.InstantDelivery.SafetyRiskControl.GET_USER_RISK_RANK;
|
||||
|
||||
/**
|
||||
* @author azouever
|
||||
*/
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class WxMaSafetyRiskControlServiceImpl implements WxMaSafetyRiskControlService {
|
||||
|
||||
private final WxMaService service;
|
||||
|
||||
@Override
|
||||
public WxMaUserSafetyRiskRankResponse getUserRiskRank(WxMaUserSafetyRiskRankRequest wxMaUserSafetyRiskRankRequest) throws WxErrorException {
|
||||
String responseContent = this.service.post(GET_USER_RISK_RANK, wxMaUserSafetyRiskRankRequest.toJson());
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return WxMaUserSafetyRiskRankResponse.fromJson(responseContent);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user