diff --git a/baishiy.go b/baishiy.go new file mode 100644 index 0000000..7fcd3aa --- /dev/null +++ b/baishiy.go @@ -0,0 +1,56 @@ +package sms + +import ( + "log" + + "git.tetele.net/tgo/helper" +) + +/* +* + + - 百世云发送短信 + * + + - @param string $sp_id sp_id + - @param string $password 密码 + - @param string $mobile 手机号码 + + - @param string $content 短信内容 + + - @param string $sms_sign 短信签名 + + - @return success bool, reply map[string]string, err error +*/ + +func SendByBaishiy(sp_id, password, mobile, sms_sign, content string) (bool, map[string]interface{}, error) { + + url := "http://124.220.34.130:9511/api/send-sms-single" + //创蓝接口参数 + data := map[string]string{ + "sp_id": sp_id, + "password": password, + "content": StringJoin("【", sms_sign, "】", content), + "mobile": mobile, + } + response, err := SendHttp("POST", url, data) + + if err != nil { + return false, nil, err + } + + var reply map[string]interface{} + + err = json.Unmarshal(response, &reply) + + if err != nil { + log.Println(string(response), err) + return false, nil, err + } + + if helper.ToStr(reply["code"]) != "0" { + return false, reply, nil + } + + return true, reply, err +} diff --git a/baishiy_test.go b/baishiy_test.go new file mode 100644 index 0000000..cd7fb26 --- /dev/null +++ b/baishiy_test.go @@ -0,0 +1,14 @@ +package sms + +import ( + "testing" +) + +func Test_SendByBaishiy(t *testing.T) { + msg := "罗您好,您的商店新增2单物理灭蚊仪-天眼款,请及时登录商家后台处理!" + ret, reply, err := SendByBaishiy("991422", "f3012ddbaa069ba58dd94ec28e35f214", "13631270978", "园圈", msg) + + t.Log(ret) + t.Log(reply) + t.Log(err) +} diff --git a/chuanglan_test.go b/chuanglan_test.go index a641c51..337c766 100644 --- a/chuanglan_test.go +++ b/chuanglan_test.go @@ -6,7 +6,8 @@ import ( func Test_SendByCL(t *testing.T) { msg := "罗您好,您的商店新增2单物理灭蚊仪-天眼款,请及时登录商家后台处理!" - ret, reply, err := SendByCL("", "", "18607565510", "平沙数字云店", msg) + //ret, reply, err := SendByCL("", "", "13631270978", "平沙数字云店", msg) + ret, reply, err := SendByCL("", "", "13631270978", "园圈", msg) t.Log(ret) t.Log(reply) diff --git a/common.go b/common.go index cc7677d..9baba85 100644 --- a/common.go +++ b/common.go @@ -82,3 +82,47 @@ func PostJsonData(url string, param interface{}, header ...map[string]string) ([ return body, nil } + +/** + * 自定义HTTP请求 + */ +func SendHttp(method, url string, param map[string]string, header ...map[string]string) ([]byte, error) { + httpClient := &http.Client{} + + paramStr := "" + if len(param) > 0 { + for key, value := range param { + paramStr += key + "=" + value + "&" + } + + paramStr = paramStr[0 : len(paramStr)-1] + } + + req, err := http.NewRequest(method, url, strings.NewReader(paramStr)) + if err != nil { + return []byte(""), err + } + + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + + if len(header) > 0 { + for _, item := range header { + for k, v := range item { + req.Header.Set(k, v) + } + } + } + + resp, err := httpClient.Do(req) + if err != nil { + return []byte(""), err + } + + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return []byte(""), err + } + + return body, nil +}