Browse Source

增加短信调用方法

master v0.1.0
guzeng 3 years ago
parent
commit
81c36fb21a
2 changed files with 72 additions and 0 deletions
  1. +54
    -0
      wo.client.go
  2. +18
    -0
      wo.client_test.go

+ 54
- 0
wo.client.go View File

@ -0,0 +1,54 @@
package smsrpc
import (
"encoding/json"
"errors"
"log"
)
func SendWoSms(cpcode, key string, msg, mobiles string, excode, templetId string, url ...string) (map[string]interface{}, error) {
if cpcode == "" || key == "" {
return nil, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
arg := WoParam{cpcode, msg, mobiles, excode, templetId, key}
req, err := SetReqData(arg)
if err != nil {
return nil, err
}
res := &Response{}
err = conn.SendWoMsg(req, res)
if err != nil {
return nil, err
}
res_data_de, err := GetResData(res)
log.Println(res_data_de, err)
if err != nil {
return nil, err
}
if res_data_de == "" {
return nil, nil
}
var res_arr map[string]interface{}
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
return nil, err
}
return res_arr, nil
}

+ 18
- 0
wo.client_test.go View File

@ -0,0 +1,18 @@
package smsrpc
import (
"testing"
)
func Test_SendWoSms(t *testing.T) {
cpcode := "AACDUZ"
key := "c1a4245d51ad7315e7c1bb5d80eb98b0"
excode := "750058"
msg := "345678"
mobiles := "18607565510"
templetId := "290901"
ret, err := SendWoSms(cpcode, key, msg, mobiles, excode, templetId)
t.Log(ret)
t.Log(err)
}

Loading…
Cancel
Save