| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 | 
							- package util
 
- import (
 
- 	"fmt"
 
- 	"github.com/fastwego/offiaccount"
 
- 	"github.com/fastwego/offiaccount/apis/menu"
 
- 	"os"
 
- 	"strings"
 
- )
 
- // 微信公众账号
 
- var OffiAccount *offiaccount.OffiAccount
 
- func init() {
 
- 	// 加载配置文件
 
- 	// 创建公众号实例
 
- 	OffiAccount = offiaccount.New(offiaccount.Config{
 
- 		Appid:          "wxe1cc563ba393dd1a",
 
- 		Secret:         "25e56243da9581eab6f4d67a12ef4658",
 
- 		//Token:          viper.GetString("TOKEN"),
 
- 		//EncodingAESKey: viper.GetString("EncodingAESKey"),
 
- 	})
 
- }
 
- func Send_Message2(access_token, msg string) {
 
- 	app := offiaccount.New(offiaccount.Config{
 
- 		Appid:  "APPID",
 
- 		Secret: "SECRET",
 
- 	})
 
- 	// 调用 api
 
- 	payload := []byte(`
 
- {
 
-      "button":[
 
-      {
 
-            "name":"菜单",
 
-            "sub_button":[
 
-            {	
 
-                "type":"view",
 
-                "name":"搜索",
 
-                "url":"http://www.baidu.com/"
 
-             }]
 
-        }]
 
- }`)
 
- 	resp, err := menu.Create(app, payload)
 
- 	fmt.Println(resp, err)
 
- }
 
- func messages1(touser string, toparty string, agentid int, content string) string {
 
- 	msg := MESSAGES{
 
- 		Touser:  touser,
 
- 		Toparty: toparty,
 
- 		Msgtype: "text",
 
- 		Agentid: agentid,
 
- 		Safe:    0,
 
- 		Text: struct {
 
- 			//Subject string `json:"subject"`
 
- 			Content string `json:"content"`
 
- 		}{Content: content},
 
- 	}
 
- 	sed_msg, _ := json.Marshal(msg)
 
- 	//fmt.Printf("%s",string(sed_msg))
 
- 	return string(sed_msg)
 
- }
 
- func main() {
 
- 	touser := "BigBoss"                            //企业号中的用户帐号,在zabbix用户Media中配置,如果配置不正常,将按部门发送。
 
- 	toparty := "2"                                 //企业号中的部门id。
 
- 	agentid := 1000002                             //企业号中的应用id。
 
- 	corpid := "xxxxxxxxxxxxxxxxx"                  //企业号的标识
 
- 	corpsecret := "exxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ///企业号中的应用的Secret
 
- 	accessToken := Get_AccessToken(corpid, corpsecret)
 
- 	content := os.Args[1]
 
- 	//  fmt.Println(content)
 
- 	// 序列化成json之后,\n会被转义,也就是变成了\\n,使用str替换,替换掉转义
 
- 	msg := strings.Replace(messages(touser, toparty, agentid, content), "\\\\", "\\", -1)
 
- 	//  fmt.Println(strings.Replace(msg,"\\\\","\\",-1))
 
- 	Send_Message(accessToken, msg)
 
- }
 
 
  |