wangning 7 years ago
parent 48cc6509c0
commit 543964051b

@ -4,7 +4,7 @@ import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean;
import com.alibaba.fastjson.JSONObject;
public interface SimpleClientApplyService {
String getSMSVerifyCode(String codeKey);
void verifyRegisterSMSCode(String codeKey, String accountName);
JSONObject newAccount(NewAccountBean accountBean);
@ -12,5 +12,9 @@ public interface SimpleClientApplyService {
String partnerSignIn(JSONObject account);
String getSmsCodeAndSend();
String getSmsCodeAndSend(String phoneNumber,String nationCode,String accountName);
void sendVerifyEmail(String address,JSONObject client);
String generateRegisterProcessKey(String accountName);
}

@ -1,21 +1,28 @@
package au.com.royalpay.payment.manage.application.core.impls;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring4.SpringTemplateEngine;
import com.alibaba.fastjson.JSONObject;
import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService;
import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean;
import au.com.royalpay.payment.manage.system.core.MailGunService;
import au.com.royalpay.payment.tools.env.SysConfigManager;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import au.com.royalpay.payment.tools.mail.SendMail;
import au.com.royalpay.payment.tools.utils.sms.SmsSingleSender;
public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
@ -26,16 +33,27 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private String appKey;
@Resource
private SysConfigManager sysConfigManager;
@Resource
private MailGunService mailGunService;
@Resource
private SpringTemplateEngine thymeleaf;
@Resource
private StringRedisTemplate stringRedisTemplate;
private final SmsSingleSender smsSingleSender = new SmsSingleSender(appId,appKey);
// TODO: 2018/5/23 kira 模板申请通过后修改
private final int REGISTER_CLIENT_TEMPLID = 123;
private final SmsSingleSender smsSingleSender = new SmsSingleSender(appId, appKey);
private final int REGISTER_CLIENT_TEMPLID = 126008;
private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT";
private final String REGISTER_CLIENT_PHONE_EXPIRE_PREFIX = "REGISTER_CLIENT_PHONE_EXPIRE";
@Override
public String getSMSVerifyCode(String codeKey){
return null;
public void verifyRegisterSMSCode(String codeKey,String accountName) {
String rediskey = getRegisterClientRedisKey(accountName);
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
if (codeValue == null || !codeValue.equals(codeKey)) {
throw new BadRequestException("Verification code has expired or is not correct");
}
stringRedisTemplate.delete(rediskey);
// stringRedisTemplate.delete(getRegisterClientPhoneExpireRedisKey(phoneNumber));
}
@Override
@ -54,17 +72,59 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
}
@Override
public String getSmsCodeAndSend(String phoneNumber,String nationCode) {
public String getSmsCodeAndSend(String phoneNumber, String nationCode,String accountName) {
String reidsCheckCodeKey = getRegisterClientPhoneExpireRedisKey(phoneNumber);
String value = stringRedisTemplate.boundValueOps(reidsCheckCodeKey).get();
if (StringUtils.isNotEmpty(value)) {
throw new BadRequestException("SMS has been sentPlease check your messages or try again in 3 minutes.");
}
JSONObject sysConfig = sysConfigManager.getSysConfig();
List<String> param = new ArrayList<>();
String register_client_key = REGISTER_CLIENT_PREFIX+RandomStringUtils.random(6, true, true);
param.add(register_client_key);
String expireMin = (String) sysConfig.getOrDefault("sms.verification.code.expire",3);
ArrayList<String> param = new ArrayList<>();
String registerClientKey = getRegisterClientRedisKey(accountName);
String registerClientCode = RandomStringUtils.random(6, true, true);
param.add(registerClientCode);
String expireMin = (String) sysConfig.getOrDefault("sms.verification.code.expire", 3);
param.add(expireMin);
stringRedisTemplate.boundValueOps(register_client_key).set(register_client_key, Long.parseLong(expireMin), TimeUnit.MINUTES);
try {
smsSingleSender.sendWithParam(nationCode, phoneNumber, REGISTER_CLIENT_TEMPLID, param, "", "", "");
} catch (Exception e) {
throw new ServerErrorException("System Error");
}
stringRedisTemplate.boundValueOps(registerClientKey).set(registerClientCode, Long.parseLong(expireMin), TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(reidsCheckCodeKey).set(reidsCheckCodeKey, Long.parseLong(expireMin), TimeUnit.MINUTES);
return registerClientCode;
}
@Override
public void sendVerifyEmail(String address,JSONObject client) {
Context ctx = new Context();
ctx.setVariable("url", url);
final String content = thymeleaf.process("mail/register_application", ctx);
param.add(DateFormatUtils.format(coupon.getDate("expiry"), "yyyy-MM-dd"));
smsSingleSender.sendWithParam(nationCode,phoneNumber,REGISTER_CLIENT_TEMPLID,,"","","");
return register_client_key;
SendMail sendMail = new SendMail();
Set<String> to = new HashSet<>();
to.add(address);
sendMail.setMailTos(to);
sendMail.setFrom("info@mail.royalpay.com.au");
sendMail.setTitle("Royalpay");
sendMail.setContent(content);
sendMail.setTags(tags);
mailGunService.sendMail(sendMail);
}
@Override
public String generateRegisterProcessKey(String accountName) {
return null;
}
private String getRegisterClientRedisKey(String accountName){
return REGISTER_CLIENT_PREFIX +accountName;
}
private String getRegisterClientPhoneExpireRedisKey(String phoneNumber){
return REGISTER_CLIENT_PHONE_EXPIRE_PREFIX +phoneNumber;
}
}

@ -19,15 +19,27 @@ public class SimpleClientApplyController {
private SimpleClientApplyService simpleClientApplyService;
@RequestMapping(value = "/account/{codeKey}", method = RequestMethod.POST)
public void registerAccount(@PathVariable String codeKey, @RequestBody @Valid NewAccountBean accountBean, Errors errors, HttpServletResponse response) throws Exception {
public void registerAccount(@PathVariable String codeKey, @RequestBody @Valid NewAccountBean accountBean, Errors errors, HttpServletResponse response)
throws Exception {
HttpUtils.handleValidErrors(errors);
String codeValue = simpleClientApplyService.getSMSVerifyCode(codeKey);
if (codeValue == null || !codeValue.equals(accountBean.getUsername())) {
throw new Exception("Verification code has expired or is not correct");
}
simpleClientApplyService.verifyRegisterSMSCode(codeKey,accountBean.getUsername());
JSONObject account = simpleClientApplyService.newAccount(accountBean);
simpleClientApplyService.deleteSMSVerifyCodeKey(codeKey);
String statusKey = simpleClientApplyService.partnerSignIn(account);
HttpUtils.setCookie(response, CommonConsts.CODE_KEY, statusKey);
}
// @RequestMapping(value = "/account/mail/verify", method = RequestMethod.GET)
// public void registerAccount(@PathVariable String codeKey, @RequestBody @Valid NewAccountBean accountBean, Errors errors, HttpServletResponse response)
// throws Exception {
// HttpUtils.handleValidErrors(errors);
// simpleClientApplyService.verifyRegisterSMSCode(codeKey, accountBean.getContactPhone());
//
// JSONObject account = simpleClientApplyService.newAccount(accountBean);
// simpleClientApplyService.deleteSMSVerifyCodeKey(codeKey);
// String statusKey = simpleClientApplyService.partnerSignIn(account);
// HttpUtils.setCookie(response, CommonConsts.CODE_KEY, statusKey);
// }
}

@ -0,0 +1,55 @@
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<table cellpadding="0" cellspacing="0" class="email-container" align="center" width="550" style="font-family: Lato, 'Lucida Sans', 'Lucida Grande', SegoeUI, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; font-weight: normal; line-height: 22px; color: #444444; text-align: left; border: 1px solid rgb(177, 213, 245); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; width: 550px;">
<tbody><tr>
<td>
<table cellpadding="0" cellspacing="0" class="padding" width="100%" style="padding-left: 40px; padding-right: 40px; padding-top: 30px; padding-bottom: 35px;">
<tbody>
<tr class="logo">
<td align="center">
<table class="logo" style="margin-bottom: 10px;">
<tbody><tr>
<td>
<img src="https://mpay.royalpay.com.au/static/images/logo_new.jpg" height="100" width="100" border="0" style="display: block;">
</td>
</tr>
</tbody></table>
</td>
</tr>
<tr class="header">
<td align="center">
<h1 style="font-size: 24px; line-height: 1.3em; margin-bottom: 5px;">Register Invitation</h1>
</td>
</tr>
<tr class="content">
<td>
<p style="font-size: 15px; font-weight: normal; line-height: 22px;">Dear Partner, </p>
<p style="font-size: 15px; font-weight: normal; line-height: 22px;">Thank you for registering an account with us!</p>
<p style="font-size: 15px; font-weight: normal; line-height: 22px;">This is a system verification email from RoyalPay. RoyalPay is an exciting platform that makes international payments as easy as local ones.
To get started, click on the button below:</p>
</td>
</tr>
<tr>
<td align="center">
<table cellpadding="12" border="0" style="font-family: Lato, 'Lucida Sans', 'Lucida Grande', SegoeUI, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; font-weight: bold; line-height: 25px; color: #444444; text-align: left;">
<tbody><tr>
<td class="button" style="color: rgb(255, 255, 255); font-size: 16px; line-height: 24px; text-align: center; display: block;">
<a th:href="${url}" style="color: rgb(255, 255, 255); text-align: center; display: block; padding: 12px 20px; height: 100%; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; text-decoration: none; background-color: rgb(43, 136, 217); min-width: 150px;"><strong>Register your account right now!</strong></a>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody></table>
Loading…
Cancel
Save