diff --git a/pom.xml b/pom.xml
index 4063958e7..e4b013402 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,11 +5,11 @@
au.com.royalpay.payment
payment-parent
- 2.2.28
+ 2.2.29
4.0.0
manage
- 2.3.83
+ 2.3.84-SNAPSHOT
UTF-8
2.4.0
diff --git a/src/main/java/au/com/royalpay/payment/manage/PaymentManageApplication.java b/src/main/java/au/com/royalpay/payment/manage/PaymentManageApplication.java
index aa40b3c5b..8afe9e5fb 100644
--- a/src/main/java/au/com/royalpay/payment/manage/PaymentManageApplication.java
+++ b/src/main/java/au/com/royalpay/payment/manage/PaymentManageApplication.java
@@ -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
diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/CustomersAnalysisServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/CustomersAnalysisServiceImp.java
index 15b92f3ab..4745670b5 100644
--- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/CustomersAnalysisServiceImp.java
+++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/CustomersAnalysisServiceImp.java
@@ -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 getCustomersAnalysis(JSONObject params) {
@@ -105,7 +106,7 @@ public class CustomersAnalysisServiceImp implements CustomersAnalysisService {
@Override
public JSONObject getCustomersRanking(JSONObject params, int page, int limit) {
- PageList logs = orderAnalysisMapper.listCustomersData(params, new PageBounds(page, limit, Order.formString( params.getString("orderValue") )));
+ PageList logs = orderAnalysisMapper.listCustomersData(params, new PageBounds(page, limit, Order.formString(params.getString("orderValue"))));
if (!logs.isEmpty()) {
for (JSONObject log : logs) {
generatorUserProfile(log, params);
@@ -259,7 +260,7 @@ public class CustomersAnalysisServiceImp implements CustomersAnalysisService {
node.put("name", client.getString("client_moniker"));
node.put("label", client.getString("short_name"));
node.put("value", client.getString("short_name"));
- node.put("symbolSize", clientInTotal.compareTo(new BigDecimal(10))<0?10:clientInTotal.toPlainString());
+ node.put("symbolSize", clientInTotal.compareTo(new BigDecimal(10)) < 0 ? 10 : clientInTotal.toPlainString());
if (clientInTotal.compareTo(new BigDecimal(300)) == 0) {
node.put("symbolSize", 100);
}
@@ -267,21 +268,21 @@ public class CustomersAnalysisServiceImp implements CustomersAnalysisService {
node.put("flag", true);
node.put("draggable", true);
nodes.add(node);
- JSONObject totalAmountInfo = getClientAmountInfo(id,"x0", "交易金额", client);
+ JSONObject totalAmountInfo = getClientAmountInfo(id, "x0", "交易金额", client);
totalAmountInfo.put("label", client.getString("total_amount"));
- totalAmountInfo.put("value", client.getBigDecimal("total_amount").setScale(2,RoundingMode.HALF_UP));
- totalAmountInfo.put("symbolSize",amountInTotal.compareTo(new BigDecimal(10))<0?10:amountInTotal.toPlainString());
+ totalAmountInfo.put("value", client.getBigDecimal("total_amount").setScale(2, RoundingMode.HALF_UP));
+ totalAmountInfo.put("symbolSize", amountInTotal.compareTo(new BigDecimal(10)) < 0 ? 10 : amountInTotal.toPlainString());
nodes.add(totalAmountInfo);
- JSONObject OrdersInfo = getClientAmountInfo(id,"x1", "订单数", client);
+ JSONObject OrdersInfo = getClientAmountInfo(id, "x1", "订单数", client);
OrdersInfo.put("label", client.getString("orders"));
OrdersInfo.put("value", client.getString("orders"));
- OrdersInfo.put("symbolSize", orderInTotal.compareTo(new BigDecimal(10))<0?10:orderInTotal.toPlainString());
+ OrdersInfo.put("symbolSize", orderInTotal.compareTo(new BigDecimal(10)) < 0 ? 10 : orderInTotal.toPlainString());
nodes.add(OrdersInfo);
- JSONObject priceInfo = getClientAmountInfo(id,"x2", "客单价", client);
+ JSONObject priceInfo = getClientAmountInfo(id, "x2", "客单价", client);
BigDecimal price = client.getBigDecimal("total_amount").divide(client.getBigDecimal("orders"), 2, RoundingMode.HALF_UP);
priceInfo.put("label", price.toPlainString());
priceInfo.put("value", price.toPlainString());
- priceInfo.put("symbolSize", price.divide(new BigDecimal(50), 0, RoundingMode.DOWN).compareTo(new BigDecimal(10))<0?5:price.divide(new BigDecimal(50), 0, RoundingMode.DOWN).toPlainString());
+ priceInfo.put("symbolSize", price.divide(new BigDecimal(50), 0, RoundingMode.DOWN).compareTo(new BigDecimal(10)) < 0 ? 5 : price.divide(new BigDecimal(50), 0, RoundingMode.DOWN).toPlainString());
nodes.add(priceInfo);
id++;
}
@@ -289,7 +290,7 @@ public class CustomersAnalysisServiceImp implements CustomersAnalysisService {
JSONObject link = new JSONObject();
String linkId = node.getString("id");
link.put("source", linkId);
- link.put("target", linkId.indexOf("x")>0?linkId.substring(0,linkId.indexOf("x")):0);
+ link.put("target", linkId.indexOf("x") > 0 ? linkId.substring(0, linkId.indexOf("x")) : 0);
links.add(link);
}
graph.put("nodes", nodes);
@@ -384,8 +385,8 @@ public class CustomersAnalysisServiceImp implements CustomersAnalysisService {
List mostUseIndustryByCustomer = orderAnalysisMapper.mostUseIndustryByCustomer(params);
List 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);
}
}
@@ -394,7 +395,7 @@ public class CustomersAnalysisServiceImp implements CustomersAnalysisService {
int amount = mostUseAmountByCustomer.getIntValue("amount_int");
if (amount == 0) {
topAmountRange = "0~100";
- }else {
+ } else {
topAmountRange = String.valueOf(amount * 100) + "~" + String.valueOf((amount + 1) * 100);
}
}
diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionServiceImpl.java
index 1f11568d1..b871acef7 100644
--- a/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionServiceImpl.java
+++ b/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionServiceImpl.java
@@ -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);
}
@@ -179,7 +180,7 @@ public class CustomerImpressionServiceImpl implements CustomerImpressionService
clientCustomersMapper.updateAfterPaymentFinish(clientCustomerInfo);
}
} finally {
- locker.unlock(CUSTOMER_IMPRESSION_PREFIX+customer_id);
+ locker.unlock(CUSTOMER_IMPRESSION_PREFIX + customer_id);
}
} catch (Exception e) {
logger.debug("Reduce Customer Impression Error Redis Value =" + redisValue, e);
diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/web/IPController.java b/src/main/java/au/com/royalpay/payment/manage/dev/web/IPController.java
index 7310f1fae..b05dd117a 100644
--- a/src/main/java/au/com/royalpay/payment/manage/dev/web/IPController.java
+++ b/src/main/java/au/com/royalpay/payment/manage/dev/web/IPController.java
@@ -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;
}
}
diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java
index 27f800cdd..3b86340f9 100644
--- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java
+++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java
@@ -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)) {
- client.put("enable_alipayplus", true);
- }
+ 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 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);
@@ -5729,7 +5728,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
params.put("client_id", client.getString("client_id"));
params.put("create_time", new Date());
params.put("operator", manager.getString("display_name"));
- params.put("is_valid","1");
+ params.put("is_valid", "1");
SubMerchantInfoInheritance subMerchantInfo = JSON.toJavaObject(params, SubMerchantInfoInheritance.class);
MerchantApplicationResult res = Optional.ofNullable(merchantChannelApplicationManager.getRegister(WxPayMerchantRegister.class))
.map(channel -> channel.apply(client, subMerchantInfo, manager))
@@ -5841,8 +5840,8 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
String rejectReason = responseElement.elementText("reject_reason");
return "查询成功:" + responseElement.elementText("secondary_merchant_id") +
"报备状态:" + responseElement.elementText("status") + StringUtils.defaultString(rejectReason, "");
- }catch (BadRequestException e){
- logger.error(e.getMessage(),e);
+ } catch (BadRequestException e) {
+ logger.error(e.getMessage(), e);
return e.getMessage();
}
}
diff --git a/src/main/resources/data/geo/GeoLite2-City.mmdb b/src/main/resources/data/geo/GeoLite2-City.mmdb
new file mode 100644
index 000000000..3ce37cb25
Binary files /dev/null and b/src/main/resources/data/geo/GeoLite2-City.mmdb differ
diff --git a/src/main/resources/data/geo/GeoLiteCity.dat b/src/main/resources/data/geo/GeoLiteCity.dat
deleted file mode 100644
index 8106a53c5..000000000
Binary files a/src/main/resources/data/geo/GeoLiteCity.dat and /dev/null differ
diff --git a/src/test/java/au/com/royalpay/payment/manage/process/aes/AESTest.java b/src/test/java/au/com/royalpay/payment/manage/process/aes/AESTest.java
index 847c57666..c0e8f61a5 100644
--- a/src/test/java/au/com/royalpay/payment/manage/process/aes/AESTest.java
+++ b/src/test/java/au/com/royalpay/payment/manage/process/aes/AESTest.java
@@ -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));
diff --git a/src/test/java/au/com/royalpay/payment/manage/valid/IPTest.java b/src/test/java/au/com/royalpay/payment/manage/valid/IPTest.java
new file mode 100644
index 000000000..3a9570f24
--- /dev/null
+++ b/src/test/java/au/com/royalpay/payment/manage/valid/IPTest.java
@@ -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);
+ }
+}