GeoIP处理;newOrderEnabled参数

master
yixian 3 years ago
parent 5c8d50fd3a
commit a24024ff9b

@ -5,11 +5,11 @@
<parent>
<groupId>au.com.royalpay.payment</groupId>
<artifactId>payment-parent</artifactId>
<version>2.2.28</version>
<version>2.2.29</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>manage</artifactId>
<version>2.3.83</version>
<version>2.3.84-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jib-maven-plugin.version>2.4.0</jib-maven-plugin.version>

@ -1,10 +1,11 @@
package au.com.royalpay.payment.manage;
import au.com.royalpay.payment.tools.geo.GeoIPSupport;
import au.com.royalpay.payment.tools.geo.MaxmindGeoIPLite2Support;
import com.alibaba.fastjson.parser.ParserConfig;
import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import com.maxmind.geoip.LookupService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
@ -44,15 +45,15 @@ public class PaymentManageApplication {
}
@Bean
public LookupService lookupService(@Value("${app.geo.dat-file:''}") String datFile, @Value("classpath:data/geo/GeoLiteCity.dat") Resource geoCityFile) throws IOException {
public GeoIPSupport geoIPSupport(@Value("${app.geo.mmdb-file:''}") String datFile, @Value("classpath:data/geo/GeoLite2-City.mmdb") Resource mmdbFile) throws IOException {
try {
if (StringUtils.isNotEmpty(datFile) && new File(datFile).exists()) {
return new LookupService(datFile);
return new MaxmindGeoIPLite2Support(datFile);
}
} catch (IOException e) {
e.printStackTrace();
}
return new LookupService(geoCityFile.getFile());
return new MaxmindGeoIPLite2Support(mmdbFile);
}
@Bean

@ -15,13 +15,14 @@ import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi;
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider;
import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.geo.GeoIPSupport;
import au.com.royalpay.payment.tools.geo.entity.GeoLocation;
import au.com.royalpay.payment.tools.utils.PageListUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.maxmind.geoip.LookupService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
@ -72,7 +73,7 @@ public class CustomersAnalysisServiceImp implements CustomersAnalysisService {
@Resource
private RetailAppService retailAppService;
@Resource
private LookupService lookupService;
private GeoIPSupport geoIPSupport;
@Override
public List<JSONObject> getCustomersAnalysis(JSONObject params) {
@ -384,8 +385,8 @@ public class CustomersAnalysisServiceImp implements CustomersAnalysisService {
List<JSONObject> mostUseIndustryByCustomer = orderAnalysisMapper.mostUseIndustryByCustomer(params);
List<JSONObject> mostUseAddressByCustomer = orderAnalysisMapper.mostUseAddressByCustomer(params);
for (JSONObject address : mostUseAddressByCustomer) {
String city = lookupService.getLocation(address.getString("customer_ip")).city;
if (topAddress.size() < 3 && !topAddress.contains(city) && StringUtils.isNotBlank(city) && city != null) {
String city = geoIPSupport.getLocation(address.getString("customer_ip")).map(GeoLocation::getCity).orElse(null);
if (topAddress.size() < 3 && !topAddress.contains(city) && StringUtils.isNotBlank(city)) {
topAddress.add(city);
}
}

@ -8,6 +8,8 @@ import au.com.royalpay.payment.manage.mappers.system.CustomerMapper;
import au.com.royalpay.payment.manage.mappers.system.ManagerCustomerRelationAlipayMapper;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
import au.com.royalpay.payment.tools.geo.GeoIPSupport;
import au.com.royalpay.payment.tools.geo.entity.GeoLocation;
import au.com.royalpay.payment.tools.lock.Locker;
import au.com.royalpay.payment.tools.utils.PageListUtils;
import com.alibaba.fastjson.JSON;
@ -15,7 +17,6 @@ import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.maxmind.geoip.LookupService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.joda.time.DateTime;
@ -42,7 +43,7 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
@Resource
private OrderMapper orderMapper;
@Resource
private LookupService lookupService;
private GeoIPSupport geoIPSupport;
@Resource
private ManagerCustomerRelationAlipayMapper managerCustomerRelationAlipayMapper;
@Resource
@ -77,7 +78,7 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
JSONObject order = ordersLast.get(0);
JSONObject paymentInfo = new JSONObject();
paymentInfo.put("pay_time", DateFormatUtils.format(order.getDate("create_time"), "yyyy-MM-dd HH:mm:ss"));
String city = lookupService.getLocation(order.getString("customer_ip")).city;
String city = geoIPSupport.getLocation(order.getString("customer_ip")).map(GeoLocation::getCity).orElse(null);
if (!StringUtils.isEmpty(city)) {
paymentInfo.put("pay_location", city);
}
@ -89,7 +90,7 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
JSONObject order = ordersFirst.get(0);
JSONObject paymentInfo = new JSONObject();
paymentInfo.put("pay_time", DateFormatUtils.format(order.getDate("create_time"), "yyyy-MM-dd HH:mm:ss"));
String city = lookupService.getLocation(order.getString("customer_ip")).city;
String city = geoIPSupport.getLocation(order.getString("customer_ip")).map(GeoLocation::getCity).orElse(null);
if (!StringUtils.isEmpty(city)) {
paymentInfo.put("pay_location", city);
}

@ -1,8 +1,12 @@
package au.com.royalpay.payment.manage.dev.web;
import au.com.royalpay.payment.tools.geo.GeoIPSupport;
import au.com.royalpay.payment.tools.geo.entity.GeoLocation;
import com.alibaba.fastjson.JSONObject;
import com.maxmind.geoip.LookupService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@ -11,12 +15,12 @@ import javax.annotation.Resource;
public class IPController {
@Resource
private LookupService lookupService;
private GeoIPSupport geoIPSupport;
@GetMapping("/{ipAddr}")
public JSONObject getIpInfo(@PathVariable String ipAddr) {
JSONObject result = new JSONObject();
result.put("city", lookupService.getLocation(ipAddr).city);
result.put("city", geoIPSupport.getLocation(ipAddr).map(GeoLocation::getCity).orElse("Unknown"));
return result;
}
}

@ -12,7 +12,6 @@ import au.com.royalpay.payment.channels.rpaypaymentsvc.runtime.RPayPaymentCardSv
import au.com.royalpay.payment.channels.rpaypaymentsvc.runtime.request.entities.RPayMerchantEntity;
import au.com.royalpay.payment.channels.wechat.config.WeChatPayConfig;
import au.com.royalpay.payment.channels.wechat.config.WechatPayEnvironment;
import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi;
import au.com.royalpay.payment.channels.wechat.runtime.beans.SubMerchantInfo;
import au.com.royalpay.payment.channels.wechat.runtime.beans.SubMerchantInfoInheritance;
import au.com.royalpay.payment.channels.wechat.runtime.beans.WechatMerchantInfo;
@ -20,10 +19,12 @@ import au.com.royalpay.payment.channels.wechat.runtime.impls.WxPayMerchantRegist
import au.com.royalpay.payment.channels.wechat.runtime.impls.WxPayMerchantRegisterLegacy;
import au.com.royalpay.payment.channels.wechat.runtime.mappers.PaymentChannelMccGoodMapper;
import au.com.royalpay.payment.channels.wechat.runtime.mappers.WxMerchantApplyMapper;
import au.com.royalpay.payment.core.ChannelContractSource;
import au.com.royalpay.payment.core.PaymentApi;
import au.com.royalpay.payment.core.PaymentChannelApi;
import au.com.royalpay.payment.core.beans.ChannelMerchantInfo;
import au.com.royalpay.payment.core.beans.EmptyMerchantApplication;
import au.com.royalpay.payment.core.beans.MchChannelContract;
import au.com.royalpay.payment.core.beans.MerchantApplicationResult;
import au.com.royalpay.payment.core.exceptions.EmailException;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
@ -551,11 +552,11 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
}
client.put("enable_alipayplus", false);
MerchantChannelPermissionResolver resolver = this.paymentApi.channelApi(PayChannel.ALIPAY_PLUS.getChannelCode()).getChannelPermissionResolver();
if (!Objects.isNull(resolver)) {
if (resolver.newOrderEnabled(client)) {
if (!Objects.isNull(resolver) &&
resolver.newOrderEnabled(client, null, PlatformEnvironment.getEnv().getForeignCurrency())) {
client.put("enable_alipayplus", true);
}
}
return client;
}
@ -1078,31 +1079,29 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
throw new InvalidShortIdException();
}
checkOrgPermission(manager, client);
JSONObject update = new JSONObject();
int clientId = client.getIntValue("client_id");
String originSubMerchantId = client.getString("sub_merchant_id");
update.put("client_id", clientId);
String subMerchantId = subMerchantInfo.getString("sub_merchant_id");
MpPaymentApi wxApi = (MpPaymentApi) paymentApi.channelApi(PayChannel.WECHAT.getChannelCode());
WeChatPayConfig.Merchant availableMerchant = wxApi.determineMerchant(subMerchantId);
update.put("merchant_id", availableMerchant == null ? null : availableMerchant.getMerchantId());
update.put("sub_merchant_id", subMerchantId);
ChannelContractSource wxContractSource = paymentApi.channelApi(PayChannel.WECHAT.getChannelCode()).initContractSource();
MchChannelContract contract = new MchChannelContract().setClientId(clientId).setMid(subMerchantId);
wxContractSource.saveContract(contract);
try {
recordSubMerchantLog(client, subMerchantInfo, manager);
} catch (Exception e) {
logger.error("记录log_client_sub_merchant_id失败", e);
}
clientMapper.update(update);
List<JSONObject> children = clientMapper.listChildClients(clientId);
for (JSONObject child : children) {
if (Objects.equals(child.getString("sub_merchant_id"), originSubMerchantId)) {
update.put("client_id", child.getIntValue("client_id"));
MchChannelContract childContract = new MchChannelContract()
.setClientId(child.getIntValue("client_id"))
.setMid(subMerchantId);
try {
recordSubMerchantLog(child, subMerchantInfo, manager);
} catch (Exception e) {
logger.error("记录log_client_sub_merchant_id失败", e);
}
clientMapper.update(update);
wxContractSource.saveContract(childContract);
}
}
clientInfoCacheSupport.clearClientCache(clientId);

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 MiB

@ -18,8 +18,8 @@ public class AESTest {
@Test
public void testEncrypt() {
String keyStr = "Aa+MtthC4Ztq4Kfa9aL+UA==";
String source = "2020@Zxcvb1026";
String keyStr = "EPrfsM2JE69ZPR7BhXn34g==";
String source = "Rpay2021";
Key key = AESCrypt.fromKeyString(Base64.decodeBase64(keyStr));
byte[] encrypted = AESCrypt.encrypt(source.getBytes(StandardCharsets.UTF_8), key);
System.out.println("encrypted: " + Base64.encodeBase64String(encrypted));

@ -0,0 +1,19 @@
package au.com.royalpay.payment.manage.valid;
import au.com.royalpay.payment.tools.geo.MaxmindGeoIPLite2Support;
import au.com.royalpay.payment.tools.geo.entity.GeoLocation;
import org.junit.Test;
import java.io.IOException;
import java.net.URL;
public class IPTest {
@Test
public void testIP() throws IOException {
String ip = "193.82.236.78";
URL datFile = getClass().getClassLoader().getResource("data/geo/GeoLite2-City.mmdb");
GeoLocation location = new MaxmindGeoIPLite2Support(datFile.getFile())
.getLocation(ip).orElse(null);
System.out.println(location);
}
}
Loading…
Cancel
Save