-
-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6914575
commit 82068de
Showing
6 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package channel | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"message-pusher/model" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func SendCustomMessage(message *model.Message, user *model.User, channel_ *model.Channel) error { | ||
url := channel_.URL | ||
if strings.HasPrefix(url, "http:") { | ||
return errors.New("自定义通道必须使用 HTTPS 协议") | ||
} | ||
template := channel_.Other | ||
template = strings.Replace(template, "$url", message.URL, -1) | ||
template = strings.Replace(template, "$to", message.To, -1) | ||
template = strings.Replace(template, "$title", message.Title, -1) | ||
template = strings.Replace(template, "$description", message.Description, -1) | ||
template = strings.Replace(template, "$content", message.Content, -1) | ||
reqBody := []byte(template) | ||
resp, err := http.Post(url, "application/json", bytes.NewReader(reqBody)) | ||
if err != nil { | ||
return err | ||
} | ||
if resp.StatusCode != 200 { | ||
return errors.New(resp.Status) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters