提交 5625bad1 编写于 作者: O o2sword

支持自定义短信通道发送验证码

上级 ace70e09
package com.x.program.center.jaxrs.code;
import com.x.base.core.project.Applications;
import com.x.program.center.ThisApplication;
import org.apache.commons.lang3.BooleanUtils;
import com.x.base.core.container.EntityManagerContainer;
......@@ -13,6 +15,7 @@ import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.jaxrs.WrapString;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
class ActionCreate extends BaseAction {
......@@ -22,7 +25,15 @@ class ActionCreate extends BaseAction {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
if (BooleanUtils.isNotTrue(Config.collect().getEnable())) {
String customSms = ThisApplication.context().applications().findApplicationName(CUSTOM_SMS_APPLICATION);
if(StringUtils.isNotBlank(customSms) && Config.customConfig(CUSTOM_SMS_CONFIG_NAME) != null){
ActionResponse resp = ThisApplication.context().applications()
.getQuery(customSms, Applications.joinQueryUri("sms", "send", "code", "mobile", mobile, "token", "(0)"));
RespWi respWi = resp.getData(RespWi.class);
if (BooleanUtils.isNotTrue(respWi.getValue())) {
throw new ExceptionTransferCodeError(resp);
}
}else if (BooleanUtils.isNotTrue(Config.collect().getEnable())) {
logger.warn("短信无法发送,系统没有启用O2云服务.");
} else {
Message message = new Message();
......
......@@ -10,49 +10,32 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.project.Applications;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.program.center.ThisApplication;
import com.x.program.center.core.entity.Code;
import com.x.program.center.core.entity.Code_;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
class ActionValidate extends BaseAction {
ActionResult<Wo> execute(String mobile, String answer) throws Exception {
/*try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
wo.setValue(false);
if(StringUtils.isNotEmpty(answer) && StringUtils.isNotEmpty(mobile)) {
Code code = this.get(emc, mobile);
if (null != code) {
if (answer.equals(code.getAnswer())) {
emc.beginTransaction(Code.class);
emc.remove(code);
emc.commit();
wo.setValue(true);
} else {
int vn = code.getVerifyNumber() == null ? 0 : code.getVerifyNumber();
vn++;
emc.beginTransaction(Code.class);
if (vn < 6) {
code.setVerifyNumber(vn);
} else {
emc.remove(code);
}
emc.commit();
}
}
}
result.setData(wo);
return result;
}*/
ActionResult<Wo> result = new ActionResult<>();
ActionResponse resp = ConnectionAction.get(Config.collect().url()
+ "/o2_collect_assemble/jaxrs/code/validate/mobile/" + mobile + "/answer/" + answer, null);
Wo wo = new Wo();
wo.setValue(resp.getData(ActionValidateCascade.Wo.class).getValue());
Wo wo;
String customSms = ThisApplication.context().applications().findApplicationName(CUSTOM_SMS_APPLICATION);
if(StringUtils.isNotBlank(customSms) && Config.customConfig(CUSTOM_SMS_CONFIG_NAME) != null){
ActionResponse resp = ThisApplication.context().applications()
.getQuery(customSms, Applications.joinQueryUri("sms", "validate", "mobile", mobile, "answer", answer, "token", "(0)"));
wo = resp.getData(Wo.class);
}else {
ActionResponse resp = ConnectionAction.get(Config.collect().url()
+ "/o2_collect_assemble/jaxrs/code/validate/mobile/" + mobile + "/answer/" + answer, null);
wo = resp.getData(Wo.class);
}
result.setData(wo);
return result;
}
......
package com.x.program.center.jaxrs.code;
import com.x.base.core.project.Applications;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.program.center.ThisApplication;
import org.apache.commons.lang3.StringUtils;
class ActionValidateCascade extends BaseAction {
ActionResult<Wo> execute(String mobile, String answer) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
ActionResponse resp = ConnectionAction.get(Config.collect().url()
+ "/o2_collect_assemble/jaxrs/code/validate/mobile/" + mobile + "/answer/" + answer, null);
Wo wo = new Wo();
wo.setValue(resp.getData(Wo.class).getValue());
Wo wo;
String customSms = ThisApplication.context().applications().findApplicationName(CUSTOM_SMS_APPLICATION);
if(StringUtils.isNotBlank(customSms) && Config.customConfig(CUSTOM_SMS_CONFIG_NAME) != null){
ActionResponse resp = ThisApplication.context().applications()
.getQuery(customSms, Applications.joinQueryUri("sms", "validate", "mobile", mobile, "answer", answer, "token", "(0)"));
wo = resp.getData(Wo.class);
}else {
ActionResponse resp = ConnectionAction.get(Config.collect().url()
+ "/o2_collect_assemble/jaxrs/code/validate/mobile/" + mobile + "/answer/" + answer, null);
wo = resp.getData(Wo.class);
}
result.setData(wo);
return result;
}
......@@ -20,4 +30,4 @@ class ActionValidateCascade extends BaseAction {
public static class Wo extends WrapBoolean {
}
}
\ No newline at end of file
}
......@@ -4,4 +4,8 @@ import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
protected static final String CUSTOM_SMS_APPLICATION = "x_sms_assemble_control";
protected static final String CUSTOM_SMS_CONFIG_NAME = "custom_sms";
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册