package weixinrpc
|
|
|
|
import (
|
|
"git.tetele.net/tgo/conf"
|
|
)
|
|
|
|
const DES_KEY = "wxserrpc"
|
|
|
|
type WxApiRes struct {
|
|
Errcode int
|
|
Errmsg string
|
|
}
|
|
|
|
type Req struct {
|
|
SiteId string
|
|
Dbname string
|
|
}
|
|
|
|
type AccessTokenReq struct {
|
|
Req
|
|
Appid string
|
|
Secret string
|
|
}
|
|
|
|
type AccessTokenRes struct {
|
|
AccessToken string
|
|
}
|
|
|
|
type UniformMessageReq struct {
|
|
Req
|
|
Appid string
|
|
Secret string
|
|
Touser string
|
|
MpAppid string
|
|
TemplateId string
|
|
Url string
|
|
MiniProgram interface{}
|
|
Data interface{}
|
|
}
|
|
|
|
type SubscribeMessageReq struct {
|
|
Req
|
|
Appid string
|
|
Secret string
|
|
Touser string
|
|
TemplateId string
|
|
Page string
|
|
MiniprogramState string
|
|
Lang string
|
|
Data interface{}
|
|
}
|
|
|
|
/**
|
|
* 获取小程序openid请求参数
|
|
*/
|
|
type MiniAppOpenidReq struct {
|
|
Appid string
|
|
Secret string
|
|
JsCode string
|
|
}
|
|
|
|
/**
|
|
* 获取小程序openid返回参数
|
|
*/
|
|
type MiniAppOpenidRes struct {
|
|
Openid string
|
|
SessionKey interface{}
|
|
Unionid interface{}
|
|
NickName string
|
|
AvatarUrl string
|
|
WxApiRes
|
|
}
|
|
|
|
/**
|
|
* 获取公众号openid返回参数
|
|
*/
|
|
type MpOpenidRes struct {
|
|
AccessToken string
|
|
ExpiresIn string
|
|
RefreshToken string
|
|
Openid string
|
|
Scope string
|
|
}
|
|
|
|
/**
|
|
* 获取公众号用户信息请求参数
|
|
*/
|
|
type MpUserInfoReq struct {
|
|
AccessToken string
|
|
Openid string
|
|
}
|
|
|
|
/**
|
|
* 根据用户access_token换取用户信息返回参数
|
|
*/
|
|
type MpUserInfoRes struct {
|
|
Openid string
|
|
Nickname string
|
|
Sex string
|
|
Province string
|
|
City string
|
|
Country string
|
|
Headimgurl string
|
|
Privilege string
|
|
Unionid string
|
|
}
|
|
|
|
|
|
func rpc_server_conn(url ...string) (*WeixinRpcServiceClient, error) {
|
|
|
|
var wx_rpc_url string
|
|
if len(url) > 0 && url[0] != "" {
|
|
wx_rpc_url = url[0]
|
|
wx_rpc_url = conf.WEIXIN_RPC_PORT
|
|
} else {
|
|
wx_rpc_url = "127.0.0.1:" + conf.WEIXIN_RPC_PORT
|
|
}
|
|
|
|
conn, _, err := DialWeixinRpcService("tcp", wx_rpc_url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return conn, nil
|
|
}
|