|
|
@ -3,13 +3,17 @@ package au.com.royalpay.payment.manage.application.core.impls;
|
|
|
|
import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService;
|
|
|
|
import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService;
|
|
|
|
import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean;
|
|
|
|
import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean;
|
|
|
|
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
|
|
|
|
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
|
|
|
|
import au.com.royalpay.payment.manage.system.core.MailGunService;
|
|
|
|
import au.com.royalpay.payment.manage.system.core.MailGunService;
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
import au.com.royalpay.payment.tools.env.SysConfigManager;
|
|
|
|
import au.com.royalpay.payment.tools.env.SysConfigManager;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.locale.LocaleSupport;
|
|
|
|
import au.com.royalpay.payment.tools.mail.SendMail;
|
|
|
|
import au.com.royalpay.payment.tools.mail.SendMail;
|
|
|
|
import au.com.royalpay.payment.tools.utils.sms.SmsSingleSender;
|
|
|
|
import au.com.royalpay.payment.tools.utils.sms.SmsSingleSender;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.utils.sms.SmsSingleSenderResult;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
@ -46,23 +50,26 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
|
|
|
|
private SpringTemplateEngine thymeleaf;
|
|
|
|
private SpringTemplateEngine thymeleaf;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private ClientManager clientManager;
|
|
|
|
private ClientManager clientManager;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private SignInAccountService signInAccountService;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
private final SmsSingleSender smsSingleSender = new SmsSingleSender(appId, appKey);
|
|
|
|
private final SmsSingleSender smsSingleSender = new SmsSingleSender(appId, appKey);
|
|
|
|
private final int REGISTER_CLIENT_TEMPLID = 126008;
|
|
|
|
// private final int REGISTER_CLIENT_TEMPLID = 126008;//正式
|
|
|
|
|
|
|
|
private final int REGISTER_CLIENT_TEMPLID = 110449;
|
|
|
|
private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT";
|
|
|
|
private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT";
|
|
|
|
private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS";
|
|
|
|
private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS";
|
|
|
|
private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL";
|
|
|
|
private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL";
|
|
|
|
private final List<String> tags = new ArrayList<>();
|
|
|
|
private final List<String> tags = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
@PostConstruct
|
|
|
|
public void init(){
|
|
|
|
public void init() {
|
|
|
|
tags.add("account");
|
|
|
|
tags.add("account");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void verifyRegisterSMSCode(String codeKey,String phoneNumber) {
|
|
|
|
public void verifyRegisterSMSCode(String codeKey, String phoneNumber) {
|
|
|
|
String rediskey = getRegisterClientRedisKey(phoneNumber);
|
|
|
|
String rediskey = getRegisterClientRedisKey(phoneNumber);
|
|
|
|
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
|
|
|
|
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
|
|
|
|
if (codeValue == null || !codeValue.equals(codeKey)) {
|
|
|
|
if (codeValue == null || !codeValue.equals(codeKey)) {
|
|
|
@ -96,23 +103,26 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
|
|
|
|
String expireMin = (String) sysConfig.getOrDefault("sms.verification.code.expire", 3);
|
|
|
|
String expireMin = (String) sysConfig.getOrDefault("sms.verification.code.expire", 3);
|
|
|
|
param.add(expireMin);
|
|
|
|
param.add(expireMin);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
smsSingleSender.sendWithParam(nationCode, phoneNumber, REGISTER_CLIENT_TEMPLID, param, "", "", "");
|
|
|
|
SmsSingleSenderResult result = smsSingleSender.sendWithParam(nationCode, phoneNumber, REGISTER_CLIENT_TEMPLID, param, "", "", "");
|
|
|
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
|
|
|
System.out.println(result);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ServerErrorException("System Error");
|
|
|
|
throw new ServerErrorException("System Error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stringRedisTemplate.boundValueOps(getRegisterClientRedisKey(phoneNumber)).set(registerClientCode,Long.parseLong(expireMin), TimeUnit.MINUTES);
|
|
|
|
stringRedisTemplate.boundValueOps(getRegisterClientRedisKey(phoneNumber)).set(registerClientCode, Long.parseLong(expireMin), TimeUnit.MINUTES);
|
|
|
|
return registerClientCode;
|
|
|
|
return registerClientCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void sendVerifyEmail(String address,int client_id) {
|
|
|
|
public void sendVerifyEmail(String address, int client_id) {
|
|
|
|
JSONObject client= clientManager.getClientInfo(client_id);
|
|
|
|
JSONObject client = clientManager.getClientInfo(client_id);
|
|
|
|
if(client==null){
|
|
|
|
if (client == null) {
|
|
|
|
throw new BadRequestException("Merchant not found");
|
|
|
|
throw new BadRequestException("Merchant not found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String key = checkOrGenerateVerifyMailKey(address,null);
|
|
|
|
String key = checkOrGenerateVerifyMailKey(address, null);
|
|
|
|
Context ctx = new Context();
|
|
|
|
Context ctx = new Context();
|
|
|
|
ctx.setVariable("url", PlatformEnvironment.getEnv().concatUrl("/register/account/mail/"+address+"/verify/" + key+"/jump"));
|
|
|
|
ctx.setVariable("url", PlatformEnvironment.getEnv().concatUrl("/register/account/mail/" + address + "/verify/" + key + "/jump"));
|
|
|
|
final String content = thymeleaf.process("mail/register_application", ctx);
|
|
|
|
final String content = thymeleaf.process("mail/register_application", ctx);
|
|
|
|
SendMail sendMail = new SendMail();
|
|
|
|
SendMail sendMail = new SendMail();
|
|
|
|
Set<String> to = new HashSet<>();
|
|
|
|
Set<String> to = new HashSet<>();
|
|
|
@ -128,17 +138,17 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String checkOrGenerateRegisterProcessKey(String accountName, String codeKey) {
|
|
|
|
public String checkOrGenerateRegisterProcessKey(String accountName, String codeKey) {
|
|
|
|
Assert.notNull(accountName,"accountName can't be null");
|
|
|
|
Assert.notNull(accountName, "accountName can't be null");
|
|
|
|
if(StringUtils.isNotEmpty(codeKey)){
|
|
|
|
if (StringUtils.isNotEmpty(codeKey)) {
|
|
|
|
String redisAccountName = stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(codeKey)).get();
|
|
|
|
String redisAccountName = stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(codeKey)).get();
|
|
|
|
if(!accountName.equals(redisAccountName)){
|
|
|
|
if (!accountName.equals(redisAccountName)) {
|
|
|
|
throw new BadRequestException("Data error,Please re-register for safety.");
|
|
|
|
throw new BadRequestException("Data error,Please re-register for safety.");
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
return codeKey;
|
|
|
|
return codeKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String key = RandomStringUtils.random(10, true, false);
|
|
|
|
String key = RandomStringUtils.random(10, true, false);
|
|
|
|
stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(key)).set(accountName,1,TimeUnit.HOURS);
|
|
|
|
stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(key)).set(accountName, 1, TimeUnit.HOURS);
|
|
|
|
return key;
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -148,18 +158,18 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String checkOrGenerateVerifyMailKey(String address, String codeKey){
|
|
|
|
public String checkOrGenerateVerifyMailKey(String address, String codeKey) {
|
|
|
|
Assert.notNull(address,"address can't be null");
|
|
|
|
Assert.notNull(address, "address can't be null");
|
|
|
|
if(StringUtils.isNotEmpty(codeKey)){
|
|
|
|
if (StringUtils.isNotEmpty(codeKey)) {
|
|
|
|
String redisAddress = stringRedisTemplate.boundValueOps(getVerifyMailRedisKey(codeKey)).get();
|
|
|
|
String redisAddress = stringRedisTemplate.boundValueOps(getVerifyMailRedisKey(codeKey)).get();
|
|
|
|
if(!address.equals(redisAddress)){
|
|
|
|
if (!address.equals(redisAddress)) {
|
|
|
|
throw new BadRequestException("Mail expired");
|
|
|
|
throw new BadRequestException("Mail expired");
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
return codeKey;
|
|
|
|
return codeKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String key = RandomStringUtils.random(10, true, false);
|
|
|
|
String key = RandomStringUtils.random(10, true, false);
|
|
|
|
stringRedisTemplate.boundValueOps(getVerifyMailRedisKey(key)).set(address,1,TimeUnit.HOURS);
|
|
|
|
stringRedisTemplate.boundValueOps(getVerifyMailRedisKey(key)).set(address, 1, TimeUnit.HOURS);
|
|
|
|
return key;
|
|
|
|
return key;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -169,13 +179,28 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
|
|
|
|
stringRedisTemplate.delete(getVerifyMailRedisKey(codeKey));
|
|
|
|
stringRedisTemplate.delete(getVerifyMailRedisKey(codeKey));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getRegisterClientRedisKey(String phoneNumber){
|
|
|
|
@Override
|
|
|
|
return REGISTER_CLIENT_PREFIX +phoneNumber;
|
|
|
|
public void verifyMail(String address, JSONObject loginAccount) {
|
|
|
|
|
|
|
|
LoginInfo loginInfo = new LoginInfo();
|
|
|
|
|
|
|
|
loginInfo.setLoginId(loginAccount.getString("userName"));
|
|
|
|
|
|
|
|
loginInfo.setPassword(loginAccount.getString("password"));
|
|
|
|
|
|
|
|
JSONObject account = signInAccountService.accountCheck(loginInfo);
|
|
|
|
|
|
|
|
JSONObject client = clientManager.getClientInfo(account.getIntValue("client_id"));
|
|
|
|
|
|
|
|
if (!address.equals(client.getString("contact_email"))) {
|
|
|
|
|
|
|
|
throw new BadRequestException(LocaleSupport.localeMessage("error.login.password"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getRegisterClientRedisKey(String phoneNumber) {
|
|
|
|
|
|
|
|
return REGISTER_CLIENT_PREFIX + phoneNumber;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private String getRegisterClientProcessRedisKey(String codeKey){
|
|
|
|
|
|
|
|
return REGISTER_CLIENT_PROCESS_PREFIX+codeKey;
|
|
|
|
private String getRegisterClientProcessRedisKey(String codeKey) {
|
|
|
|
|
|
|
|
return REGISTER_CLIENT_PROCESS_PREFIX + codeKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private String getVerifyMailRedisKey(String codekey){
|
|
|
|
|
|
|
|
return VERIFY_MAIL_PREFIX+codekey;
|
|
|
|
private String getVerifyMailRedisKey(String codekey) {
|
|
|
|
|
|
|
|
return VERIFY_MAIL_PREFIX + codekey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|