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

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