欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php 微信開發(fā)獲取用戶信息如何實(shí)現(xiàn)

 更新時(shí)間:2016年12月13日 14:21:10   投稿:lqh  
這篇文章主要介紹了php 微信開發(fā)獲取用戶信息如何實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下

php 微信開發(fā)獲取用戶信息

獲取用戶信息的大致算法是

用戶授權(quán)登錄第三方網(wǎng)站,

重點(diǎn):scope參數(shù):
snsapi_basic 靜默登錄,不需要用戶授權(quán),只能獲取到openid;
snsapi_userinfo ,需要用戶點(diǎn)擊授權(quán),能獲取到openid和所有用戶信息;

第一步:先獲取用戶的code值;
第二步:根據(jù)code值去獲取access_token,每次請(qǐng)求的值都不一樣,如果沒有使用,每五分鐘更新一次;
第三步:根據(jù)access_token獲取用戶信息;

1.獲取code代碼實(shí)現(xiàn):

getcode.php

if(isset($_SESSION['user'])){
              print_r($_SESSION['user']);
              exit;
            }

$appid='wx1d7c6fcd6131143b3';

            $redirect_url="http://www.antfortune.vip/callback.php";
            $scope='snsapi_userinfo';//獲取的方式;


            $url='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.urlencode($redirect_url).'&response_type=code&scope='.$scope.'&state=123#wechat_redirect';


header("Location:".$url);

2、根據(jù)code獲取access_token和openid

getOpenid.php



<?php
//獲取用戶openid
$appid="your appid";
$appsecret="your appsecret";
$code=$_GET['code'];



function getOpenID($appid,$appsecret,$code){
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=". 
$appsecret."&code=".$code."&grant_type=authorization_code";

$weixin=file_get_contents($url);//通過code換取網(wǎng)頁授權(quán)access_token
$jsondecode=json_decode($weixin); //對(duì)JSON格式的字符串進(jìn)行編碼
$array = get_object_vars($jsondecode);//轉(zhuǎn)換成數(shù)組
$openid = $array['openid'];//輸出openid
return $openid;
}

echo getOpenID($appid,$appsecret,$code);


感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論