微信接口的RPC包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

77 lines
1.2 KiB

package weixinrpc
import (
"encoding/json"
"log"
"strconv"
"time"
"git.tetele.net/tgo/crypter"
"github.com/golang/protobuf/proto"
)
func GetMpUserInfo(accessToken,openId string,url ...string) (*MpUserInfoRes, error) {
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
data := MpUserInfoReq{}
data.AccessToken = accessToken
data.Openid = openId
data_json, err := json.Marshal(data)
if err != nil {
return nil, err
}
encryData := crypter.DesEn(string(data_json), DES_KEY)
now_int64 := time.Now().Unix()
now := strconv.FormatInt(now_int64, 10)
sign := Sign(encryData, now)
req := &Request{
proto.String(encryData),
proto.String(now),
proto.String(sign),
nil}
res := &Response{}
err = conn.GetMpUserInfo(req, res)
if err != nil {
return nil, err
}
return HandleMpUserInfo(res)
}
/**
* 处理返回结果
*/
func HandleMpUserInfo(res *Response) (*MpUserInfoRes, error) {
//解密
res_data_de, err := GetOrgData(res)
if err != nil {
return nil, err
}
var res_arr MpUserInfoRes
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
log.Println(err, res_data_de)
return nil, err
}
return &res_arr, nil
}