Authored by chenchao
Committed by LUOXC

add risk watch

(cherry picked from commit 78c9f3a2)
package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.AlipayBlackUser;
public interface AlipayBlackUserMapper {
int insert(AlipayBlackUser record);
int insertSelective(AlipayBlackUser record);
AlipayBlackUser selectByAlipayUid(String alipayUid);
int updateByPrimaryKeySelective(AlipayBlackUser record);
int updateByPrimaryKey(AlipayBlackUser record);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
public class AlipayBlackUser {
private Integer id;
private String alipayUid;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAlipayUid() {
return alipayUid;
}
public void setAlipayUid(String alipayUid) {
this.alipayUid = alipayUid == null ? null : alipayUid.trim();
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yohoufo.dal.order.AlipayBlackUserMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.AlipayBlackUser">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="alipay_uid" jdbcType="VARCHAR" property="alipayUid" />
</resultMap>
<sql id="Base_Column_List">
id, alipay_uid
</sql>
<select id="selectByAlipayUid" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from alipay_black_user
where alipay_uid = #{alipayUid,jdbcType=VARCHAR}
</select>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.AlipayBlackUser" useGeneratedKeys="true">
insert into alipay_black_user (alipay_uid)
values (#{alipayUid,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.AlipayBlackUser" useGeneratedKeys="true">
insert into alipay_black_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="alipayUid != null">
alipay_uid,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="alipayUid != null">
#{alipayUid,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.AlipayBlackUser">
update alipay_black_user
<set>
<if test="alipayUid != null">
alipay_uid = #{alipayUid,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.AlipayBlackUser">
update alipay_black_user
set alipay_uid = #{alipayUid,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -91,5 +91,12 @@ public class AlarmEventBuilder {
return smsAlarmEvent;
}
public static SmsAlarmEvent buildAlipayBlackUidAlarmEvent(int uid, String alipayUid){
SmsAlarmEvent smsAlarmEvent ;
String content ;
content = "拦截到支付宝黑名单用户:"+ uid +",alipayUid:" + alipayUid ;
smsAlarmEvent = new SmsAlarmEvent("ufoOrder.alipayBlackUid", "ufoOrder.alipayBlackUidIntercept", content);
return smsAlarmEvent;
}
}
... ...
... ... @@ -31,20 +31,14 @@ import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.model.response.PaymentConfirmRsp;
import com.yohoufo.order.model.response.PrepayResponse;
import com.yohoufo.order.service.*;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.mq.producer.TradeMqSender;
import com.yohoufo.order.service.AbstractOrderPaymentService;
import com.yohoufo.order.service.BuyerOrderPaymentService;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.SellerOrderPaymentService;
import com.yohoufo.order.service.*;
import com.yohoufo.order.service.handler.BuyerOrderPayDiffTimeHandler;
import com.yohoufo.order.service.handler.transfer.AlipayTransferChancelSelector;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
import com.yohoufo.order.service.pay.unionpay.JsUnionpayService;
import com.yohoufo.order.service.pay.unionpay.UnionpayServiceAbstract;
import com.yohoufo.order.service.pay.wallet.WalletPayService;
import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService;
import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService;
... ... @@ -53,7 +47,6 @@ import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.service.transfer.TransferResult;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.PaymentHelper;
import lombok.val;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -168,6 +161,9 @@ public class PaymentServiceImpl implements IPaymentService {
@Autowired
private TradeMqSender tradeMqSender;
@Autowired
private ShoppingRiskWatchDog shoppingRiskWatchDog;
/**
* 获取主场的订单service
*
... ... @@ -692,7 +688,8 @@ public class PaymentServiceImpl implements IPaymentService {
}
@Database(ForceMaster = true)
public boolean transAllEarnest(long orderCode, Integer uid, BigDecimal amount, AuthorizeResultRespVO aliPayAccount) {
public boolean transAllEarnest(long orderCode, Integer uid, BigDecimal amount,
AuthorizeResultRespVO aliPayAccount) {
logger.info("退还商家所有保证金,转账开始,orderCode = {}, uid={}, amount={}, alipayAccount={}", orderCode, uid, amount, aliPayAccount);
int now = (int) (System.currentTimeMillis() / 1000);
... ... @@ -743,7 +740,7 @@ public class PaymentServiceImpl implements IPaymentService {
transfer.setUpdateTime(now);
try {
logger.info("transAllEarnest开始调用阿里接口参数buyerOrderCode={}, alipayAccount={}, transferAmount={}", orderCode, account, amount);
shoppingRiskWatchDog.checkAlipayBlackUser(aliPayAccount.getUid(), aliPayAccount.getAlipayId());
if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {
transfer.setInterfaceType(2);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
... ... @@ -1120,12 +1117,14 @@ public class PaymentServiceImpl implements IPaymentService {
addTradeBills(tradeBills);
}
private void transferWithAlipayTransferAndAddSuccessTradeBills(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
TransferResult transferResult = alipayService.newAlipayTransfer()
TransferResult transferResult = alipayService.newAlipayTransfer(account.getUid())
.transferOrderCode(Long.toString(orderCode))
.alipayUid(account.getAlipayId())
.alipayAccount(account.getAlipayAccount())
.transferAmount(amount)
.riskWatcher((uid, alipayUid)-> shoppingRiskWatchDog.checkAlipayBlackUser(uid, alipayUid) )
.transfer();
if (transferResult.getCode() == 200) {
logger.info("{}, transfer success and out trade no is {}", logTag, orderCode);
... ... @@ -1146,11 +1145,13 @@ public class PaymentServiceImpl implements IPaymentService {
}
private void transferWithAlipayTransfer(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
TransferResult transferResult = alipayService.newAlipayTransfer()
TransferResult transferResult = alipayService.newAlipayTransfer(account.getUid())
.transferOrderCode(Long.toString(orderCode))
.alipayUid(account.getAlipayId())
.alipayAccount(account.getAlipayAccount())
.transferAmount(amount)
.riskWatcher((uid, alipayUid)-> shoppingRiskWatchDog.checkAlipayBlackUser(uid, alipayUid))
.transfer();
if (transferResult.getCode() == 200) {
logger.info("{}, transfer success and out trade no is {}", logTag, orderCode);
... ... @@ -1171,15 +1172,21 @@ public class PaymentServiceImpl implements IPaymentService {
}
}
private void transferWithAlipayExceedMillionTransfer(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
private void transferWithAlipayExceedMillionTransfer(String logTag,
TradeBills tradeBills,
long orderCode,
AuthorizeResultRespVO account,
BigDecimal amount,
OrdersPayTransfer transfer) {
String businessId = transfer.getId() + "_" + tradeBills.getId();
TransferResult transferResult = alipayService.newAlipayExceedMillionTransfer()
TransferResult transferResult = alipayService.newAlipayExceedMillionTransfer(account.getUid())
.transferOrderCode(Long.toString(orderCode))
.alipayUid(account.getAlipayId())
.alipayAccount(account.getAlipayAccount())
.transferAmount(amount)
.businessId(businessId)
.userName(account.getCertName())
.riskWatcher((uid, alipayUid)-> shoppingRiskWatchDog.checkAlipayBlackUser(uid, alipayUid))
.transfer();
// success to wait
if (transferResult.getCode() == 200) {
... ... @@ -1196,8 +1203,12 @@ public class PaymentServiceImpl implements IPaymentService {
}
private Map<String, String> transferWhenExceedMillion(Integer transferId, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account,
private Map<String, String> transferWhenExceedMillion(Integer transferId,
TradeBills tradeBills,
long orderCode,
AuthorizeResultRespVO account,
BigDecimal amount, int now) throws Exception {
Map<String, String> mapResult = alipayService.transferMoneyWhenExceedMillion(
Long.toString(orderCode),
transferId + "_" + tradeBills.getId(),
... ...
... ... @@ -2,19 +2,25 @@ package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.constants.RegionEnum;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.AlipayBlackUserMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.order.constants.ClientSpecialSemanticCode;
import com.yohoufo.order.convert.builder.AlarmEventBuilder;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.SellerGoodsHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* 购物风控
... ... @@ -32,6 +38,9 @@ public class ShoppingRiskWatchDog {
@Autowired
private UserProxyService userProxyService;
@Autowired
private AlipayBlackUserMapper alipayBlackUserMapper;
public void checkWaitingPayCnt(int uid){
logger.info("in ShoppingRiskWatchDog.checkWaitingPayCnt uid {}", uid);
List<Integer> statusList = new ArrayList<>(1);
... ... @@ -53,4 +62,18 @@ public class ShoppingRiskWatchDog {
}
}
}
public void checkAlipayBlackUser(int uid, String alipayUid){
if (StringUtils.isBlank(alipayUid)){
logger.warn("in checkAlipayBlackUser alipayUid null, uid {}", uid);
return;
}
if(Objects.nonNull(alipayBlackUserMapper.selectByAlipayUid(alipayUid))){
logger.info("checkAlipayBlackUser intercept black uid {} alipay uid {}", uid, alipayUid);
SmsAlarmEvent smsAlarmEvent = AlarmEventBuilder.buildAlipayBlackUidAlarmEvent(uid, alipayUid);
EventBusPublisher.publishEvent(smsAlarmEvent);
throw new UfoServiceException(441, "支付宝黑名单");
}
}
}
... ...
... ... @@ -7,6 +7,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.HttpClient;
import com.yohoufo.common.utils.MD5Utils;
... ... @@ -37,6 +38,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
public abstract class AlipayServiceAbstract extends AbstractPayService {
... ... @@ -192,14 +195,15 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
public class AlipayTransfer implements TransferChannel {
int uid;
String transferOrderCode;
String alipayUid;
String alipayAccount;
BigDecimal transferAmount;
BiConsumer<Integer, String> rishWatcherConsumer;
private AlipayTransfer(){
private AlipayTransfer(int uid){
this.uid = uid;
}
public AlipayTransfer transferOrderCode(String transferOrderCode){
... ... @@ -222,8 +226,14 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
return this;
}
public AlipayTransfer riskWatcher(BiConsumer<Integer, String> rishWatcherConsumer){
this.rishWatcherConsumer = rishWatcherConsumer;
return this;
}
@Override
public TransferResult transfer() {
rishWatcherConsumer.accept(uid, alipayUid);
Map<String, String> queryParams = buildTransferParams(transferOrderCode, alipayUid, alipayAccount, transferAmount);
String respTxt;
try {
... ... @@ -272,12 +282,12 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
}
public AlipayTransfer newAlipayTransfer(){
return new AlipayTransfer();
public AlipayTransfer newAlipayTransfer(int uid){
return new AlipayTransfer(uid);
}
public AlipayExceedMillionTransferChannel newAlipayExceedMillionTransfer(){
return new AlipayExceedMillionTransferChannel();
public AlipayExceedMillionTransferChannel newAlipayExceedMillionTransfer(int uid){
return new AlipayExceedMillionTransferChannel(uid);
}
... ... @@ -307,16 +317,16 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
public class AlipayExceedMillionTransferChannel implements TransferChannel{
int uid;
String transferOrderCode;
String alipayUid;
String alipayAccount;
BigDecimal transferAmount;
String businessId;
String userName;
private AlipayExceedMillionTransferChannel(){
BiConsumer<Integer, String> riskWatcher;
private AlipayExceedMillionTransferChannel(int uid){
this.uid = uid;
}
public AlipayExceedMillionTransferChannel transferOrderCode(String transferOrderCode){
... ... @@ -349,6 +359,11 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
return this;
}
public AlipayExceedMillionTransferChannel riskWatcher(BiConsumer<Integer, String> riskWatcher){
this.riskWatcher = riskWatcher;
return this;
}
@Override
public TransferResult transfer() {
Map<String, String> queryParams = buildTransferParamsWhenExceedMillion(transferOrderCode, businessId, alipayUid, alipayAccount, userName, transferAmount);
... ...