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
}
