2
3
Просмотр исходного кода

短信
Signed-off-by: lijunqing <lijunqing@dashoo.cn>

lijunqing 6 лет назад
Родитель
Сommit
001dad5ce0

+ 63 - 0
src/dashoo.cn/backend/api/business/msg/msgService.go

@@ -0,0 +1,63 @@
+package msg
+
+import (
+	"dashoo.cn/backend/api/business/oilrtx"
+	. "dashoo.cn/backend/api/mydb"
+	"dashoo.cn/utils"
+	. "dashoo.cn/utils/db"
+	"encoding/json"
+	"github.com/go-xorm/xorm"
+	"io/ioutil"
+	"log"
+	"strconv"
+	"time"
+)
+
+type MsgService struct {
+	ServiceBase
+	MyServiceBase
+}
+
+func GetMsgService(xormEngine *xorm.Engine) *MsgService {
+	s := new(MsgService)
+	s.DBE = xormEngine
+	return s
+}
+
+//处理短信数据
+//tomobile 目的手机号 msg 信息 typecode 发送节点(1-1注册审核通过1-2注册审核不通过。。)username 发送用户 userrealname 发送用户真实姓名 userid 发送用户id
+func (s *MsgService) HandleMsg(toMobile,msg,typeCode,userName,userRealName,userId string) (err error)  {
+
+	//调用短信接口发送短信
+	rtxSvc := oilrtx.GetRtxService(utils.DBE)
+
+	defer func() {
+		//恢复程序的控制权
+		err := recover()
+		if err != nil {
+			log.Println("handleMsgError= ", err)
+		}
+	}()
+	resp:=rtxSvc.HandleSendMsg("", toMobile, msg)
+
+	var rtxRespToken oilrtx.RtxRespToken
+	if resp !=nil{
+		jsonBlob, _ := ioutil.ReadAll(resp.Body)
+		json.Unmarshal(jsonBlob, &rtxRespToken)
+	}else{
+		rtxRespToken.Code=-1
+	}
+	//如果发送返回代码存入短信信息记录表
+	var resultMsg oilrtx.Base_Msg
+	resultMsg.Type=typeCode
+	resultMsg.UserName=userName
+	resultMsg.UserRealName=userRealName
+	resultMsg.UserId=userId
+	resultMsg.ToMobile=toMobile
+	resultMsg.Msg=msg
+	resultMsg.ToTime=time.Now().Format("2006-01-02 15:04:05")
+	resultMsg.Status=strconv.Itoa(rtxRespToken.Code)
+	_,error:=s.InsertEntity(&resultMsg)
+
+	return error
+}

+ 2 - 2
src/dashoo.cn/backend/api/business/oilrtx/rtx.go

@@ -56,7 +56,7 @@ type Tmp_User struct {
 }
 
 
-type BaseMsg struct {
+type Base_Msg struct {
 	Id           int    `xorm:"not null pk autoincr INT(11)"`
 	Type         string `xorm:"not null comment('类别(1注册(1-1注册成功1-2注册失败) 2密码重置(2-1验证码2-2重置密码))') VARCHAR(10)"`
 	UserName     string `xorm:"not null comment('企业用户名(即登录账号)') VARCHAR(50)"`
@@ -69,7 +69,7 @@ type BaseMsg struct {
 }
 
 
-type BaseVCode struct {
+type Base_VCode struct {
 	Id           int    `xorm:"not null pk autoincr INT(11)"`
 	UserName     string `xorm:"not null comment('企业用户名(即登录账号)') VARCHAR(50)"`
 	UserId       string `xorm:"not null comment('用户名Id(BaseUser表Id)') VARCHAR(11)"`

+ 1 - 0
src/dashoo.cn/backend/api/controllers/base.go

@@ -300,6 +300,7 @@ func (this *BaseController) Prepare() {
 		"/api/register/orgloginlist",
 		"/api/register/getauditerbydept",
 		"/api/register/getCode",
+		"/api/register/updatepassword",
 	}
 	for _, v := range urls {
 		fmt.Println("**this.Ctx.Input.URL()**", this.Ctx.Input.URL())

+ 42 - 81
src/dashoo.cn/backend/api/controllers/register/oilcorporateinfo.go

@@ -1,6 +1,7 @@
 package register
 
 import (
+	msg2 "dashoo.cn/backend/api/business/msg"
 	"dashoo.cn/backend/api/business/oilrtx"
 	"encoding/json"
 	"fmt"
@@ -295,33 +296,17 @@ func (this *OilCorporateInfoController) ComAudit() {
 				_, err3 := svcRegister.InsertEntityBytbl(OilCorporateInfoName, &model)
 				if err3 == nil {
 					//编辑短信内容
-					//toMobile:=model.UserTelephone
-					//msg:="恭喜您!市场管理信息系统账号注册成功,系统登录用户名为: "+model.UserName
-
-					//调用短信接口发送短信
-					//rtxSvc := oilrtx.GetRtxService(utils.DBE)
-					//resp:=rtxSvc.HandleSendMsg("", toMobile, msg)
-					//jsonBlob, _ := ioutil.ReadAll(resp.Body)
-					//var rtxRespToken oilrtx.RtxRespToken
-					//json.Unmarshal(jsonBlob, &rtxRespToken)
-
-					//如果发送返回代码存入短信信息记录表
-					//var resultMsg oilrtx.BaseMsg
-					//resultMsg.Type="1-1"
-					//resultMsg.UserName=model.UserName
-					//resultMsg.UserRealName=model.UserRealName
-					//resultMsg.UserId=strconv.Itoa(model.UserId)
-					//resultMsg.ToMobile=toMobile
-					//resultMsg.Msg=msg
-					//resultMsg.ToTime=time.Now().Format("2006-01-02 15:04:05")
-					//resultMsg.Status=strconv.Itoa(rtxRespToken.Code)
-					//svcRegister.InsertEntityBytbl("Base_Msg", &resultMsg)
-
-					errinfo.Message = "审核通过!"
-					errinfo.Code = 0
-					errinfo.Item = model.Id
-					this.Data["json"] = &errinfo
-					this.ServeJSON()
+					toMobile:=model.UserTelephone
+					msg:="恭喜您!市场管理信息系统账号注册成功,系统登录用户名为: "+model.UserName
+					msgService:=msg2.GetMsgService(utils.DBE)
+					err:=msgService.HandleMsg(toMobile,msg,"1-1",model.UserName,model.UserRealName,strconv.Itoa(model.UserId))
+					if err==nil {
+						errinfo.Message = "审核通过!"
+						errinfo.Code = 0
+						errinfo.Item = model.Id
+						this.Data["json"] = &errinfo
+						this.ServeJSON()
+					}
 				} else {
 					errinfo.Message = "操作失败!--1"
 					errinfo.Code = -1
@@ -350,31 +335,16 @@ func (this *OilCorporateInfoController) ComAudit() {
 
 		//编辑短信内容
 		//查找审批人联系方式
-		//var sPerson userRole.Base_User
-		//svc.GetEntity(&sPerson,"Id="+model.CheckUserId)
-		//toMobile:=model.UserTelephone
-		//msg:="市场管理信息系统账号注册失败,因“"+Remark+"”,请按照要求重新注册,联系人:"+model.CheckUserName+",联系电话:"+sPerson.Mobile+""
+		var sPerson userRole.Base_User
+		svc.GetEntity(&sPerson,"Id="+model.CheckUserId)
+		toMobile:=model.UserTelephone
+		msg:="市场管理信息系统账号注册失败,因“"+Remark+"”,请按照要求重新注册,联系人:"+model.CheckUserName+",联系电话:"+sPerson.Mobile+""
 
 		//调用短信接口发送短信
-		//rtxSvc := oilrtx.GetRtxService(utils.DBE)
-		//resp:=rtxSvc.HandleSendMsg("", toMobile, msg)
-		//jsonBlob, _ := ioutil.ReadAll(resp.Body)
-		//var rtxRespToken oilrtx.RtxRespToken
-		//json.Unmarshal(jsonBlob, &rtxRespToken)
-		//
-		//如果发送返回代码存入短信信息记录表
-		//var resultMsg oilrtx.BaseMsg
-		//resultMsg.Type="1-2"
-		//resultMsg.UserName=model.UserName
-		//resultMsg.UserRealName=model.UserRealName
-		//resultMsg.UserId=strconv.Itoa(model.UserId)
-		//resultMsg.ToMobile=toMobile
-		//resultMsg.Msg=msg
-		//resultMsg.ToTime=time.Now().Format("2006-01-02 15:04:05")
-		//resultMsg.Status=strconv.Itoa(rtxRespToken.Code)
-		//svc.InsertEntityBytbl("Base_Msg", &resultMsg)
+		msgService:=msg2.GetMsgService(utils.DBE)
+		res:=msgService.HandleMsg(toMobile,msg,"1-2",model.UserName,model.UserRealName,strconv.Itoa(model.UserId))
 
-		if err == nil {
+		if err == nil && res==nil{
 			errinfo.Message = "审核未通过!"
 			errinfo.Code = 0
 			this.Data["json"] = &errinfo
@@ -596,7 +566,7 @@ func (this *OilCorporateInfoController) GetCode() {
 	//将数据存入
 	err2 := svcRegister.DeleteEntityBytbl("Base_VCode", "UserName='"+userName+"'")
 	if err2==nil{
-		var model oilrtx.BaseVCode
+		var model oilrtx.Base_VCode
 		model.UserName=userName
 		model.UserId=strconv.Itoa(sPerson.Id)
 		model.Code=randomNumber
@@ -604,50 +574,41 @@ func (this *OilCorporateInfoController) GetCode() {
 		if err==nil{
 			//发短信
 			//编辑短信内容
-			toMobile:=mobile
 			msg:="验证码为: "+ randomNumber+",5分钟内有效"
-
 			//调用短信接口发送短信
-			//rtxSvc := oilrtx.GetRtxService(utils.DBE)
-			//resp:=rtxSvc.HandleSendMsg("", toMobile, msg)
-			//jsonBlob, _ := ioutil.ReadAll(resp.Body)
-			var rtxRespToken oilrtx.RtxRespToken
-			//json.Unmarshal(jsonBlob, &rtxRespToken)
-
-			//如果发送返回代码存入短信信息记录表
-			var resultMsg oilrtx.BaseMsg
-			resultMsg.Type="2-1"
-			resultMsg.UserName=userName
-			resultMsg.UserRealName=sPerson.Realname
-			resultMsg.UserId=strconv.Itoa(sPerson.Id)
-			resultMsg.ToMobile=toMobile
-			resultMsg.Msg=msg
-			resultMsg.ToTime=time.Now().Format("2006-01-02 15:04:05")
-			resultMsg.Status=strconv.Itoa(rtxRespToken.Code)
-			svcRegister.InsertEntityBytbl("Base_Msg", &resultMsg)
-
-			errinfo.Message = "请等待接收验证码,5分钟内有效"
-			errinfo.Code = 0
-			this.Data["json"] = &errinfo
-			this.ServeJSON()
+			msgService:=msg2.GetMsgService(utils.DBE)
+			error:=msgService.HandleMsg(mobile,msg,"2-1",userName,sPerson.Realname,strconv.Itoa(sPerson.Id))
+			if error==nil{
+				errinfo.Message = "请等待接收验证码,5分钟内有效"
+				errinfo.Code = 0
+				this.Data["json"] = &errinfo
+				this.ServeJSON()
+			}
 		}
 	}
 	}
 }
 
-
+type UpdatePw struct{
+	UserName string
+	YzCode   string
+	PassWord string
+}
 // @Title 更新密码
 // @Description 更新密码
-// @router /updatePassword [get]
+// @router /updatepassword [post]
 func (this *OilCorporateInfoController) UpdatePassword() {
 	svcRegister := register.GetOilCorporateInfoService(utils.DBE)
 	var errinfo ErrorDataInfo
-	userName:=this.GetString("userName")
-	//mobile:=this.GetString("mobile")
-	yzCode:=this.GetString("yzCode")
-	passWord:=this.GetString("passWord")
+	var model UpdatePw
+	var jsonBlob = this.Ctx.Input.RequestBody
+	json.Unmarshal(jsonBlob, &model)
+
+	userName:=model.UserName
+	yzCode:=model.YzCode
+	passWord:=model.PassWord
 
-	var res oilrtx.BaseVCode
+	var res oilrtx.Base_VCode
 	svcRegister.GetEntity(&res,"UserName='"+userName+"' and Code='"+yzCode+"'")
 
 	if res.UserName!=""{

+ 7 - 7
src/dashoo.cn/frontend_web/src/pages/passwordback.vue

@@ -193,7 +193,7 @@
                 }
               }, 1000)
 
-              let time2 = 70
+              let time2 = 300
               let timer2 = setInterval(() => {
                 if (time2 <= 0) {
                   this.isCodePass = true
@@ -202,6 +202,7 @@
                   this.formData.UserPass=""
                   this.formData.UserPass2=""
                   clearInterval(timer)
+                  clearInterval(timer2)
                 } else {
                   time2--
                 }
@@ -257,14 +258,13 @@
         }
 
         let params = {
-          userName: this.formData.UserName,
-          mobile: this.formData.Telephone,
-          yzCode: this.formData.yzCode,
-          passWord:this.formData.UserPass2
+          UserName: this.formData.UserName,
+          YzCode: this.formData.yzCode,
+          PassWord:this.formData.UserPass2
 
         }
-
-        _this.$axios.post('/register/updatePassword', {params})
+        console.log(params)
+        _this.$axios.post('/register/updatepassword',params)
           .then(function (response) {
             if (response.data.code === 0) {
               _this.$message({