首頁  >  文章  >  後端開發  >  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
上一篇:PHP內核之zval下一篇:PHP內核之zval