123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package services
- import (
- "encoding/json"
- "fmt"
- "hongze/hongze_yb/global"
- "hongze/hongze_yb/services/alarm_msg"
- "hongze/hongze_yb/utils"
- "io/ioutil"
- "net/http"
- "net/url"
- )
- const SmsExpireMinute = 15
- func SendSmsCode(mobile, vCode string) bool {
- flag := false
-
- tplId := "254663"
- result, err := sendSms(mobile, tplId, vCode)
- 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 {
-
- go alarm_msg.SendAlarmMsg("短信验证码发送失败, Err:"+err.Error()+";Result:"+string(result), 2)
- flag = false
- }
- if netReturn["error_code"].(float64) == 0 {
- fmt.Printf("接口返回result字段是:\r\n%v", netReturn["result"])
- flag = true
- } else {
-
- if netReturn["error_code"].(float64) != 205401 {
- go alarm_msg.SendAlarmMsg("短信验证码发送失败, Result:"+string(result), 2)
- }
- flag = false
- }
- return flag
- }
- func sendSms(mobile, tplId, code string) (rs []byte, err error) {
- var Url *url.URL
- apiURL := "http://v.juhe.cn/sms/send"
-
- param := url.Values{}
-
- param.Set("mobile", mobile)
- param.Set("tpl_id", tplId)
- tplVal := fmt.Sprintf(`#code#=%s&#m#=%d`, code, SmsExpireMinute)
- param.Set("tpl_value", tplVal)
- param.Set("key", utils.JhGnAppKey)
- Url, err = url.Parse(apiURL)
- if err != nil {
- fmt.Printf("解析url错误:\r\n%v", err)
- return nil, err
- }
-
- 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)
- }
- 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 {
-
- go alarm_msg.SendAlarmMsg("短信验证码发送失败, Err:"+err.Error()+";Result:"+string(result), 2)
- flag = false
- }
- if netReturn["error_code"].(float64) == 0 {
- fmt.Printf("接口返回result字段是:\r\n%v", netReturn["result"])
- flag = true
- } else {
-
- if netReturn["error_code"].(float64) != 205401 {
- go alarm_msg.SendAlarmMsg("短信验证码发送失败, Result:"+string(result), 2)
- }
- 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{}
-
- param.Set("mobile", mobile)
- param.Set("tplId", "10054")
- param.Set("tplValue", "#code#="+code)
- param.Set("key", utils.JhGjAppKey)
- param.Set("areaNum", areaNum)
- Url, err = url.Parse(apiURL)
- if err != nil {
- fmt.Printf("解析url错误:\r\n%v", err)
- return nil, err
- }
-
- Url.RawQuery = param.Encode()
- resp, err := http.Get(Url.String())
- if err != nil {
- fmt.Println("err:", err)
- return nil, err
- }
- global.LOG.Info("sendSmsGj:param:" + Url.String())
- defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
- global.LOG.Info("sendSmsGj:result:" + string(body))
- return body, err
- }
|