github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/bizwifi/qrcode/get.go (about)

     1  package qrcode
     2  
     3  import (
     4  	"github.com/chanxuehong/wechat/mp/core"
     5  )
     6  
     7  // 获取物料二维码
     8  //
     9  //	shopId: 门店ID
    10  //	imgId:  物料样式编号:
    11  //	        0-二维码,可用于自由设计宣传材料;
    12  //	        1-桌贴(二维码),100mm×100mm(宽×高),可直接张贴
    13  func Get(clt *core.Client, shopId int64, imgId int) (qrcodeURL string, err error) {
    14  	request := struct {
    15  		ShopId int64 `json:"shop_id"`
    16  		ImgId  int   `json:"img_id"`
    17  	}{
    18  		ShopId: shopId,
    19  		ImgId:  imgId,
    20  	}
    21  
    22  	var result struct {
    23  		core.Error
    24  		Data struct {
    25  			QrcodeURL string `json:"qrcode_url"`
    26  		} `json:"data"`
    27  	}
    28  
    29  	incompleteURL := "https://api.weixin.qq.com/bizwifi/qrcode/get?access_token="
    30  	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
    31  		return
    32  	}
    33  
    34  	if result.ErrCode != core.ErrCodeOK {
    35  		err = &result.Error
    36  		return
    37  	}
    38  
    39  	qrcodeURL = result.Data.QrcodeURL
    40  	return
    41  }