1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/dbj151-weiphp

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
В этом репозитории не указан файл с открытой лицензией (LICENSE). При использовании обратитесь к конкретному описанию проекта и его зависимостям в коде.
Клонировать/Скачать
get_code_openid.php 2.7 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Dave Отправлено 08.12.2017 04:17 5850eb5
<?php
header("Content-type: text/html; charset=utf-8");
class get_code_openid{
/**
* 获取code值
* */
public function get_code($act = "get_code"){
if(!isset($_GET['code'])){
$appid = "wx0fedaa9a564c2877";
$urls = urlencode('http://xsfr.mgtvshop.com/get_code_openid.php?act='.$act);
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$urls."&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
header("location:".$url);
}else{
//这里获取到code
file_put_contents('./Runtime/code.json',json_encode(['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换取网页授权access_token
$jsondecode=json_decode($weixin); //对JSON格式的字符串进行编码
$user_info = get_object_vars($jsondecode);//转换成数组
return json_encode($user_info);
}
/**
* 通过code获取openid
* */
public function get_openId(){
$this->get_code('get_openId');
$data = file_get_contents('./Runtime/code.json');
$code_info = json_decode($data,true);
$appid = "wx0fedaa9a564c2877";
$appsecret = "f21d29c42141104d9a5aa1ce1bdf4204";
$code = $code_info['code'];
$result = $this->getOpenID($appid,$appsecret,$code);
$info = json_decode($result,true);
$access_token_info = file_get_contents('./Runtime/access_token.json');
$access_token = json_decode($access_token_info);
$access_token = $access_token->access_token->access_token;
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$access_token."&openid=".$info['openid'];
$user_info = file_get_contents($url);
echo $user_info;
}
/**
* 获取用户基本信息
* */
public function get_userinfo(){
$this->get_openId();
$data = file_get_contents('./Runtime/result.json');
file_put_contents('./Runtime/data_test.txt',$data);exit;
echo $data;exit;
$data = json_decode($data,true);
var_dump($data);exit;
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$data['access_token']."&openid=".$data['openid'];
$user_info = file_get_contents($url);
echo $user_info;
}
}
if(!isset($_GET['act'])){
echo "act不能为空";
}else{
$act = $_GET['act'];
$obj = new get_code_openid();
$obj->$act();
}
?>

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/dbj151-weiphp.git
git@api.gitlife.ru:oschina-mirror/dbj151-weiphp.git
oschina-mirror
dbj151-weiphp
dbj151-weiphp
master