ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 类名 ~~~ \Oreo\Wechat\Auth\WechatAuth ~~~ # # 参数 | 名称 | 类型 | 说明 | | --- | --- | --- | | appId | String | 小程序的唯一标识 | | appSecret | String | 小程序的SecretKey | | code | String | 用户Code(微信小程序登录时获取的code) | # ## 调用函数 | 函数名称 | 类型 | 传参值 |说明 | | --- | --- | --- |--- | | authIndex | Int | 3 | 1=>获取Code; 2=>Code兑换OpenId和access_token;3=>小程序Code兑换OpenId;4=>根据access_token和OpenId获取用户信息;| # ## 调用方法(实例) ``` $wx = new \Oreo\Wechat\Auth\WechatAuth(); //初始化类 $wx->appId = 'wxc123457898'; //公众号appId $wx->appSecret = '05c139ee3123456789abcdef'; //公众号appSecret $wx->code = $_GET['code']; //微信小程序登录时获取的code $arr = $wx->authIndex(3); /* var_dump($arr); exit(); */ $arr = json_decode($arr,true); //将会获取到 $openid = $arr['openid']; //用户openId $session_key = $arr['session_key'];//用户session_key ```