Skip to content

Commit

Permalink
add webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
bozhang75 committed Aug 1, 2022
1 parent 2080aaf commit 29acffd
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* @Time : 2022/7/29 15:02
* @Author : [email protected]
* @File : webhook_upload.go
* @File : qw_webhook_upload.go
* @Software: GoLand
*/

package example

import (
"../wxconf"
"fmt"
"github.com/yijizhichang/wechat-sdk/examples/wxconf"
"io"
"net/http"
"os"
Expand Down
12 changes: 5 additions & 7 deletions examples/example/qy_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import (
"github.com/yijizhichang/wechat-sdk/examples/wxconf"
)

func QyAccessToken() {
token, err := wxconf.QyWechatClint.GetQyAccessToken("VyMmm3hy5n7Q5t23tozkraUtuOt_sdfsadfsfsDCXGEQ")
token2, err2 := wxconf.QyWechatClint.GetQyAccessToken("2rLl96BjFobh7Y_lD6sdfsfdsfsfsfsdjWY3QwIu4")
fmt.Printf("企业微token:",token, err)
fmt.Printf("企业微token2:",token2, err2)

func QyAccessToken() {
token, err := wxconf.QyWechatClient.GetQyAccessToken("VyMmm3hy5n7Q5t23tozkraUtuOt_sdfsadfsfsDCXGEQ")
token2, err2 := wxconf.QyWechatClient.GetQyAccessToken("2rLl96BjFobh7Y_lD6sdfsfdsfsfsfsdjWY3QwIu4")
fmt.Printf("企业微token:", token, err)
fmt.Printf("企业微token2:", token2, err2)

}

34 changes: 15 additions & 19 deletions examples/example/qy_company_department.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,35 @@ import (
"github.com/yijizhichang/wechat-sdk/examples/wxconf"
)

func QyGetDepartment(token string){
func QyGetDepartment(token string) {

department := wxconf.QyWechatClint.GetDepartment()
res, err := department.GetDepartmentList(token,0)
department := wxconf.QyWechatClient.GetDepartment()
res, err := department.GetDepartmentList(token, 0)
if err != nil {
fmt.Printf("QyGetDepartment GetDepartmentList Err: %+v",err)
fmt.Printf("QyGetDepartment GetDepartmentList Err: %+v", err)
}

fmt.Printf("QyGetDepartment GetDepartmentList Res: %+v",res)
fmt.Printf("QyGetDepartment GetDepartmentList Res: %+v", res)
}

func QyGetDepartmentSimpleUserList(token string) {

func QyGetDepartmentSimpleUserList(token string){

departmentUser := wxconf.QyWechatClint.GetDepartmentUser()
res, err := departmentUser.GetDepartmentSimpleUserList(token,5,0)
departmentUser := wxconf.QyWechatClient.GetDepartmentUser()
res, err := departmentUser.GetDepartmentSimpleUserList(token, 5, 0)
if err != nil {
fmt.Printf("QyGetDepartmentSimpleUserList GetDepartmentSimpleUserList Err: %+v",err)
fmt.Printf("QyGetDepartmentSimpleUserList GetDepartmentSimpleUserList Err: %+v", err)
}

fmt.Printf("QyGetDepartmentSimpleUserList GetDepartmentSimpleUserList Res: %+v",res)
fmt.Printf("QyGetDepartmentSimpleUserList GetDepartmentSimpleUserList Res: %+v", res)
}

func QyGetDepartmentUserList(token string){
func QyGetDepartmentUserList(token string) {

departmentUser := wxconf.QyWechatClint.GetDepartmentUser()
res, err := departmentUser.GetDepartmentUserList(token,7,0)
departmentUser := wxconf.QyWechatClient.GetDepartmentUser()
res, err := departmentUser.GetDepartmentUserList(token, 7, 0)
if err != nil {
fmt.Printf("QyGetDepartmentUserList GetDepartmentUserList Err: %+v",err)
fmt.Printf("QyGetDepartmentUserList GetDepartmentUserList Err: %+v", err)
}

fmt.Printf("QyGetDepartmentUserList GetDepartmentUserList Res: %+v",res)
fmt.Printf("QyGetDepartmentUserList GetDepartmentUserList Res: %+v", res)
}



20 changes: 9 additions & 11 deletions examples/example/qy_customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ import (
"github.com/yijizhichang/wechat-sdk/examples/wxconf"
)

func QyGetCustomerList(token string) {
cus := wxconf.QyWechatClint.GetCustomer()
func QyGetCustomerList(token string) {
cus := wxconf.QyWechatClient.GetCustomer()
res, err := cus.GetQyCustomerList(token, "xinyu888")
if err != nil {
fmt.Printf("Err: %+v",err)
fmt.Printf("Err: %+v", err)
}
fmt.Printf("Res: %+v",res)
fmt.Printf("Res: %+v", res)
}

func QyGetCustomerView(token string) {
cus := wxconf.QyWechatClint.GetCustomer()
res, err := cus.GetQyCustomerView(token, "wmt0zCEAAAfyx96crCFRHwLxqtR3_5yA","") //wmt0zCEAAAfyx96crCFRHwLxqtR3_3yA
func QyGetCustomerView(token string) {
cus := wxconf.QyWechatClient.GetCustomer()
res, err := cus.GetQyCustomerView(token, "wmt0zCEAAAfyx96crCFRHwLxqtR3_5yA", "") //wmt0zCEAAAfyx96crCFRHwLxqtR3_3yA
if err != nil {
fmt.Printf("Err: %+v",err)
fmt.Printf("Err: %+v", err)
}
fmt.Printf("Res: %+v",res)
fmt.Printf("Res: %+v", res)
}


47 changes: 21 additions & 26 deletions examples/example/qy_customer_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import (
"github.com/yijizhichang/wechat-sdk/work/customer"
)

func QyGetCustomerTagList(token string){
func QyGetCustomerTagList(token string) {

customerTag := wxconf.QyWechatClint.GetCustomerTag()
res, err := customerTag.GetCustomerTagList(token, customer.CusTagReq{TagId:[]string{}, GroupId: []string{}})
customerTag := wxconf.QyWechatClient.GetCustomerTag()
res, err := customerTag.GetCustomerTagList(token, customer.CusTagReq{TagId: []string{}, GroupId: []string{}})
if err != nil {
fmt.Printf("QyGetCustomerTagList GetCustomerTagList Err: %+v",err)
fmt.Printf("QyGetCustomerTagList GetCustomerTagList Err: %+v", err)
}

fmt.Printf("QyGetCustomerTagList GetCustomerTagList Res: %+v",res)
fmt.Printf("QyGetCustomerTagList GetCustomerTagList Res: %+v", res)
}

func QyCreateCustomerTag(token string){
customerTag := wxconf.QyWechatClint.GetCustomerTag()
func QyCreateCustomerTag(token string) {
customerTag := wxconf.QyWechatClient.GetCustomerTag()
req := new(customer.CreateCusTagReq)
req.GroupName = "技术Mark"
addTag1 := customer.AddTag{
Expand All @@ -39,56 +39,51 @@ func QyCreateCustomerTag(token string){
req.Tag = append(req.Tag, addTag1, addTag2)
res, err := customerTag.CreateCustomerTag(token, *req)
if err != nil {
fmt.Printf("QyCreateCustomerTag CreateCustomerTag Err: %+v",err)
fmt.Printf("QyCreateCustomerTag CreateCustomerTag Err: %+v", err)
}

fmt.Printf("QyCreateCustomerTag CreateCustomerTag Res: %+v",res)
fmt.Printf("QyCreateCustomerTag CreateCustomerTag Res: %+v", res)
}

func QyUpdateCustomerTag(token string){
customerTag := wxconf.QyWechatClint.GetCustomerTag()
func QyUpdateCustomerTag(token string) {
customerTag := wxconf.QyWechatClient.GetCustomerTag()
req := new(customer.UpdateCusTagReq)
req.Id = "ett0zCEAAAqlT6DRVQUh6CJnUhD2mZTA"
req.Name = "m3"
req.Order = 5


res, err := customerTag.UpdateCustomerTag(token, *req)
if err != nil {
fmt.Printf("QyUpdateCustomerTag UpdateCustomerTag Err: %+v",err)
fmt.Printf("QyUpdateCustomerTag UpdateCustomerTag Err: %+v", err)
}

fmt.Printf("QyUpdateCustomerTag UpdateCustomerTag Res: %+v",res)
fmt.Printf("QyUpdateCustomerTag UpdateCustomerTag Res: %+v", res)
}

func QyDelCustomerTag(token string){
customerTag := wxconf.QyWechatClint.GetCustomerTag()
func QyDelCustomerTag(token string) {
customerTag := wxconf.QyWechatClient.GetCustomerTag()
req := new(customer.DelCusTagReq)
req.TagId = []string{"ett0zCEAAAqlT6DRVQUh6CJnUhD2mZTA"}


res, err := customerTag.DelCustomerTag(token, *req)
if err != nil {
fmt.Printf("QyDelCustomerTag DelCustomerTag Err: %+v",err)
fmt.Printf("QyDelCustomerTag DelCustomerTag Err: %+v", err)
}

fmt.Printf("QyDelCustomerTag DelCustomerTag Res: %+v",res)
fmt.Printf("QyDelCustomerTag DelCustomerTag Res: %+v", res)
}

func QyMarkTag(token string){
customerTag := wxconf.QyWechatClint.GetCustomerTag()
func QyMarkTag(token string) {
customerTag := wxconf.QyWechatClient.GetCustomerTag()
req := new(customer.MarkTagReq)
req.Userid = "xinyu8521"
req.ExternalUserid = "wmt0zCEAAAfyx96crCFRHwLxqtR3_3yA"
req.AddTag = []string{"ett0zCEAAAw3i1L_kh9gQIIc6A-XZ6tQ"}


res, err := customerTag.MarkCustomerTag(token, *req)
if err != nil {
fmt.Printf("QyMarkTag MarkCustomerTag Err: %+v",err)
fmt.Printf("QyMarkTag MarkCustomerTag Err: %+v", err)
}

fmt.Printf("QyMarkTag MarkCustomerTag Res: %+v",res)
fmt.Printf("QyMarkTag MarkCustomerTag Res: %+v", res)
}


16 changes: 7 additions & 9 deletions examples/example/qy_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func QyServe(rw http.ResponseWriter, req *http.Request) {
fmt.Println("QyServe 1111")
// 传入request和responseWriter
server := wxconf.QyWechatClint.GetQyServer(req, rw)
server := wxconf.QyWechatClient.GetQyServer(req, rw)
fmt.Println("QyServe 2222")
//设置接收消息的处理方法
server.SetMessageHandler(func(msg message.MixMessage) *response.Reply {
Expand All @@ -33,8 +33,8 @@ func QyServe(rw http.ResponseWriter, req *http.Request) {

fmt.Println("QyServe 3333")
fmt.Println("msg %+v", msg)
msgJson,_ := json.Marshal(msg)
fmt.Println("msgJson",string(msgJson))
msgJson, _ := json.Marshal(msg)
fmt.Println("msgJson", string(msgJson))

//根据微信回调时的消息类型,来相应获取对应消息明细
switch msg.MsgCommon.MsgType {
Expand Down Expand Up @@ -93,7 +93,7 @@ func QyServe(rw http.ResponseWriter, req *http.Request) {
fmt.Println("图文消息:", reStr)
msgType = message.MsgTypeNews
default:
reStr =""
reStr = ""
msgType = message.MsgTypeNothing
}

Expand All @@ -116,12 +116,11 @@ func QyServe(rw http.ResponseWriter, req *http.Request) {
server.Send()
}


//与微信交互服务地址,sdk包返回需要给微信的内容,由应用发送给微信
func QyResponseServe(rw http.ResponseWriter, req *http.Request) {

// 传入request和responseWriter
server := wxconf.QyWechatClint.GetQyResponseServer(req)
server := wxconf.QyWechatClient.GetQyResponseServer(req)
//设置接收消息的处理方法
server.SetMessageHandler(func(msg message.MixMessage) *response.Reply {
var reStr interface{}
Expand Down Expand Up @@ -211,7 +210,7 @@ func QyResponseServe(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(200)
//rw.Header().Set("Content-Type",contentType)
rw.Write([]byte(str))
fmt.Println("echostrExist is true",str,contentType)
fmt.Println("echostrExist is true", str, contentType)
return
}
//发送回复的消息
Expand All @@ -221,6 +220,5 @@ func QyResponseServe(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(200)
rw.Write([]byte(str2))

fmt.Println("send to wx",str2,contentType2)
fmt.Println("send to wx", str2, contentType2)
}

28 changes: 18 additions & 10 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,29 @@ import (
"github.com/yijizhichang/wechat-sdk/examples/cache"
"github.com/yijizhichang/wechat-sdk/examples/example"
"github.com/yijizhichang/wechat-sdk/examples/wxconf"
wxCache "github.com/yijizhichang/wechat-sdk/util/cache"
"net/http"
)

// 测试参数
// go run example.go -appid='your appdi' -appsecret='your appsecret' -token='your token' -port='80'
/* 测试公众号时打开对应参数
var appid = flag.String("appid", "your AppID", "appid")
var appsecret = flag.String("appsecret", "your AppSecret", "appsecret")
var token = flag.String("token", "your Token", "token")
var aeskey = flag.String("asekey", "your EncodingAesKey", "asekey")
var port = flag.String("port", "80", "port")
*/

//qw
//qw 测试企微时,打开对应参数
// go run main.go -cropid='your cropid' -token='your token' -aeskey='your aeskey' -cropsecret='your cropsecret' -rpkey='your rpkey' -port='80'
// go run main.go -cropid='111' -cropsecret='222' -rpkey='333'
var cropid = flag.String("cropid", "your CorpID", "cropid")
var cropsecret = flag.String("cropsecret", "your CorpSecret", "cropsecret")
var rpkey = flag.String("rpkey", "your RasPrivateKey", "rpkey")
var port = flag.String("port", "9999", "port")

// 参数配置
/*
func getWxConfig(cacheModel wxCache.Cache) *wechat.Config {
config := &wechat.Config{
AppID: *appid, // 开发者ID(AppID)
Expand All @@ -43,13 +46,15 @@ func getWxConfig(cacheModel wxCache.Cache) *wechat.Config {
return config
}
*/

func getQyWechatConfig(fileCache cache.FileClient) *wechat.QyConfig {
config := &wechat.QyConfig{
CorpID: *cropid, // 企业ID
CorpSecret: *cropsecret, // 应用的凭证密钥; 每个应用有独立的secret,获取到的access_token只能本应用使用,所以每个应用的access_token应该分开来获取
RasPrivateKey: *rpkey, // 消息加密私钥
Token: *token, // 令牌(Token)
EncodingAESKey: *aeskey, // 消息加解密密钥 EncodingAESKey
Token: "", //*token, // 令牌(Token)
EncodingAESKey: "", //*aeskey, // 消息加解密密钥 EncodingAESKey
ThirdAccessToken: false, //是用其他应用生成的access_token
Cache: fileCache, //缓存
ProxyUrl: "", //代理地址
Expand Down Expand Up @@ -119,16 +124,19 @@ func main() {
}
fileCache := cache.NewFileClient(file)
wxconf.QyWechatClient = wechat.NewQyWechat(getQyWechatConfig(fileCache))
fmt.Printf("qy param:", *cropid, *token, *aeskey, *cropsecret, *rpkey)
//fmt.Printf("qy param:", *cropid, *token, *aeskey, *cropsecret, *rpkey)

//测试
//example.QyAccessToken() //获取企业access_token

token, err := wxconf.QyWechatClient.GetQyAccessToken(*cropsecret)
if err != nil {
fmt.Printf("GetQyAccessToken Err: %+v", err)
}
fmt.Println("token=%s", token)
/*
token, err := wxconf.QyWechatClient.GetQyAccessToken(*cropsecret)
if err != nil {
fmt.Printf("GetQyAccessToken Err: %+v", err)
}
fmt.Println("token=%s", token)
*/
//example.QyGetCustomerTagList(token) //获取企业标签库
//example.QyCreateCustomerTag(token) //创建企业标签
//example.QyUpdateCustomerTag(token) //修改企业标签
Expand Down
Loading

0 comments on commit 29acffd

Please sign in to comment.