修改企业微信

This commit is contained in:
邹宗楠
2022-06-23 10:35:09 +08:00
parent a4a9309e97
commit 55c810e929
4 changed files with 70 additions and 34 deletions

View File

@@ -10,11 +10,11 @@ import (
"strings"
)
const token = "nn3P9sfkGK5UlHgtNoAqB"
const receiverId = "ww9a156bfa070e1857"
const encodingAeskey = "471RkJkfISWJQUC2f8DSdOgXH0reVCxWCpfaTawSIWA"
const Token = "nn3P9sfkGK5UlHgtNoAqB"
const ReceiverId = "ww9a156bfa070e1857"
const EncodingAeskey = "471RkJkfISWJQUC2f8DSdOgXH0reVCxWCpfaTawSIWA"
func getString(str, endstr string, start int, msg *string) int {
func GetString(str, endstr string, start int, msg *string) int {
end := strings.Index(str, endstr)
*msg = str[start:end]
return end + len(endstr)
@@ -28,20 +28,20 @@ func VerifyURL(w http.ResponseWriter, r *http.Request) {
start += len("msg_signature=")
var msg_signature string
next := getString(httpstr, "&timestamp=", start, &msg_signature)
next := GetString(httpstr, "&timestamp=", start, &msg_signature)
var timestamp string
next = getString(httpstr, "&nonce=", next, &timestamp)
next = GetString(httpstr, "&nonce=", next, &timestamp)
var nonce string
next = getString(httpstr, "&echostr=", next, &nonce)
next = GetString(httpstr, "&echostr=", next, &nonce)
echostr := httpstr[next:len(httpstr)]
echostr, _ = url.QueryUnescape(echostr)
fmt.Println(msg_signature, timestamp, nonce, echostr, next)
wxcpt := NewWXBizMsgCrypt(token, encodingAeskey, receiverId, JsonType)
wxcpt := NewWXBizMsgCrypt(Token, EncodingAeskey, ReceiverId, JsonType)
echoStr, cryptErr := wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr)
if nil != cryptErr {
fmt.Println("verifyUrl fail", cryptErr)
@@ -57,19 +57,19 @@ func MsgHandler(w http.ResponseWriter, r *http.Request) {
start += len("msg_signature=")
var msg_signature string
next := getString(httpstr, "&timestamp=", start, &msg_signature)
next := GetString(httpstr, "&timestamp=", start, &msg_signature)
var timestamp string
next = getString(httpstr, "&nonce=", next, &timestamp)
next = GetString(httpstr, "&nonce=", next, &timestamp)
nonce := httpstr[next:len(httpstr)]
fmt.Println(msg_signature, timestamp, nonce)
body, err := ioutil.ReadAll(r.Body)
fmt.Println(string(body), err)
wxcpt := NewWXBizMsgCrypt(token, encodingAeskey, receiverId, JsonType)
wxcpt := NewWXBizMsgCrypt(Token, EncodingAeskey, ReceiverId, JsonType)
msg, err_ := wxcpt.DecryptMsg(msg_signature, timestamp, nonce, body)
fmt.Println(string(msg), err_)
var msgContent MsgContent
err = json.Unmarshal(msg, &msgContent)

View File

@@ -8,6 +8,7 @@ import (
"encoding/base64"
"encoding/binary"
"encoding/json"
"encoding/xml"
"fmt"
"math/rand"
"sort"
@@ -47,9 +48,9 @@ func NewCryptError(err_code int, err_msg string) *CryptError {
}
type WXBizJsonMsg4Recv struct {
Tousername string `json:"tousername"`
Encrypt string `json:"encrypt"`
Agentid string `json:"agentid"`
Tousername string `xml:"ToUserName"`
Encrypt string `xml:"Encrypt"`
Agentid string `xml:"AgentID"`
}
type WXBizJsonMsg4Send struct {
@@ -80,7 +81,7 @@ type JsonProcessor struct {
func (self *JsonProcessor) parse(src_data []byte) (*WXBizJsonMsg4Recv, *CryptError) {
var msg4_recv WXBizJsonMsg4Recv
err := json.Unmarshal(src_data, &msg4_recv)
err := xml.Unmarshal(src_data, &msg4_recv)
if nil != err {
fmt.Println("Unmarshal fail", err)
return nil, NewCryptError(ParseJsonError, "json to msg fail")