sms服务替换

master
yixian 4 years ago
parent 8214e507e6
commit f799b86c4d

@ -21,7 +21,8 @@ import au.com.royalpay.payment.manage.product.beans.ProductBean;
import au.com.royalpay.payment.manage.product.core.ClientProduct;
import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.manage.support.sms.SmsSenderQcloudImpl;
import au.com.royalpay.payment.manage.support.sms.SmsSender;
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
import au.com.royalpay.payment.tools.device.ManageDeviceSupport;
import au.com.royalpay.payment.tools.device.support.DeviceRegister;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
@ -44,6 +45,7 @@ import org.thymeleaf.spring5.SpringTemplateEngine;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@ -87,10 +89,9 @@ public class ManageAppServiceImp implements ManageAppService {
@Resource
private SpringTemplateEngine thymeleaf;
@Resource
private SmsSenderQcloudImpl smsSender;
private SmsSender smsSender;
private final String BIND_MANAGE_EMAIL_PREFIX = "BIND_MANAGE_EMAIL";
private final String BIND_MANAGE_PHONE_PREFIX = "BIND_MANAGE_PHONE";
private final int BIND_PHONE_TEMPLID = 126978;
@Override
@ -121,7 +122,7 @@ public class ManageAppServiceImp implements ManageAppService {
public List<JSONObject> getReferrerList(JSONObject device) {
String clientType = device.getString("client_type");
manageDeviceSupport.findRegister(clientType);
return orgMapper.listOrgs(1,new PageBounds());
return orgMapper.listOrgs(1, new PageBounds());
}
@Override
@ -137,7 +138,7 @@ public class ManageAppServiceImp implements ManageAppService {
String clientType = device.getString("client_type");
manageDeviceSupport.findRegister(clientType);
JSONObject manager = managerMapper.findById(device.getString("manager_id"));
if (StringUtils.isNotBlank(info.getClient_pay_type())&& StringUtils.isNotBlank(info.getClient_pay_desc())) {
if (StringUtils.isNotBlank(info.getClient_pay_type()) && StringUtils.isNotBlank(info.getClient_pay_desc())) {
info.setClient_pay_type("");
info.setClient_pay_desc("");
}
@ -149,7 +150,7 @@ public class ManageAppServiceImp implements ManageAppService {
String clientType = device.getString("client_type");
manageDeviceSupport.findRegister(clientType);
JSONObject manager = managerMapper.findById(device.getString("manager_id"));
clientManager.disableClient(clientMoniker,manager);
clientManager.disableClient(clientMoniker, manager);
}
@Override
@ -215,7 +216,7 @@ public class ManageAppServiceImp implements ManageAppService {
String clientType = device.getString("client_type");
manageDeviceSupport.findRegister(clientType);
List<JSONObject> rates = clientManager.clientRates(clientMoniker, true);
return rates.stream().collect(Collectors.groupingBy(e -> e.getString("rate_name"),HashMap::new,Collectors.toList()));
return rates.stream().collect(Collectors.groupingBy(e -> e.getString("rate_name"), HashMap::new, Collectors.toList()));
}
@Override
@ -270,7 +271,7 @@ public class ManageAppServiceImp implements ManageAppService {
String clientType = device.getString("client_type");
manageDeviceSupport.findRegister(clientType);
JSONObject manager = managerMapper.findById(device.getString("manager_id"));
clientManager.uploadAuthFiles(manager, clientMoniker,filesInfo);
clientManager.uploadAuthFiles(manager, clientMoniker, filesInfo);
}
@Override
@ -373,7 +374,7 @@ public class ManageAppServiceImp implements ManageAppService {
Calendar monthCal = Calendar.getInstance();
monthCal.setTime(new Date());
monthCal.set(Calendar.MONTH, (monthCal.get(Calendar.MONTH) - 1));
JSONObject total = financialPartnerCommissionMapper.findTotalByOrg(monthCal.get(Calendar.YEAR), monthCal.get(Calendar.MONTH)+1, manager.getString("org_id"));
JSONObject total = financialPartnerCommissionMapper.findTotalByOrg(monthCal.get(Calendar.YEAR), monthCal.get(Calendar.MONTH) + 1, manager.getString("org_id"));
if (total == null) {
total = new JSONObject();
total.put("total_amount", BigDecimal.ZERO);
@ -404,7 +405,7 @@ public class ManageAppServiceImp implements ManageAppService {
}
@Override
public List<JSONObject> getBdPrizeList(JSONObject device) {
public List<JSONObject> getBdPrizeList(JSONObject device) {
String clientType = device.getString("client_type");
manageDeviceSupport.findRegister(clientType);
JSONObject manager = managerMapper.findById(device.getString("manager_id"));
@ -465,15 +466,15 @@ public class ManageAppServiceImp implements ManageAppService {
public void bindAccountEmail(JSONObject device, JSONObject email) {
String codeKey = device.getString("manager_id");
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateManageEmailKey(codeKey)).get();
if(StringUtils.isNotEmpty(codeKeyValueRedis)){
if (StringUtils.isNotEmpty(codeKeyValueRedis)) {
throw new BadRequestException("Captcha has been sent.Please check your email or try again in 5 minutes.");
}
String codeKeyValue = RandomStringUtils.random(6, false, true);
logger.debug("send sms code : {} ", codeKeyValue);
Context ctx = new Context();
JSONObject manager = managerMapper.findById(device.getString("manager_id"));
ctx.setVariable("account",manager);
ctx.setVariable("captcha",codeKeyValue);
ctx.setVariable("account", manager);
ctx.setVariable("captcha", codeKeyValue);
final String content = thymeleaf.process("mail/account_bind_email.html", ctx);
royalThreadPoolExecutor.execute(() -> {
try {
@ -483,23 +484,23 @@ public class ManageAppServiceImp implements ManageAppService {
throw new EmailException("Email Sending Failed", e);
}
});
stringRedisTemplate.boundValueOps(getUpdateManageEmailKey(codeKey)).set(codeKeyValue+"&"+email.getString("contact_email"), 5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(getUpdateManageEmailKey(codeKey)).set(codeKeyValue + "&" + email.getString("contact_email"), 5, TimeUnit.MINUTES);
}
@Override
public void updateAccountEmail(JSONObject device, JSONObject params) {
String key = stringRedisTemplate.boundValueOps(getUpdateManageEmailKey(device.getString("manager_id"))).get();
if(key == null){
if (key == null) {
throw new BadRequestException("Captcha has expired");
}
String captcha = key.split("&")[0];
String email = key.split("&")[1];
if(!StringUtils.equals(captcha,params.getString("captcha"))){
if (!StringUtils.equals(captcha, params.getString("captcha"))) {
throw new BadRequestException("Verification code is wrong");
}
JSONObject account = new JSONObject();
account.put("manager_id",device.getString("manager_id"));
account.put("email",email);
JSONObject account = new JSONObject();
account.put("manager_id", device.getString("manager_id"));
account.put("email", email);
managerMapper.update(account);
deleteManageEmailKey(device.getString("manager_id"));
}
@ -508,60 +509,55 @@ public class ManageAppServiceImp implements ManageAppService {
public void bindAccountPhone(JSONObject device, JSONObject phone) {
String codeKey = device.getString("manager_id");
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateManagePhoneKey(codeKey)).get();
if(StringUtils.isNotEmpty(codeKeyValueRedis)){
if (StringUtils.isNotEmpty(codeKeyValueRedis)) {
throw new BadRequestException("Captcha has been sent.Please check your phone or try again in 5 minutes.");
}
String codeKeyValue = RandomStringUtils.random(6, false, true);
logger.debug("send sms code : {} ", codeKeyValue);
String nationCode = phone.getString("nation_code");
String phoneNumber = phone.getString("contact_phone");
ArrayList<String> param = new ArrayList<>();
param.add("绑定手机号");
param.add(codeKeyValue);
String expireMin = "5";
param.add(expireMin);
try {
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, BIND_PHONE_TEMPLID, param, "RoyalPay", "", "");
smsSender.sendAuthCodeMessage(nationCode.trim(), phoneNumber, Locale.ENGLISH, new AuthCodeMessage("绑定手机号", codeKeyValue, 5));
} catch (Exception e) {
e.printStackTrace();
throw new ServerErrorException("Phone number is wrong.Please try again.");
}
stringRedisTemplate.boundValueOps(getUpdateManagePhoneKey(codeKey)).set(codeKeyValue+"&"+nationCode+"&"+phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(getUpdateManagePhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Duration.ofMinutes(5));
}
@Override
public void updateAccountPhone(JSONObject device, JSONObject params) {
String key = stringRedisTemplate.boundValueOps(getUpdateManagePhoneKey(device.getString("manager_id"))).get();
if(key == null){
if (key == null) {
throw new BadRequestException("Captcha has expired");
}
String captcha = key.split("&")[0];
String nation_code = key.split("&")[1];
String contact_phone = key.split("&")[2];
if(!StringUtils.equals(captcha,params.getString("captcha"))){
if (!StringUtils.equals(captcha, params.getString("captcha"))) {
throw new BadRequestException("Verification code is wrong");
}
JSONObject account = new JSONObject();
account.put("manager_id",device.getString("manager_id"));
account.put("contact_phone",contact_phone);
account.put("nation_code","+" + nation_code);
JSONObject account = new JSONObject();
account.put("manager_id", device.getString("manager_id"));
account.put("contact_phone", contact_phone);
account.put("nation_code", "+" + nation_code);
managerMapper.update(account);
deleteManagePhoneKey(device.getString("manager_id"));
}
private void deleteManageEmailKey(String codeKey){
private void deleteManageEmailKey(String codeKey) {
stringRedisTemplate.delete(getUpdateManageEmailKey(codeKey));
}
private void deleteManagePhoneKey(String codeKey){
private void deleteManagePhoneKey(String codeKey) {
stringRedisTemplate.delete(getUpdateManagePhoneKey(codeKey));
}
private String getUpdateManageEmailKey(String codeKey){
return BIND_MANAGE_EMAIL_PREFIX+codeKey;
private String getUpdateManageEmailKey(String codeKey) {
return BIND_MANAGE_EMAIL_PREFIX + codeKey;
}
private String getUpdateManagePhoneKey(String codeKey){
return BIND_MANAGE_PHONE_PREFIX+codeKey;
private String getUpdateManagePhoneKey(String codeKey) {
return BIND_MANAGE_PHONE_PREFIX + codeKey;
}
}

@ -46,7 +46,8 @@ import au.com.royalpay.payment.manage.riskbusiness.enums.RiskResultTypeEnum;
import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.manage.signin.core.impls.SignInAccountServiceImpl;
import au.com.royalpay.payment.manage.support.sms.SmsSenderQcloudImpl;
import au.com.royalpay.payment.manage.support.sms.SmsSender;
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery;
import au.com.royalpay.payment.manage.tradelog.core.TradeLogService;
import au.com.royalpay.payment.manage.tradelog.refund.RefundService;
@ -106,6 +107,7 @@ import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@ -234,11 +236,10 @@ public class RetailAppServiceImp implements RetailAppService {
private final String IMG_AGGREGATE_FILE = "https://file.royalpay.com.au/open/2020/04/08/1586313342533_41vI3w9R8OHrhAVYWvdv7S2IyQra4z.pdf";
@Resource
private SmsSenderQcloudImpl smsSender;
private SmsSender smsSender;
private final String BIND_ACCOUNT_EMAIL_PREFIX = "BIND_ACCOUNT_EMAIL";
private final String BIND_ACCOUNT_PHONE_PREFIX = "BIND_ACCOUNT_PHONE";
private final String UNBIND_ACCOUNT_PHONE_PREFIX = "UHBIND_ACCOUNT_PHONE";
private final int BIND_PHONE_TEMPLID = 126978;
private Map<String, AppMsgSender> senderMap = new HashMap<>();
private final String fileName[] = {"client_bank_file", "client_id_file", "client_company_file"};
@ -2234,18 +2235,13 @@ public class RetailAppServiceImp implements RetailAppService {
logger.debug("send sms code : {} ", codeKeyValue);
String nationCode = phone.getString("nation_code").contains("+") ? phone.getString("nation_code").substring(1) : phone.getString("nation_code");
String phoneNumber = phone.getString("contact_phone");
ArrayList<String> param = new ArrayList<>();
param.add("绑定手机号");
param.add(codeKeyValue);
String expireMin = "1";
param.add(expireMin);
try {
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, BIND_PHONE_TEMPLID, param, "RoyalPay", "", "");
smsSender.sendAuthCodeMessage(nationCode.trim(), phoneNumber, Locale.ENGLISH, new AuthCodeMessage("绑定手机号", codeKeyValue, 1));
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new BadRequestException("Phone number is wrong.Please try again.");
}
stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Duration.ofMinutes(1));
}
@Override
@ -2259,18 +2255,13 @@ public class RetailAppServiceImp implements RetailAppService {
String codeKeyValue = RandomStringUtils.random(6, false, true);
String nationCode = client.getString("nation_code").contains("+") ? client.getString("nation_code").substring(1) : client.getString("nation_code");
String phoneNumber = client.getString("contact_phone");
ArrayList<String> param = new ArrayList<>();
param.add("解綁绑定手机号");
param.add(codeKeyValue);
String expireMin = "1";
param.add(expireMin);
try {
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, BIND_PHONE_TEMPLID, param, "RoyalPay", "", "");
smsSender.sendAuthCodeMessage(nationCode.trim(), phoneNumber, Locale.ENGLISH, new AuthCodeMessage("解綁绑定手机号", codeKeyValue, 1));
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new BadRequestException("Phone number is wrong.Please try again.");
}
stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Duration.ofMinutes(1));
}
@Override

@ -23,7 +23,6 @@ public class SmsSenderQcloudImpl implements SmsSender {
private static final int REGISTER_CLIENT_TEMPLID_ZH = 126978;
private static final int REGISTER_CLIENT_TEMPLID_EN = 346078;
private static final int REFUSE_CLIENT_TEMPLID = 166108;
private static final int RESET_PASSWORD_TEMPLID = 126978;
private final SmsSingleSender sender;
private final String sign;

Loading…
Cancel
Save