没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
请求url:
https://xxrj.pro/getopenid?code=021ULzl6192cIM1N1Vm61c6Bl61ULzlJ
返回值:
{"expires_in":7200,"openid":"o7Vwe0cG7kfKa3xxxxxxxxxxxx0x8","session_key":"/Cw7AY2serdTkJWFMgj+Gg=="}
源码
func (c *WxApiController) Getopenid(){
Appid:="wxa4cf091234567899999" //随意写的,在自己小程序后台查看
Secret:="c73f8123456789987456321" //随意写的,在自己小程序后台查看
Code:=strings.TrimSpace(c.GetString("code"))
fmt.Print('s',Code)
baseUrl := "https://api.weixin.qq.com/sns/jscode2session?appid="+Appid+"&secret="+Secret+"&js_code="+Code+"&grant_type=authorization_code"
resp, err := http.Get(baseUrl)
if err != nil {
fmt.Println(err.Error())
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return
}
var data map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
fmt.Println(err.Error())
return
}
c.Data["json"] = data
c.ServeJSON()
https://xxrj.pro/getopenid?code=021ULzl6192cIM1N1Vm61c6Bl61ULzlJ
返回值:
{"expires_in":7200,"openid":"o7Vwe0cG7kfKa3xxxxxxxxxxxx0x8","session_key":"/Cw7AY2serdTkJWFMgj+Gg=="}
源码
func (c *WxApiController) Getopenid(){
Appid:="wxa4cf091234567899999" //随意写的,在自己小程序后台查看
Secret:="c73f8123456789987456321" //随意写的,在自己小程序后台查看
Code:=strings.TrimSpace(c.GetString("code"))
fmt.Print('s',Code)
baseUrl := "https://api.weixin.qq.com/sns/jscode2session?appid="+Appid+"&secret="+Secret+"&js_code="+Code+"&grant_type=authorization_code"
resp, err := http.Get(baseUrl)
if err != nil {
fmt.Println(err.Error())
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return
}
var data map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
fmt.Println(err.Error())
return
}
c.Data["json"] = data
c.ServeJSON()
资源评论
- ywtywt3372021-11-07有用,能作为参考用
xxrj
- 粉丝: 3
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功