Merge remote-tracking branch 'origin/clientApply' into clientApply

master
yuan 6 years ago
commit 9d05f01072

@ -4,11 +4,22 @@ import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
public interface SimpleClientApplyService { public interface SimpleClientApplyService {
String getSMSVerifyCode(String codeKey); void verifyRegisterSMSCode(String codeKey, String phoneNumber);
JSONObject newAccount(NewAccountBean accountBean); JSONObject newAccount(NewAccountBean accountBean);
void deleteSMSVerifyCodeKey(String codeKey);
String partnerSignIn(JSONObject account); String partnerSignIn(JSONObject account);
String getAndSendSmsCode(String phoneNumber, String nationCode);
String checkOrGenerateRegisterProcessKey(String accountName, String codeKey);
void deleteRegisterProcessKey(String codeKey);
void sendVerifyEmail(String address, int client_id);
String checkOrGenerateVerifyMailKey(String address, String codeKey);
void deleteVerifyMailKey(String codeKey);
} }

@ -0,0 +1,179 @@
package au.com.royalpay.payment.manage.application.core.impls;
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.core.ClientManager;
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.ServerErrorException;
import au.com.royalpay.payment.tools.mail.SendMail;
import au.com.royalpay.payment.tools.utils.sms.SmsSingleSender;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.Assert;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring4.SpringTemplateEngine;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
@Value("${royalpay.sms.appid}")
private int appId;
@Value("${royalpay.sms.appkey}")
private String appKey;
@Resource
private SysConfigManager sysConfigManager;
@Resource
private MailGunService mailGunService;
@Resource
private SpringTemplateEngine thymeleaf;
@Resource
private ClientManager clientManager;
@Resource
private StringRedisTemplate stringRedisTemplate;
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_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS";
private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL";
private final List<String> tags = new ArrayList<>();
@PostConstruct
public void init(){
tags.add("account");
}
@Override
public void verifyRegisterSMSCode(String codeKey,String phoneNumber) {
String rediskey = getRegisterClientRedisKey(phoneNumber);
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);
}
@Override
public JSONObject newAccount(NewAccountBean accountBean) {
return null;
}
@Override
public String partnerSignIn(JSONObject account) {
return null;
}
@Override
public String getAndSendSmsCode(String phoneNumber, String nationCode) {
String reidsCheckCodeKey = getRegisterClientRedisKey(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();
ArrayList<String> param = new ArrayList<>();
String registerClientCode = RandomStringUtils.random(6, true, true);
param.add(registerClientCode);
String expireMin = (String) sysConfig.getOrDefault("sms.verification.code.expire", 3);
param.add(expireMin);
try {
smsSingleSender.sendWithParam(nationCode, phoneNumber, REGISTER_CLIENT_TEMPLID, param, "", "", "");
} catch (Exception e) {
throw new ServerErrorException("System Error");
}
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){
throw new BadRequestException("Merchant not found");
}
String key = checkOrGenerateVerifyMailKey(address,null);
Context ctx = new Context();
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<>();
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 checkOrGenerateRegisterProcessKey(String accountName, String codeKey) {
Assert.notNull(accountName,"accountName can't be null");
if(StringUtils.isNotEmpty(codeKey)){
String redisAccountName = stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(codeKey)).get();
if(!accountName.equals(redisAccountName)){
throw new BadRequestException("Data error,Please re-register for safety.");
}else {
return codeKey;
}
}
String key = RandomStringUtils.random(10, true, false);
stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(key)).set(accountName,1,TimeUnit.HOURS);
return key;
}
@Override
public void deleteRegisterProcessKey(String codeKey) {
stringRedisTemplate.delete(getRegisterClientProcessRedisKey(codeKey));
}
@Override
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)){
throw new BadRequestException("Data error");
}else {
return codeKey;
}
}
String key = RandomStringUtils.random(10, true, false);
stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(key)).set(address,1,TimeUnit.HOURS);
return key;
}
@Override
public void deleteVerifyMailKey(String codeKey) {
stringRedisTemplate.delete(getVerifyMailRedisKey(codeKey));
}
private String getRegisterClientRedisKey(String phoneNumber){
return REGISTER_CLIENT_PREFIX +phoneNumber;
}
private String getRegisterClientProcessRedisKey(String codeKey){
return REGISTER_CLIENT_PROCESS_PREFIX+codeKey;
}
private String getVerifyMailRedisKey(String codekey){
return VERIFY_MAIL_PREFIX+codekey;
}
}

@ -4,30 +4,58 @@ 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.tools.CommonConsts; import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.http.HttpUtils; import au.com.royalpay.payment.tools.http.HttpUtils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors; import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
@RestController @Controller
@RequestMapping("/register") @RequestMapping("/register")
public class SimpleClientApplyController { public class SimpleClientApplyController {
@Resource @Resource
private SimpleClientApplyService simpleClientApplyService; private SimpleClientApplyService simpleClientApplyService;
@Resource
@RequestMapping(value = "/account/{codeKey}", method = RequestMethod.POST) @RequestMapping(value = "/account/{codeKey}", method = RequestMethod.POST)
public void registerAccount(@PathVariable String codeKey, @RequestBody @Valid NewAccountBean accountBean, Errors errors, HttpServletResponse response) throws Exception { @ResponseBody
public void registerAccount(@PathVariable String codeKey, @RequestBody @Valid NewAccountBean accountBean, Errors errors, HttpServletResponse response)
throws Exception {
HttpUtils.handleValidErrors(errors); HttpUtils.handleValidErrors(errors);
String codeValue = simpleClientApplyService.getSMSVerifyCode(codeKey); simpleClientApplyService.verifyRegisterSMSCode(codeKey,accountBean.getContactPhone());
if (codeValue == null || !codeValue.equals(accountBean.getUsername())) {
throw new Exception("Verification code has expired or is not correct");
}
JSONObject account = simpleClientApplyService.newAccount(accountBean); JSONObject account = simpleClientApplyService.newAccount(accountBean);
simpleClientApplyService.deleteSMSVerifyCodeKey(codeKey);
String statusKey = simpleClientApplyService.partnerSignIn(account); String statusKey = simpleClientApplyService.partnerSignIn(account);
HttpUtils.setCookie(response, CommonConsts.CODE_KEY, statusKey); HttpUtils.setCookie(response, CommonConsts.CODE_KEY, statusKey);
} }
@RequestMapping(value = "/account/mail/{address}/verify/{codeKey}/jump", method = RequestMethod.GET)
public ModelAndView jumpVerifyMail(@PathVariable String codeKey, @PathVariable String address){
simpleClientApplyService.checkOrGenerateVerifyMailKey(address,codeKey);
ModelAndView view = new ModelAndView("verify_mail");
view.addObject("codeKey", codeKey);
return view;
}
@RequestMapping(value = "/account/mail/{address}/verify/{codeKey}", method = RequestMethod.POST)
@ResponseBody
public void verifyMail(@PathVariable String codeKey, @PathVariable String address,@RequestBody JSONObject account){
simpleClientApplyService.checkOrGenerateVerifyMailKey(address,codeKey);
ModelAndView view = new ModelAndView("verify_mail");
view.addObject("codeKey", codeKey);
simpleClientApplyService.deleteVerifyMailKey(codeKey);
}
} }

@ -18,6 +18,8 @@ public class NewAccountBean {
private String displayName; private String displayName;
@JSONField(name = "contact_phone") @JSONField(name = "contact_phone")
private String contactPhone; private String contactPhone;
@JSONField(name = "nation_code")
private String nation_code = "+61";
private int role = PartnerRole.CASHIER.getCode(); private int role = PartnerRole.CASHIER.getCode();
public JSONObject toJson() { public JSONObject toJson() {
@ -70,4 +72,12 @@ public class NewAccountBean {
public void setContactPhone(String contactPhone) { public void setContactPhone(String contactPhone) {
this.contactPhone = contactPhone; this.contactPhone = contactPhone;
} }
public String getNation_code() {
return nation_code;
}
public void setNation_code(String nation_code) {
this.nation_code = nation_code;
}
} }

@ -106,3 +106,8 @@ mail.mailgun.domain=mail.royalpay.com.au
mail.mailgun.default.merchantlist=merchants@mail.royalpay.com.au mail.mailgun.default.merchantlist=merchants@mail.royalpay.com.au
##############
##短信key
##############
royalpay.sms.appid=1400035361
royalpay.sms.appkey=d6e7cc6400ecd159963c1972cdb088cf

@ -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>

@ -0,0 +1,158 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>RoyalPay | Reset Password</title>
<link rel="apple-touch-icon" sizes="57x57" href="ico/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="ico/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="ico/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="ico/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="ico/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="ico/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="ico/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="ico/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="ico/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="ico/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="ico/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="ico/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="ico/favicon-16x16.png">
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.5 -->
<link href="static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="./static/lib/dist/css/AdminLTE.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style type="text/css">
#bg {
display: block;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index: 1001;
-moz-opacity: 0.7;
opacity: .70;
filter: alpha(opacity=70);
}
#show {
display: block;
position: absolute;
top: 50%;
left: 40%;
width: 20%;
padding: 8px;
z-index: 1002;
overflow: auto;
}
</style>
</head>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<p><img src="static/images/rp_logo.svg" style="width:45%"></p>
<a href="index.html"><b>RoyalPay</b></a>
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">Verify Your Mail</p>
<form action="" method="post">
<div class="form-group has-feedback">
<input type="text" id="userName" class="form-control" placeholder="User Names">
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="row">
<div class="form-group col-xs-12">
<input type="text" name="codeKey" class="form-control" style="width: 70%;display: inline"
id="codeKey" placeholder="Verification Code">
<img style="width:30%;display:inline;height: 34px;float: right" id="email-kaptcha"
src="/global/userstatus/captcha-login"
title="点击更换"/>
</div>
<div class="col-xs-12 margin-bottom">
<button type="button" id="submitEmail-btn" class="btn btn-success btn-block btn-flat">Submit</button>
</div>
</div>
<p style="font-size: smaller">
文案修改 We need your partner code to confirm your identity information, please enter it. (Your partner code is the same as the first four letters of your order ID.)
</p>
</form>
</div>
<!-- /.login-box-body -->
</div>
<!-- /.login-box -->
<script src="static/lib/jquery/jquery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="static/lib/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" data-th-inline="javascript">
$(document).ready(function () {
$('input').keypress(function (evt) {
if (evt.keyCode == 13) {
$('#login-btn').click();
}
});
$('#submitEmail-btn').click(function () {
var userName = $('#userName').val();
if (userName == null || userName.length == 0) {
alert('请输入用户名');
return;
}
var verifyCode = $('#email—verifyCode').val();
if (verifyCode == null || verifyCode.length == 0) {
alert('请填写验证码');
return;
}
$("#bg").show();
$("#show").show();
$.ajax({
url: '/register/account/mail/'+,
method: 'GET',
contentType: 'application/json',
dataType: 'text',
success: function (resp) {
$("#bg").hide();
$("#show").hide();
alert("Reset password email has send your mailbox:"+resp);
location.href = 'index.html'
},
error: function (jqXHR) {
$("#bg").hide();
$("#show").hide();
alert(JSON.parse(jqXHR.responseText).message);
$('#email-kaptcha').attr("src", "/global/userstatus/captcha-login?" + Math.floor(Math.random() * 100));
}
})
})
})
</script>
<div id="bg" style="display: none"></div>
<div id="show" style="display: none">
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0"
aria-valuemax="100" style="width: 100%">
<span class="sr-only">Requesting...</span>
</div>
</div>
</div>
</body>
</html>
Loading…
Cancel
Save