时间:2021-07-01 10:21:17 帮助过:2人阅读
因为项目需要,我也是一个新手,所以用了两天把支付,分享,还有获取用户信息做完了,作为一个新手,在网上找代码真心费力!所以为了,让更多的新手一看就会,不走弯路,在此特地写张这篇文章!好了,废话不多说直接上代码和方法!我的qq1414970267,不会的直接问我!
config.php 代码
<?php session_start(); $appid = 'wxc0edcad16ff403cb'; $secret = '3d3b62ae770eff710eaa9d82722639cd'; ?> index.php <?php include_once 'config.php'; $redirect_uri = "http://www.127ck.com/index1/openid.php"; $redirect_uri = urlencode($redirect_uri); $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=" . $redirect_uri . "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; header('Location: ' . $url . ''); ?> openid.php <?php include_once 'config.php'; $code = $_GET['code']; function get_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); $rs = $result ? json_decode($result, true) : ""; return $rs; } $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code"; $rs = get_curl($url); $openid = $rs['openid']; $access_token = $rs['access_token']; $url_userinfo = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$access_token."&openid=".$openid."&lang=zh_CN"; $rs_userinfo = get_curl($url_userinfo); var_dump($rs_userinfo); ?>
这就是获取信息的全部代码,代码亲测,绝对可用!不懂可用问我!
相关推荐:
php微信公众号开发之现金红包
以上就是php 微信获取用户信息全码的详细内容,更多请关注Gxl网其它相关文章!