修改企业微信
This commit is contained in:
@@ -2,12 +2,9 @@ package enterprise_wechat
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 回调参数
|
// 回调参数(推送SuiteTicket)
|
||||||
type SuiteTicketInfo struct {
|
type SuiteTicketInfo struct {
|
||||||
SuiteId string `xml:"SuiteId"` // 第三方应用的SuiteId
|
SuiteId string `xml:"SuiteId"` // 第三方应用的SuiteId
|
||||||
InfoType string `xml:"InfoType"` // suite_ticket
|
InfoType string `xml:"InfoType"` // suite_ticket
|
||||||
@@ -15,18 +12,28 @@ type SuiteTicketInfo struct {
|
|||||||
SuiteTicket string `xml:"SuiteTicket"` // Ticket内容,最长为512字节
|
SuiteTicket string `xml:"SuiteTicket"` // Ticket内容,最长为512字节
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) GetEnterpriseMsg(request *http.Request) (*SuiteTicketInfo, error) {
|
// 回调参数(解密推送消息Encrypt =》 SuiteTicketInfo 转化为上面的推送信息)
|
||||||
data, err := ioutil.ReadAll(request.Body)
|
type SuiteEncrypt struct {
|
||||||
if err != nil {
|
ToUserName string `xml:"ToUserName"` // 企业微信的CorpID,当为第三方套件回调事件时,CorpID的内容为suiteid
|
||||||
return nil, err
|
AgentID string `xml:"AgentID"` // 接收的应用id,可在应用的设置页面获取
|
||||||
}
|
Encrypt string `xml:"Encrypt"` // 消息结构体加密后的字符串
|
||||||
globals.SugarLogger.Debug("data============enterprise", data)
|
}
|
||||||
globals.SugarLogger.Debug("data============enterprise", string(data))
|
|
||||||
|
// 解密加密推送信息
|
||||||
suite := &SuiteTicketInfo{}
|
func (a *API) GetEnterpriseSend(request []byte) (*SuiteEncrypt, error) {
|
||||||
if err := xml.Unmarshal(data, suite); err != nil {
|
encrypt := &SuiteEncrypt{}
|
||||||
return nil, err
|
if err := xml.Unmarshal(request, encrypt); err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
return suite, err
|
|
||||||
|
return encrypt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) GetEnterpriseMsg(param []byte) (*SuiteTicketInfo, error) {
|
||||||
|
suite := &SuiteTicketInfo{}
|
||||||
|
if err := xml.Unmarshal(param, suite); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return suite, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -469,6 +469,34 @@ func (a *API) OrderJDZBDelivery(orderId string, userName string) (detail string,
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 订单拣货完成且商家自送
|
||||||
|
// https://openapi.jddj.com/djapi/bm/open/api/order/OrderSerllerDelivery
|
||||||
|
func (a *API) OrderJDZBStoreDelivery(orderId string, userName string) (detail string, err error) {
|
||||||
|
jdParams := map[string]interface{}{
|
||||||
|
"orderId": orderId,
|
||||||
|
"operator": utils.GetAPIOperator(userName),
|
||||||
|
}
|
||||||
|
result, err := a.AccessAPINoPage("bm/open/api/order/OrderSerllerDelivery", jdParams, nil, nil, orderOperationResultParser)
|
||||||
|
if err == nil {
|
||||||
|
return utils.Interface2String(result), nil
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 订单拣货完成且顾客自提
|
||||||
|
// https://openapi.jddj.com/djapi/bm/open/api/order/OrderSelfMention
|
||||||
|
func (a *API) OrderJDZBSelfDelivery(orderId string, userName string) (detail string, err error) {
|
||||||
|
jdParams := map[string]interface{}{
|
||||||
|
"orderId": orderId,
|
||||||
|
"operator": utils.GetAPIOperator(userName),
|
||||||
|
}
|
||||||
|
result, err := a.AccessAPINoPage("bm/open/api/order/OrderSelfMention", jdParams, nil, nil, orderOperationResultParser)
|
||||||
|
if err == nil {
|
||||||
|
return utils.Interface2String(result), nil
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
// 订单达达配送转商家自送接口
|
// 订单达达配送转商家自送接口
|
||||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=e7b4950164754eecac7ea87278c2b071
|
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=e7b4950164754eecac7ea87278c2b071
|
||||||
func (a *API) ModifySellerDelivery(orderId string, userName string) (detail string, err error) {
|
func (a *API) ModifySellerDelivery(orderId string, userName string) (detail string, err error) {
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const token = "nn3P9sfkGK5UlHgtNoAqB"
|
const Token = "nn3P9sfkGK5UlHgtNoAqB"
|
||||||
const receiverId = "ww9a156bfa070e1857"
|
const ReceiverId = "ww9a156bfa070e1857"
|
||||||
const encodingAeskey = "471RkJkfISWJQUC2f8DSdOgXH0reVCxWCpfaTawSIWA"
|
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)
|
end := strings.Index(str, endstr)
|
||||||
*msg = str[start:end]
|
*msg = str[start:end]
|
||||||
return end + len(endstr)
|
return end + len(endstr)
|
||||||
@@ -28,20 +28,20 @@ func VerifyURL(w http.ResponseWriter, r *http.Request) {
|
|||||||
start += len("msg_signature=")
|
start += len("msg_signature=")
|
||||||
|
|
||||||
var msg_signature string
|
var msg_signature string
|
||||||
next := getString(httpstr, "×tamp=", start, &msg_signature)
|
next := GetString(httpstr, "×tamp=", start, &msg_signature)
|
||||||
|
|
||||||
var timestamp string
|
var timestamp string
|
||||||
next = getString(httpstr, "&nonce=", next, ×tamp)
|
next = GetString(httpstr, "&nonce=", next, ×tamp)
|
||||||
|
|
||||||
var nonce string
|
var nonce string
|
||||||
next = getString(httpstr, "&echostr=", next, &nonce)
|
next = GetString(httpstr, "&echostr=", next, &nonce)
|
||||||
|
|
||||||
echostr := httpstr[next:len(httpstr)]
|
echostr := httpstr[next:len(httpstr)]
|
||||||
|
|
||||||
echostr, _ = url.QueryUnescape(echostr)
|
echostr, _ = url.QueryUnescape(echostr)
|
||||||
fmt.Println(msg_signature, timestamp, nonce, echostr, next)
|
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)
|
echoStr, cryptErr := wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr)
|
||||||
if nil != cryptErr {
|
if nil != cryptErr {
|
||||||
fmt.Println("verifyUrl fail", cryptErr)
|
fmt.Println("verifyUrl fail", cryptErr)
|
||||||
@@ -57,19 +57,19 @@ func MsgHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
start += len("msg_signature=")
|
start += len("msg_signature=")
|
||||||
|
|
||||||
var msg_signature string
|
var msg_signature string
|
||||||
next := getString(httpstr, "×tamp=", start, &msg_signature)
|
next := GetString(httpstr, "×tamp=", start, &msg_signature)
|
||||||
|
|
||||||
var timestamp string
|
var timestamp string
|
||||||
next = getString(httpstr, "&nonce=", next, ×tamp)
|
next = GetString(httpstr, "&nonce=", next, ×tamp)
|
||||||
|
|
||||||
nonce := httpstr[next:len(httpstr)]
|
nonce := httpstr[next:len(httpstr)]
|
||||||
fmt.Println(msg_signature, timestamp, nonce)
|
fmt.Println(msg_signature, timestamp, nonce)
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
fmt.Println(string(body), err)
|
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)
|
msg, err_ := wxcpt.DecryptMsg(msg_signature, timestamp, nonce, body)
|
||||||
|
|
||||||
fmt.Println(string(msg), err_)
|
fmt.Println(string(msg), err_)
|
||||||
var msgContent MsgContent
|
var msgContent MsgContent
|
||||||
err = json.Unmarshal(msg, &msgContent)
|
err = json.Unmarshal(msg, &msgContent)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -47,9 +48,9 @@ func NewCryptError(err_code int, err_msg string) *CryptError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WXBizJsonMsg4Recv struct {
|
type WXBizJsonMsg4Recv struct {
|
||||||
Tousername string `json:"tousername"`
|
Tousername string `xml:"ToUserName"`
|
||||||
Encrypt string `json:"encrypt"`
|
Encrypt string `xml:"Encrypt"`
|
||||||
Agentid string `json:"agentid"`
|
Agentid string `xml:"AgentID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WXBizJsonMsg4Send struct {
|
type WXBizJsonMsg4Send struct {
|
||||||
@@ -80,7 +81,7 @@ type JsonProcessor struct {
|
|||||||
|
|
||||||
func (self *JsonProcessor) parse(src_data []byte) (*WXBizJsonMsg4Recv, *CryptError) {
|
func (self *JsonProcessor) parse(src_data []byte) (*WXBizJsonMsg4Recv, *CryptError) {
|
||||||
var msg4_recv WXBizJsonMsg4Recv
|
var msg4_recv WXBizJsonMsg4Recv
|
||||||
err := json.Unmarshal(src_data, &msg4_recv)
|
err := xml.Unmarshal(src_data, &msg4_recv)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
fmt.Println("Unmarshal fail", err)
|
fmt.Println("Unmarshal fail", err)
|
||||||
return nil, NewCryptError(ParseJsonError, "json to msg fail")
|
return nil, NewCryptError(ParseJsonError, "json to msg fail")
|
||||||
|
|||||||
Reference in New Issue
Block a user