songjiayang / wechat

WeChat mini app authorization client.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wechat

A WeChat mini app authoriation client.

Installtion

Use go get github.com/songjiayang/wechat to install.

Usage

package main

import (
	"fmt"
	"os"

	"github.com/songjiayang/wechat"
	"github.com/songjiayang/wechat/api"
)

func main() {
	cfg := &wechat.Config{
		AppID:     os.Getenv("WECHAT_APPID"),
		SecretKey: os.Getenv("WECHAT_SECRETKEY"),
		Timeout:   30,
	}

	client := wechat.NewWechat(cfg)

	// get accessToken and cached.
	token, _ := client.AccessToken()
	fmt.Println(token)

	// WeChat mini programs login code.
	output, _ := client.Login("code")
	fmt.Println(output)

	phoneOutput, _ := api.GetPhoneNumber(
		os.Getenv("WECHAT_APPID"),
		output.SessionKey,
		os.Getenv("WECHAT_IV"),
		os.Getenv("WECHAT_ENCRYPTED_DATA"),
	)

	fmt.Println(phoneOutput.PhoneNumber)
}

Reference

About

WeChat mini app authorization client.


Languages

Language:Go 100.0%