Browse Source

百世云短信

master v1.1.2
loshiqi 4 months ago
parent
commit
3fcf8d8aa0
4 changed files with 116 additions and 1 deletions
  1. +56
    -0
      baishiy.go
  2. +14
    -0
      baishiy_test.go
  3. +2
    -1
      chuanglan_test.go
  4. +44
    -0
      common.go

+ 56
- 0
baishiy.go View File

@ -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
}

+ 14
- 0
baishiy_test.go View File

@ -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)
}

+ 2
- 1
chuanglan_test.go View File

@ -6,7 +6,8 @@ import (
func Test_SendByCL(t *testing.T) { func Test_SendByCL(t *testing.T) {
msg := "罗您好,您的商店新增2单物理灭蚊仪-天眼款,请及时登录商家后台处理!" 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(ret)
t.Log(reply) t.Log(reply)


+ 44
- 0
common.go View File

@ -82,3 +82,47 @@ func PostJsonData(url string, param interface{}, header ...map[string]string) ([
return body, nil 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
}

Loading…
Cancel
Save