wangning 7 years ago
parent 09976bbab9
commit 48cc6509c0

@ -4,11 +4,13 @@ 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,String phoneNumber,String nationCode); String getSMSVerifyCode(String codeKey);
JSONObject newAccount(NewAccountBean accountBean); JSONObject newAccount(NewAccountBean accountBean);
void deleteSMSVerifyCodeKey(String codeKey); void deleteSMSVerifyCodeKey(String codeKey);
String partnerSignIn(JSONObject account); String partnerSignIn(JSONObject account);
String getSmsCodeAndSend();
} }

@ -1,12 +1,22 @@
package au.com.royalpay.payment.manage.application.core.impls; package au.com.royalpay.payment.manage.application.core.impls;
import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService; import java.util.ArrayList;
import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean; import java.util.List;
import au.com.royalpay.payment.tools.utils.sms.SmsSingleSender; import java.util.concurrent.TimeUnit;
import com.alibaba.fastjson.JSONObject; import javax.annotation.Resource;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
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.tools.env.SysConfigManager;
import au.com.royalpay.payment.tools.utils.sms.SmsSingleSender;
public class SimpleClientApplyServiceImpl implements SimpleClientApplyService { public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
@ -14,13 +24,18 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private int appId; private int appId;
@Value("${royalpay.sms.appkey}") @Value("${royalpay.sms.appkey}")
private String appKey; private String appKey;
@Resource
private SysConfigManager sysConfigManager;
@Resource
private StringRedisTemplate stringRedisTemplate;
private final SmsSingleSender smsSingleSender = new SmsSingleSender(appId,appKey); private final SmsSingleSender smsSingleSender = new SmsSingleSender(appId,appKey);
// TODO: 2018/5/23 kira 模板申请通过后修改
private final int REGISTER_CLIENT_TEMPLID = 123;
private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT";
@Override @Override
String getSMSVerifyCode(String codeKey,String phoneNumber,String nationCode){ public String getSMSVerifyCode(String codeKey){
// smsSingleSender.sendWithParam(); return null;
return null;
} }
@Override @Override
@ -37,4 +52,19 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
public String partnerSignIn(JSONObject account) { public String partnerSignIn(JSONObject account) {
return null; return null;
} }
@Override
public String getSmsCodeAndSend(String phoneNumber,String nationCode) {
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);
param.add(expireMin);
stringRedisTemplate.boundValueOps(register_client_key).set(register_client_key, Long.parseLong(expireMin), TimeUnit.MINUTES);
param.add(DateFormatUtils.format(coupon.getDate("expiry"), "yyyy-MM-dd"));
smsSingleSender.sendWithParam(nationCode,phoneNumber,REGISTER_CLIENT_TEMPLID,,"","","");
return register_client_key;
}
} }

@ -21,7 +21,7 @@ public class SimpleClientApplyController {
@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 { 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,accountBean.getContactPhone(),accountBean.getNation_code()); String codeValue = simpleClientApplyService.getSMSVerifyCode(codeKey);
if (codeValue == null || !codeValue.equals(accountBean.getUsername())) { if (codeValue == null || !codeValue.equals(accountBean.getUsername())) {
throw new Exception("Verification code has expired or is not correct"); throw new Exception("Verification code has expired or is not correct");
} }

Loading…
Cancel
Save