/** * 微信公众号联合登录 * @return array|int * @throws DataNotFoundException * @throws DbException * @throws LogicException * @throws ModelNotFoundException */public function openid(): array{ $code = $this->request->param('code', ''); if (empty($code)) throw new LogicException("code必传"); $secret = Config::get('business.wechat.secret'); $appid = Config::get('business.wechat.appid'); $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret;=" . $secret . "&code;=" . $code . "&grant;_type=authorization_code"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $content = curl_exec($ch); $status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status == 404) { return $status; } curl_close($ch); $errcode = json_decode($content, true); if (isset($errcode['errcode'])) { throw new LogicException($errcode['errmsg']); } //Log::info('errcode:' . $content); if (isset($errcode['openid']) && isset($errcode['access_token'])) { $info = $this->getUserInfo($errcode['openid'], $errcode['access_token']); //Log::info('info:' . json_encode($info, true)); $unionid = $info['unionid']; $nickname = $info['nickname']; $headimgurl = $info['headimgurl']; $clientSecret = $this->request->param('clientSecret', ''); return $this->userInfoService->login( 'mobile', $clientSecret. 'driving-test-web', 'oauth', $errcode['openid'], '', $this->request->deviceId, $this->request->deviceToken, $this->request->ip(), $errcode['openid'], $nickname, $headimgurl, $unionid ); } throw new LogicException('获取失败');}/** * 微信小程序获取openid * @return array|int * @throws DataNotFoundException * @throws DbException * @throws LogicException * @throws ModelNotFoundException */public function smallOpenid(){ $code = $this->request->param('code', ''); $nickname = $this->request->param('nickname', ''); $headimgurl = $this->request->param('headimgurl', ''); if (empty($code)) throw new LogicException("code必传"); $secret = Config::get('business.wechat.small_secret'); $appid = Config::get('business.wechat.small_appid'); $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret;=" . $secret . "&js;_code=" . $code . "&grant;_type=authorization_code"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $content = curl_exec($ch); $status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status == 404) { return $status; } curl_close($ch); $result = json_decode($content, true); if (isset($result['errcode'])) { throw new LogicException($result['errmsg']); } //return $result['openid']; $clientSecret = $this->request->param('clientSecret', ''); return $this->userInfoService->login( 'mobile', $clientSecret. 'driving-test-wechat', 'oauth', $result['openid'], '', $this->request->deviceId, $this->request->deviceToken, $this->request->ip(), $result['openid'], $nickname, $headimgurl, $result['unionid'] );}/** * 头条获取openid * @return array|int * @throws DataNotFoundException * @throws DbException * @throws LogicException * @throws ModelNotFoundException */public function toutiaoOpenid(){ $code = $this->request->param('code', ''); $nickname = $this->request->param('nickname', ''); $headimgurl = $this->request->param('headimgurl', ''); if (empty($code)) throw new LogicException("code必传"); $secret = Config::get('business.toutiao.secret'); $appid = Config::get('business.toutiao.app_id'); $url = "https://developer.toutiao.com/api/apps/jscode2session?appid=" . $appid . "&secret;=" . $secret . "&code;=" . $code; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $content = curl_exec($ch); $status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status == 404) { return $status; } curl_close($ch); $result = json_decode($content, true); if ($result['error'] != 0) { throw new LogicException($result['errcode'] . ':' . $result['errmsg']); } //return $result['openid']; //Log::info('字节小程序openid:' . $result['openid'].';unionid:'.$result['unionid']); $clientSecret = $this->request->param('clientSecret', ''); return $this->userInfoService->login( 'mobile', $clientSecret. 'driving-test-tiktok', 'oauth', $result['openid'], '', $this->request->deviceId, $this->request->deviceToken, $this->request->ip(), $result['openid'], $nickname, $headimgurl, $result['unionid'] );}/** * 获取用户信息 * @param string $openid 调用【网页授权获取用户信息】接口获取到用户在该公众号下的Openid * @return string */public function getUserInfo($openid, $access_token){ $response = self::curlGet('https://api.weixin.qq.com/sns/userinfo?access_token=' . $access_token . '&openid;=' . $openid . '〈=zh_CN'); return json_decode($response, true);}public static function curlGet($url = '', $options = array()){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); if (!empty($options)) { curl_setopt_array($ch, $options); } //https请求 不验证证书和host curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $data = curl_exec($ch); curl_close($ch); return $data;}
以上就是抖音 微信小程序登录的全部内容,希望能够对大家有所帮助。
2024-10-17
2023-06-06
2023-04-23
2023-07-26
2023-03-15
英盛企业版苹果版
办公学习84.1MB
下载东方财富期货苹果版
办公学习216.3MB
下载新概念英语第一册苹果版
办公学习228.6MB
下载菜鸟点我达苹果最新版
系统工具160.8MB
下载HiSuiteapp苹果版
系统工具31.1MB
下载黑洞代理苹果版
生活实用38.6MB
下载MXF Video Converter苹果版
摄影图像53MB
下载超级阿姨苹果最新版
生活实用186.8MB
下载史莱姆模拟器游戏苹果版
其他软件176.6MB
下载北京卫视养生堂app
医疗健康6.73MB
下载