@ -6,18 +6,23 @@ import au.com.royalpay.payment.manage.mappers.system.*;
import au.com.royalpay.payment.manage.mappers.preapply.SysClientPreMapperMapper ;
import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean ;
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.tools.env.PlatformEnvironment ;
import au.com.royalpay.payment.tools.env.SysConfigManager ;
import au.com.royalpay.payment.tools.exceptions.BadRequestException ;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException ;
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.utils.PasswordUtils ;
import cn.yixblog.platform.http.HttpRequestGenerator ;
import cn.yixblog.platform.http.HttpRequestResult ;
import com.alibaba.fastjson.JSONObject ;
import com.github.qcloudsms.SmsSingleSender ;
import org.apache.commons.lang3.RandomStringUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.time.DateFormatUtils ;
@ -59,6 +64,9 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private SpringTemplateEngine thymeleaf ;
@Resource
private ClientManager clientManager ;
@Resource
private SignInAccountService signInAccountService ;
@Resource
private ClientAccountMapper clientAccountMapper ;
@ -77,10 +85,10 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
@Resource
private ClientConfigMapper clientConfigMapper ;
@Resource
private StringRedisTemplate stringRedisTemplate ;
private final SmsSingleSender smsSingleSender = new SmsSingleSender ( appId , appKey ) ;
private final SmsSingleSender ssender = new SmsSingleSender ( appId , appKey ) ;
// TODO: 2018/5/24 kira
private final int REGISTER_CLIENT_TEMPLID = 126008 ;
private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT" ;
private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS" ;
@ -88,12 +96,12 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private final List < String > tags = new ArrayList < > ( ) ;
@PostConstruct
public void init ( ) {
public void init ( ) {
tags . add ( "account" ) ;
}
@Override
public void verifyRegisterSMSCode ( String codeKey , String phoneNumber ) {
public void verifyRegisterSMSCode ( String codeKey , String phoneNumber ) {
String rediskey = getRegisterClientRedisKey ( phoneNumber ) ;
String codeValue = stringRedisTemplate . boundValueOps ( rediskey ) . get ( ) ;
if ( codeValue = = null | | ! codeValue . equals ( codeKey ) ) {
@ -119,7 +127,6 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
if ( StringUtils . isNotEmpty ( value ) ) {
throw new BadRequestException ( "SMS has been sent, Please check your messages or try again in 3 minutes." ) ;
}
JSONObject sysConfig = sysConfigManager . getSysConfig ( ) ;
ArrayList < String > param = new ArrayList < > ( ) ;
String registerClientCode = RandomStringUtils . random ( 6 , true , true ) ;
@ -127,23 +134,23 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
String expireMin = ( String ) sysConfig . getOrDefault ( "sms.verification.code.expire" , 3 ) ;
param . add ( expireMin ) ;
try {
s m sSingleS ender. sendWithParam ( nationCode , phoneNumber , REGISTER_CLIENT_TEMPLID , param , " ", "" , "" ) ;
s sender. sendWithParam ( nationCode , phoneNumber , REGISTER_CLIENT_TEMPLID , param , " RoyalPay ", "" , "" ) ; //
} catch ( Exception e ) {
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 ;
}
@Override
public void sendVerifyEmail ( String address , int client_id ) {
JSONObject client = clientManager . getClientInfo ( client_id ) ;
if ( client = = null ) {
public void sendVerifyEmail ( String address , int client_id ) {
JSONObject client = clientManager . getClientInfo ( client_id ) ;
if ( client = = null ) {
throw new BadRequestException ( "Merchant not found" ) ;
}
String key = checkOrGenerateVerifyMailKey ( address , null ) ;
String key = checkOrGenerateVerifyMailKey ( address , null ) ;
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 ) ;
SendMail sendMail = new SendMail ( ) ;
Set < String > to = new HashSet < > ( ) ;
@ -159,17 +166,17 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
@Override
public String checkOrGenerateRegisterProcessKey ( String accountName , String codeKey ) {
Assert . notNull ( accountName , "accountName can't be null" ) ;
if ( StringUtils . isNotEmpty ( codeKey ) ) {
Assert . notNull ( accountName , "accountName can't be null" ) ;
if ( StringUtils . isNotEmpty ( codeKey ) ) {
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." ) ;
} else {
} else {
return codeKey ;
}
}
String key = RandomStringUtils . random ( 10 , true , false ) ;
stringRedisTemplate . boundValueOps ( getRegisterClientProcessRedisKey ( key ) ) . set ( accountName , 1 , TimeUnit . HOURS ) ;
String key = RandomStringUtils . random ( 10 , true , false ) ;
stringRedisTemplate . boundValueOps ( getRegisterClientProcessRedisKey ( key ) ) . set ( accountName , 1 , TimeUnit . HOURS ) ;
return key ;
}
@ -179,18 +186,18 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
}
@Override
public String checkOrGenerateVerifyMailKey ( String address , String codeKey ) {
Assert . notNull ( address , "address can't be null" ) ;
if ( StringUtils . isNotEmpty ( codeKey ) ) {
public String checkOrGenerateVerifyMailKey ( String address , String codeKey ) {
Assert . notNull ( address , "address can't be null" ) ;
if ( StringUtils . isNotEmpty ( codeKey ) ) {
String redisAddress = stringRedisTemplate . boundValueOps ( getVerifyMailRedisKey ( codeKey ) ) . get ( ) ;
if ( ! address . equals ( redisAddress ) ) {
if ( ! address . equals ( redisAddress ) ) {
throw new BadRequestException ( "Mail expired" ) ;
} else {
} else {
return codeKey ;
}
}
String key = RandomStringUtils . random ( 10 , true , false ) ;
stringRedisTemplate . boundValueOps ( get RegisterClientProcess RedisKey( key ) ) . set ( address , 1 , TimeUnit . HOURS ) ;
String key = RandomStringUtils . random ( 10 , true , false ) ;
stringRedisTemplate . boundValueOps ( get VerifyMail RedisKey( key ) ) . set ( address , 1 , TimeUnit . HOURS ) ;
return key ;
}
@ -355,13 +362,29 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
}
return banInfo ;
}
@Override
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 ;
}
}