12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
-
-
- package authorization
-
- import (
- "encoding/json"
- "net/url"
-
- "gitee.com/yansen_zh/wxcomponent/config"
- wxerr "gitee.com/yansen_zh/wxcomponent/errors"
- "gitee.com/yansen_zh/wxcomponent/utils/request"
- )
-
-
- type PreAuthCodeResult struct {
- wxerr.Error
- PreAuthCode string `json:"pre_auth_code"`
- ExpiresIn int `json:"expires_in"`
- }
-
- const (
- apiCreatePreauthcode = "https://apies.weixin.qq.com/cgi-bin/component/api_create_preauthcode"
- )
-
-
- func CreatePreAuthCode() (*PreAuthCodeResult, error) {
- queryParam := url.Values{}
- queryParam.Set("component_access_token", config.GetAccessToken())
-
- data := map[string]string{
- "component_appid": config.GetAppID(),
- }
-
- resp, e2 := request.PostJSON(apiCreatePreauthcode, &queryParam, data)
- if e2 != nil {
- return nil, e2
- }
-
- result := PreAuthCodeResult{}
- if err := json.Unmarshal(resp, &result); err != nil {
- return nil, err
- }
-
- return &result, nil
- }
|