小程序
小游戏
企业微信
微信支付
扫描小程序码分享
我看了官方文档,知道是用临时code来换取,奈何我编成实在太菜,不知道怎么写,有没有人可以给代码啊,求告知啊,我不要用云函数的,
6 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
public function getOpenid($appid, $appsecret) { $SERVER_NAME = $_SERVER['SERVER_NAME']; $REQUEST_URI = $_SERVER['REQUEST_URI']; $redirect_uri = urlencode('http://' . $SERVER_NAME . $REQUEST_URI); $code = $_GET['code']; if (! $code) { // 网页授权 $autourl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"; header("location:$autourl"); } else { // 获取openid $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code"; $row = $this->posturl($url); return ($row['openid']); } } public function posturl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $jsoninfo = json_decode($output, true); return $jsoninfo; }
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
emmmm,个人项目?
--↓↓👍如果觉得有帮助的话请点个【赞】吧(我的小尾巴又肥来啦!)
你可以用开发者工具,新建一个项目,勾选“云开发Quickstart项目”,然后demo里就有~
直接调用里头的云函数:login,就能拿到openid,而且不需要用户点击授权~
谢邀。看这个试试:
https://developers.weixin.qq.com/community/develop/article/doc/000a0aed14c3285bea79e67ee56813
不用云函数就只有https的方法了,但是api.weixin.qq.com是禁止在小程序里调用的
api.weixin.qq.com是禁止在小程序里调用的
最简单的就是通过按钮授权获取。
新建个项目,默认的demo里就有
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
public function getOpenid($appid, $appsecret) { $SERVER_NAME = $_SERVER['SERVER_NAME']; $REQUEST_URI = $_SERVER['REQUEST_URI']; $redirect_uri = urlencode('http://' . $SERVER_NAME . $REQUEST_URI); $code = $_GET['code']; if (! $code) { // 网页授权 $autourl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"; header("location:$autourl"); } else { // 获取openid $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code"; $row = $this->posturl($url); return ($row['openid']); } } public function posturl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $jsoninfo = json_decode($output, true); return $jsoninfo; }
emmmm,个人项目?
--↓↓👍如果觉得有帮助的话请点个【赞】吧(我的小尾巴又肥来啦!)
你可以用开发者工具,新建一个项目,勾选“云开发Quickstart项目”,然后demo里就有~
直接调用里头的云函数:login,就能拿到openid,而且不需要用户点击授权~
谢邀。看这个试试:
https://developers.weixin.qq.com/community/develop/article/doc/000a0aed14c3285bea79e67ee56813
不用云函数就只有https的方法了,但是
api.weixin.qq.com是禁止在小程序里调用的
最简单的就是通过按钮授权获取。
新建个项目,默认的demo里就有