Parcourir la source

短信api

master
huangjiajun il y a 1 an
Parent
révision
c389cce6d9
2 fichiers modifiés avec 11 ajouts et 12 suppressions
  1. +1
    -1
      db/offical/db_sms_num_list.go
  2. +10
    -11
      sms/api.go

+ 1
- 1
db/offical/db_sms_num_list.go Voir le fichier

@@ -5,7 +5,7 @@ import (
"xorm.io/xorm"
)

func GetSmsNum(engine *xorm.Engine, smsType string, uid string) *model.SmsNumList {
func GetSmsNum(engine *xorm.Engine, smsType, uid interface{}) *model.SmsNumList {
var data model.SmsNumList
get, err := engine.Where("uid=? and type=?", uid, smsType).Get(&data)
if get == false || err != nil {


+ 10
- 11
sms/api.go Voir le fichier

@@ -15,7 +15,7 @@ import (
)

//短信数量
func SmsNumGetSmsNum(engine *xorm.Engine, smsType, uid string) int {
func SmsNumGetSmsNum(engine *xorm.Engine, smsType, uid interface{}) int {
numData := offical.GetSmsNum(engine, smsType, uid)
num := 0
if numData != nil {
@@ -28,14 +28,14 @@ func SmsNumGetSmsNum(engine *xorm.Engine, smsType, uid string) int {
}

//发送短信
func SmsSend(engine *xorm.Engine, args map[string]string) error {
func SmsSend(engine *xorm.Engine, args map[string]interface{}) error {
num := SmsNumGetSmsNum(engine, args["sms_type"], args["uid"])
ex := strings.Split(args["mobile"], ",")
ex := strings.Split(args["mobile"].(string), ",")
if len(ex) == 0 {
return errors.New("请输入手机号")
}
count := len(ex)
contentLen := php2go.Ceil(float64(len(args["content"])) / 4 / 70)
contentLen := php2go.Ceil(float64(len(args["content"].(string))) / 4 / 70)
if args["type"] == "mob" {
contentLen = 1
}
@@ -52,7 +52,7 @@ func SmsSend(engine *xorm.Engine, args map[string]string) error {
return errors.New("平台短信不足")
}
}
where := make(map[string]string)
where := make(map[string]interface{})
param := []string{
"content", //短信内容
"mobile", //号码多个以英文”,”号分割,最大 2000 个
@@ -61,13 +61,13 @@ func SmsSend(engine *xorm.Engine, args map[string]string) error {
}
for _, v := range param {
if args[v] != "" {
where[v] = args[v]
where[v] = args[v].(string)
}
}
send := ""
var err error
if args["type"] == "mob" { //mob
where = map[string]string{
where = map[string]interface{}{
"appkey": args["smsmsg_key"],
"zone": args["zone"],
"phone": args["phone"],
@@ -105,7 +105,7 @@ func SmsSend(engine *xorm.Engine, args map[string]string) error {
}
var record = model.SmsRecord{
OrdId: "",
Uid: zhios_third_party_utils.StrToInt(args["uid"]),
Uid: int(zhios_third_party_utils.AnyToInt64(args["uid"])),
Amount: zhios_third_party_utils.IntToStr(count * int(contentLen)),
CostPrice: "",
Balance: zhios_third_party_utils.IntToStr(num - count*int(contentLen)),
@@ -117,10 +117,9 @@ func SmsSend(engine *xorm.Engine, args map[string]string) error {
TradeNo: "",
Type: 1,
OrdType: "buy",
SubUid: zhios_third_party_utils.StrToInt(args["sub_uid"]),
Fee: "",
Ext: zhios_third_party_utils.SerializeStr(ext),
SmsType: args["sms_type"],
SmsType: args["sms_type"].(string),
}
engine.InsertOne(&record)
sql := `UPDATE sms_num_list set num=num-%d WHERE uid=%s and type=%s;`
@@ -153,7 +152,7 @@ func SmsApiSend(engine *xorm.Engine, method string, args map[string]string) (str
fmt.Println(err)
return string(post), err
}
func SmsMobApiSend(args map[string]string) (string, error) {
func SmsMobApiSend(args map[string]interface{}) (string, error) {
thisUrl := "https://webapi.sms.mob.com/sms/sendmsg"
post, err := zhios_third_party_utils.CurlPost(thisUrl, zhios_third_party_utils.SerializeStr(args), nil)
fmt.Println(string(post))


Chargement…
Annuler
Enregistrer