Skip to content

Commit

Permalink
Merge branch 'work' into simple
Browse files Browse the repository at this point in the history
  • Loading branch information
bozhang75 committed Aug 1, 2022
2 parents d2d7a5f + 29acffd commit ea072ea
Show file tree
Hide file tree
Showing 11 changed files with 540 additions and 108 deletions.
62 changes: 62 additions & 0 deletions examples/example/qw_webhook_upload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @Time : 2022/7/29 15:02
* @Author : [email protected]
* @File : qw_webhook_upload.go
* @Software: GoLand
*/

package example

import (
"fmt"
"github.com/yijizhichang/wechat-sdk/examples/wxconf"
"io"
"net/http"
"os"
)

//上传临时素材
func WebhookUpload(rw http.ResponseWriter, req *http.Request) {
//从请求当中判断方法
if req.Method == "GET" {
io.WriteString(rw, "<html><head><title>上传</title></head>"+
"<body><form action='#' method=\"post\" enctype=\"multipart/form-data\">"+
"<label>上传类型</label>"+":"+
"<select name='type'><option value ='image'>图片</option><option value ='voice'>语音</option><option value ='video'>视频</option><option value ='thumb'>缩略图</option></select>"+
"<input type=\"file\" name='file' /><br/><br/> "+
"<label><input type=\"submit\" value=\"上传图片\"/></label></form></body></html>")
} else {
//获取文件内容 要这样获取
file, head, err := req.FormFile("file")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()

upType := req.FormValue("type")
fmt.Println("上传类型:", upType)

//创建文件
fW, err := os.Create("/tmp/upload/" + head.Filename)
if err != nil {
fmt.Println("文件创建失败")
return
}
defer fW.Close()
_, err = io.Copy(fW, file)
if err != nil {
fmt.Println("文件保存失败")
return
}

key := "9691a6f0-701f-425c-9ff2-fd7187b6f108"
//webhook 上传管理
webhookClient := wxconf.QyWechatClient.GetWebhook()
re, err := webhookClient.UploadQyTempMedia(key, "file", "/tmp/upload/"+head.Filename)

fmt.Println("上传webhook文件:", re, "err:", err)

}

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

Loading

0 comments on commit ea072ea

Please sign in to comment.