qrcode.go 775 Bytes
Newer Older
haoyanbin's avatar
1  
haoyanbin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
package wx

import (
	"encoding/base64"
	"github.com/medivhzhan/weapp/v2"
	"io/ioutil"
)

func GetUnlimited(token string, scene string, page string, width int, colorR string, colorG string, colorB string) string {
	getter := weapp.UnlimitedQRCode{
		Scene:     scene,
		Page:      page,
		Width:     width,
		AutoColor: true,
		LineColor: weapp.Color{colorR, colorG, colorB},
		IsHyaline: true,
	}

	resp, res, err := getter.Get(token)
	if err != nil {
		// 处理一般错误信息
		return err.Error()
	}

	if err := res.GetResponseError(); err != nil {
		// 处理微信返回错误信息
		return err.Error()
	}
	defer resp.Body.Close()

	content, err := ioutil.ReadAll(resp.Body)
	sEnc := base64.StdEncoding.EncodeToString(content)
	// 处理图片内容
	return sEnc
}