github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/oauth2/component/oauth2.go (about)

     1  package component
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  )
     7  
     8  // AuthCodeURL 生成网页授权地址.
     9  //
    10  //	appId:          公众号的唯一标识
    11  //	componentAppId: 服务方的appid,在申请创建公众号服务成功后,可在公众号服务详情页找到
    12  //	redirectURI:    授权后重定向的回调链接地址
    13  //	scope:          应用授权作用域
    14  //	state:          重定向后会带上 state 参数, 开发者可以填写 a-zA-Z0-9 的参数值, 最多128字节
    15  func AuthCodeURL(appId, componentAppId, redirectURI, scope, state string) string {
    16  	return fmt.Sprintf("https://open.weixin.qq.com/connect/oauth2/authorize?"+
    17  		"appid=%s&component_appid=%s&redirect_uri=%s&scope=%s&state=%s&response_type=code#wechat_redirect",
    18  		url.QueryEscape(appId),
    19  		url.QueryEscape(componentAppId),
    20  		url.QueryEscape(redirectURI),
    21  		url.QueryEscape(scope),
    22  		url.QueryEscape(state),
    23  	)
    24  }