首页  >  文章  >  后端开发  >  php 微信获取用户信息全码

php 微信获取用户信息全码

不言
不言原创
2018-04-19 09:30:571634浏览

这篇文章介绍的内容是关于php 微信获取用户信息全码,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

  因为项目需要,我也是一个新手,所以用了两天把支付,分享,还有获取用户信息做完了,作为一个新手,在网上找代码真心费力!所以为了,让更多的新手一看就会,不走弯路,在此特地写张这篇文章!好了,废话不多说直接上代码和方法!我的qq1414970267,不会的直接问我!

    config.php 代码

 <?php
 session_start();
 $appid = &#39;wxc0edcad16ff403cb&#39;;
 $secret = &#39;3d3b62ae770eff710eaa9d82722639cd&#39;;
?>
index.php
<?php
include_once &#39;config.php&#39;;
$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(&#39;Location: &#39; . $url . &#39;&#39;);
?>
openid.php
<?php
include_once &#39;config.php&#39;;
$code = $_GET[&#39;code&#39;];
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[&#39;openid&#39;];
$access_token = $rs[&#39;access_token&#39;];
$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 微信获取用户信息全码的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn