فهرست منبع

fix:修改短信验证码

zqbao 9 ماه پیش
والد
کامیت
6c447e1346
3فایلهای تغییر یافته به همراه4 افزوده شده و 55 حذف شده
  1. 1 2
      controllers/user.go
  2. 1 53
      services/sms.go
  3. 2 0
      utils/config.go

+ 1 - 2
controllers/user.go

@@ -164,10 +164,9 @@ func (this *UserController) GetVerifyCode() {
 		var ok bool
 		if req.AreaCode == "86" {
 			ok = services.SendSmsCode(req.Phone, code)
-		} else {
-			ok = services.SendSmsCodeGj(req.Phone, code, req.AreaCode)
 		}
 		if !ok {
+			br.Msg = "请检查手机号和区号"
 			br.ErrMsg = "短信验证码发送失败"
 			return
 		} else {

+ 1 - 53
services/sms.go

@@ -11,7 +11,7 @@ import (
 
 func SendSmsCode(mobile, vcode string) bool {
 	flag := false
-	tplId := "262642"
+	tplId := utils.SMS_TPLID
 	expiresTime := "15"
 	result, err := sendSms(mobile, tplId, vcode, expiresTime)
 	if err != nil {
@@ -61,55 +61,3 @@ func sendSms(mobile, tplId, code, expirdTime string) (rs []byte, err error) {
 	defer resp.Body.Close()
 	return ioutil.ReadAll(resp.Body)
 }
-
-func SendSmsCodeGj(mobile, vcode, areaNum string) bool {
-	flag := false
-	result, err := sendSmsGj(mobile, vcode, areaNum)
-	if err != nil {
-		fmt.Println("发送短信失败")
-		return false
-	}
-	fmt.Println("result", string(result))
-	var netReturn map[string]interface{}
-	err = json.Unmarshal(result, &netReturn)
-	if err != nil {
-		utils.ApiLog.Info("短信验证码发送失败", "err:"+err.Error()+" result"+string(result))
-		flag = false
-	}
-	if netReturn["error_code"].(float64) == 0 {
-		fmt.Printf("接口返回result字段是:\r\n%v", netReturn["result"])
-		flag = true
-	} else {
-		utils.ApiLog.Info("短信验证码发送失败" + "result" + string(result))
-		flag = false
-	}
-	return flag
-}
-
-func sendSmsGj(mobile, code, areaNum string) (rs []byte, err error) {
-	var Url *url.URL
-	apiURL := "http://v.juhe.cn/smsInternational/send.php"
-	//初始化参数
-	param := url.Values{}
-	//配置请求参数,方法内部已处理urlencode问题,中文参数可以直接传参
-	param.Set("mobile", mobile)                    //接受短信的用户手机号码
-	param.Set("tplId", "262642")                   //您申请的短信模板ID,根据实际情况修改
-	param.Set("tplValue", "#code#="+code+"#m#=15") //您设置的模板变量,根据实际情况
-	param.Set("key", utils.JhGjAppKey)             //应用APPKEY(应用详细页查询)
-	param.Set("areaNum", areaNum)                  //应用APPKEY(应用详细页查询)
-
-	Url, err = url.Parse(apiURL)
-	if err != nil {
-		fmt.Printf("解析url错误:\r\n%v", err)
-		return nil, err
-	}
-	//如果参数中有中文参数,这个方法会进行URLEncode
-	Url.RawQuery = param.Encode()
-	resp, err := http.Get(Url.String())
-	if err != nil {
-		fmt.Println("err:", err)
-		return nil, err
-	}
-	defer resp.Body.Close()
-	return ioutil.ReadAll(resp.Body)
-}

+ 2 - 0
utils/config.go

@@ -89,9 +89,11 @@ func init() {
 	WX_MINI_APPID = config["wx_mini_appid"]
 	WX_MINI_APP_SECRET = config["wx_mini_app_secret"]
 	// 仅测试
+	SMS_TPLID = "262642"
 	AlarmMsgUrl = `http://127.0.0.1:8606/api/alarm/send`
 	WX_MINI_APPID = "wx1c6d59a9ca4b42b3"
 	WX_MINI_APP_SECRET = "090716fa7b7fd89172cb26065fa4e6af"
+
 	DW_WX_Id = config["dw_wx_id"]
 	DW_WX_APPID = config["dw_wx_appid"]
 	DW_WX_APP_SECRET = config["dw_wx_app_secret"]