修改企业微信

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)