mina

package module
v0.0.0-...-c84549d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2018 License: MIT Imports: 13 Imported by: 0

README

mina

Build Status

Golang 微信小程序 SDK

done

登录和解密

todo

生成二维码

usage

package mina

import (
	"github.com/solarhell/mina/debug"
	"net/http"
)

func main() {
	c := NewClient(&http.Client{
		Transport: &debug.DebugRequestTransport{
			RequestHeader:  true,
			RequestBody:    true,
			ResponseHeader: true,
			ResponseBody:   true,
		},
	})

	ui, err := c.Login("appid", "secret", "code")
	...
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSignature   = errors.New("signature error")
	ErrPaddingSize = errors.New("padding size error")
)

Functions

func AesCBCDecrypt

func AesCBCDecrypt(sessionKey, encryptedData, iv string) (plaintext []byte,
	err error)

接口返回的加密数据( encryptedData )进行对称解密。 解密算法如下: 对称解密使用的算法为 AES-128-CBC,数据采用PKCS#7填充。 对称解密的目标密文为 Base64_Decode(encryptedData)。 对称解密秘钥 aeskey = Base64_Decode(session_key), aeskey 是16字节。 对称解密算法初始向量 为Base64_Decode(iv),其中iv由数据接口返回。 AES并没有64位的块, 如果采用PKCS5, 那么实质上就是采用PKCS7

func CheckSignature

func CheckSignature(signature, sessionKey, rawData string) bool

func CodeToURL

func CodeToURL(appID, secret, code string) (string, error)

func PKCS5UnPadding

func PKCS5UnPadding(plaintext []byte, blockSize int) ([]byte, error)

https://play.golang.org/p/oZ5OwdRYLV

func Sha1

func Sha1(key string) string

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client) *Client

func (*Client) Login

func (c *Client) Login(appID, secret, code string) (lr LoginResponse, err error)

type CommonResponse

type CommonResponse struct {
	Errcode int    `json:"errcode,omitempty"`
	Errmsg  string `json:"errmsg,omitempty"`
}

Response 请求微信返回基础数据

type DebugRequestTransport

type DebugRequestTransport struct {
	RequestHeader  bool
	RequestBody    bool // RequestHeader 为 true 时,这个选项才会生效
	ResponseHeader bool
	ResponseBody   bool // ResponseHeader 为 true 时,这个选项才会生效

	// debug 信息输出到 Writer 中, 默认是 os.Stderr
	Writer io.Writer

	Transport http.RoundTripper
}

DebugRequestTransport 会打印请求和响应信息, 方便调试.

func (*DebugRequestTransport) RoundTrip

func (t *DebugRequestTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type LoginResponse

type LoginResponse struct {
	CommonResponse
	Unionid    string `json:"unionid,omitempty"`
	Openid     string `json:"openid"`
	SessionKey string `json:"session_key"`
}

type UserInfo

type UserInfo struct {
	UnionId   string     `json:"unionId,omitempty"`
	OpenId    string     `json:"openId"`
	NickName  string     `json:"nickName"`
	Gender    int        `json:"gender"` // 值为1时是男性,值为2时是女性,值为0时是未知
	AvatarUrl string     `json:"avatarUrl"`
	City      string     `json:"city"`
	Province  string     `json:"province"`
	Country   string     `json:"country"`
	Language  string     `json:"language"`
	Watermark *Watermark `json:"watermark,omitempty"` //数据水印( watermark )
}

微信小程序加密数据结构

func DecryptUserInfo

func DecryptUserInfo(sessionKey, encryptedData, iv string) (ui UserInfo, err error)

type Watermark

type Watermark struct {
	Appid     string `json:"appid"`
	Timestamp int64  `json:"timestamp"`
}

用于校验数据正确性

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL