这篇文章介绍的内容是关于php 微信获取用户信息全码,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
因为项目需要,我也是一个新手,所以用了两天把支付,分享,还有获取用户信息做完了,作为一个新手,在网上找代码真心费力!所以为了,让更多的新手一看就会,不走弯路,在此特地写张这篇文章!好了,废话不多说直接上代码和方法!我的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 微信获取用户信息全码的详细内容。