github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/card/code/update.go (about)

     1  package code
     2  
     3  import (
     4  	"github.com/chanxuehong/wechat/mp/core"
     5  )
     6  
     7  // 更改Code接口.
     8  func Update(clt *core.Client, id *CardItemIdentifier, newCode string) (err error) {
     9  	request := struct {
    10  		*CardItemIdentifier
    11  		NewCode string `json:"new_code,omitempty"`
    12  	}{
    13  		CardItemIdentifier: id,
    14  		NewCode:            newCode,
    15  	}
    16  
    17  	var result core.Error
    18  
    19  	incompleteURL := "https://api.weixin.qq.com/card/code/update?access_token="
    20  	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
    21  		return
    22  	}
    23  
    24  	if result.ErrCode != core.ErrCodeOK {
    25  		err = &result
    26  		return
    27  	}
    28  	return
    29  }