wangning 7 years ago
parent e9be935d2a
commit 3f03b2aa18

@ -22,4 +22,6 @@ public interface SimpleClientApplyService {
void deleteVerifyMailKey(String codeKey);
void verifyMail(String address, JSONObject loginAccount);
}

@ -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.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.ServerErrorException;
import au.com.royalpay.payment.tools.locale.LocaleSupport;
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.SmsSingleSenderResult;
import com.alibaba.fastjson.JSONObject;
@ -46,11 +50,14 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private SpringTemplateEngine thymeleaf;
@Resource
private ClientManager clientManager;
@Resource
private SignInAccountService signInAccountService;
@Resource
private StringRedisTemplate stringRedisTemplate;
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_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS";
private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL";
@ -96,7 +103,10 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
String expireMin = (String) sysConfig.getOrDefault("sms.verification.code.expire", 3);
param.add(expireMin);
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) {
throw new ServerErrorException("System Error");
}
@ -169,12 +179,27 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
stringRedisTemplate.delete(getVerifyMailRedisKey(codeKey));
}
@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 getVerifyMailRedisKey(String codekey) {
return VERIFY_MAIL_PREFIX + codekey;
}

@ -2,8 +2,6 @@ package au.com.royalpay.payment.manage.application.web;
import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService;
import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean;
import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.http.HttpUtils;
@ -27,8 +25,7 @@ import javax.validation.Valid;
public class SimpleClientApplyController {
@Resource
private SimpleClientApplyService simpleClientApplyService;
@Resource
private SignInAccountService signInAccountService;
@RequestMapping(value = "/account/{codeKey}", method = RequestMethod.POST)
@ResponseBody
public void registerAccount(@PathVariable String codeKey, @RequestBody @Valid NewAccountBean accountBean, Errors errors, HttpServletResponse response)
@ -55,10 +52,7 @@ public class SimpleClientApplyController {
@ResponseBody
public void verifyMail(@PathVariable String codeKey, @PathVariable String address,@RequestBody JSONObject account){
simpleClientApplyService.checkOrGenerateVerifyMailKey(address,codeKey);
LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginId(account.getString("userName"));
loginInfo.setPassword(account.getString("password"));
signInAccountService.accountCheck(loginInfo);
simpleClientApplyService.verifyMail(address,account);
simpleClientApplyService.deleteVerifyMailKey(codeKey);
}

@ -32,6 +32,30 @@ public class SimpleClientApplyServiceImplTest {
@Test
public void getAndSendSmsCode() {
String phone = "17626011667";
String nationCode = "+86";
String code = simpleClientApplyService.getAndSendSmsCode(phone, nationCode);
System.out.println(code);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
try {
simpleClientApplyService.getAndSendSmsCode(phone, nationCode);
} catch (Exception e) {
System.out.println("之前应当报错,短信已经发送");
}
simpleClientApplyService.verifyRegisterSMSCode(code, phone);
try {
simpleClientApplyService.verifyRegisterSMSCode(code, phone);
System.out.println(code);
} catch (Exception e) {
System.out.println("报错 无法验证");
}
}
@Test

Loading…
Cancel
Save