mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-25 01:14:36 +08:00
🆕 #2198 【小程序】增加根据提交信息数据获取用户安全等级的接口
This commit is contained in:
parent
a79b05cd45
commit
1af394cdd9
@ -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();
|
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 WxMaDeviceSubscribeService deviceSubscribeService = new WxMaDeviceSubscribeServiceImpl(this);
|
||||||
private final WxMaMarketingService marketingService = new WxMaMarketingServiceImpl(this);
|
private final WxMaMarketingService marketingService = new WxMaMarketingServiceImpl(this);
|
||||||
private final WxMaImmediateDeliveryService immediateDeliveryService = new WxMaImmediateDeliveryServiceImpl(this);
|
private final WxMaImmediateDeliveryService immediateDeliveryService = new WxMaImmediateDeliveryServiceImpl(this);
|
||||||
|
private final WxMaSafetyRiskControlService safetyRiskControlService = new WxMaSafetyRiskControlServiceImpl(this);
|
||||||
private Map<String, WxMaConfig> configMap;
|
private Map<String, WxMaConfig> configMap;
|
||||||
private int retrySleepMillis = 1000;
|
private int retrySleepMillis = 1000;
|
||||||
private int maxRetryTimes = 5;
|
private int maxRetryTimes = 5;
|
||||||
@ -587,4 +588,8 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
|||||||
public WxMaImmediateDeliveryService getWxMaImmediateDeliveryService() {
|
public WxMaImmediateDeliveryService getWxMaImmediateDeliveryService() {
|
||||||
return this.immediateDeliveryService;
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,6 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import sun.rmi.runtime.Log;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
package cn.binarywang.wx.miniapp.bean.safety.request;
|
||||||
|
|
||||||
|
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户的安全等级请求参数
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/azouever">azouever</a>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WxMaUserSafetyRiskRankRequest implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1052539797739665816L;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序appid
|
||||||
|
* 必填
|
||||||
|
*/
|
||||||
|
private String appid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的openid
|
||||||
|
* 必填
|
||||||
|
*/
|
||||||
|
private String openid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 场景值,0:注册,1:营销作弊
|
||||||
|
* 必填
|
||||||
|
*/
|
||||||
|
private Integer scene;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户手机号
|
||||||
|
* 非必填
|
||||||
|
*/
|
||||||
|
@SerializedName("mobile_no")
|
||||||
|
private String mobileNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户访问源ip
|
||||||
|
* 必填
|
||||||
|
*/
|
||||||
|
@SerializedName("client_ip")
|
||||||
|
private String clientIp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户邮箱地址
|
||||||
|
* 非必填
|
||||||
|
*/
|
||||||
|
@SerializedName("email_address")
|
||||||
|
private String emailAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外补充信息
|
||||||
|
* 非必填
|
||||||
|
*/
|
||||||
|
@SerializedName("extended_info")
|
||||||
|
private String extendedInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* false:正式调用,true:测试调用
|
||||||
|
* 非必填
|
||||||
|
*/
|
||||||
|
@SerializedName("is_test")
|
||||||
|
private boolean isTest;
|
||||||
|
|
||||||
|
public String toJson() {
|
||||||
|
return WxMaGsonBuilder.create().toJson(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package cn.binarywang.wx.miniapp.bean.safety.response;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户的安全等级响应参数
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/azouever">azouever</a>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WxMaUserSafetyRiskRankResponse implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2434941857751339150L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 唯一请求标识,标记单次请求
|
||||||
|
*/
|
||||||
|
@SerializedName("unoin_id")
|
||||||
|
private Integer unoinId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户风险等级
|
||||||
|
* 合法值 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/safety-control-capability/riskControl.getUserRiskRank.html
|
||||||
|
*/
|
||||||
|
@SerializedName("risk_rank")
|
||||||
|
private Integer riskRank;
|
||||||
|
|
||||||
|
public static WxMaUserSafetyRiskRankResponse fromJson(String json) {
|
||||||
|
return WxGsonBuilder.create().fromJson(json, WxMaUserSafetyRiskRankResponse.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,5 +16,5 @@ public class WxMaShopAddOrderResponse extends WxMaShopBaseResponse implements Se
|
|||||||
private static final long serialVersionUID = -8923439859095040010L;
|
private static final long serialVersionUID = -8923439859095040010L;
|
||||||
|
|
||||||
@SerializedName("data")
|
@SerializedName("data")
|
||||||
private WxMaShopAddOrderResult date;
|
private WxMaShopAddOrderResult data;
|
||||||
}
|
}
|
||||||
|
@ -523,6 +523,17 @@ public class WxMaApiUrlConstants {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全风控
|
||||||
|
*/
|
||||||
|
interface SafetyRiskControl {
|
||||||
|
/**
|
||||||
|
* 获取用户的安全等级,无需用户授权
|
||||||
|
*/
|
||||||
|
String GET_USER_RISK_RANK = "https://api.weixin.qq.com/wxa/getuserriskrank";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package cn.binarywang.wx.miniapp.api.impl;
|
||||||
|
|
||||||
|
|
||||||
|
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.test.ApiTestModule;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import org.testng.annotations.Guice;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.testng.AssertJUnit.assertNotNull;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Guice(modules = ApiTestModule.class)
|
||||||
|
public class WxMaSafetyRiskControlServiceImplTest {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected WxMaService wxService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetUserRiskRank() throws WxErrorException {
|
||||||
|
WxMaUserSafetyRiskRankRequest wxMaUserSafetyRiskRankRequest = WxMaUserSafetyRiskRankRequest.builder()
|
||||||
|
.appid("")
|
||||||
|
.openid("")
|
||||||
|
.scene(1)
|
||||||
|
.isTest(true)
|
||||||
|
.build();
|
||||||
|
WxMaUserSafetyRiskRankResponse wxMaUserSafetyRiskRankResponse = this.wxService.getSafetyRiskControlService().getUserRiskRank(wxMaUserSafetyRiskRankRequest);
|
||||||
|
assertNotNull(wxMaUserSafetyRiskRankResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user