商城网站建设定制,网站内外链接怎么做,设计公司logo图片,php图书管理系统网站开发首先须要申请,必须企业,个体工商户,媒体等#xff0c;微信开放平台申请地址 https://open.weixin.qq.com/#xff0c;要交300多的费用才能开通
1#xff0c;编写入口#xff1a;微信开放平台的扫码登陆开放的接口可以自动生成PC扫码页面#xff0c;你得到了官方通过审核的…首先须要申请,必须企业,个体工商户,媒体等微信开放平台申请地址 https://open.weixin.qq.com/要交300多的费用才能开通
1编写入口微信开放平台的扫码登陆开放的接口可以自动生成PC扫码页面你得到了官方通过审核的appid和appsecret后先构造一个扫码网址入口这里以一号店的扫码登陆页面为例子
https://open.weixin.qq.com/connect/qrconnect?appidwxbdc5610cc59c1631redirect_urihttps%3A%2F%2Fpassport.yhd.com%2Fwechat%2Fcallback.doresponse_typecodescopesnsapi_loginstate3d6be0a4035d839573b04816624a415e#wechat_redirect
访问后 扫码后手机端效果 入口代码如下
?php
//-------配置
$AppID wxbdc5610cc59c1631;
$AppSecret d4624c36333337afxxxxxxxxxxxxxx;
$callback https://passport.yhd.com/wechat/callback.php; //回调地址
//微信登录 login.php
session_start();
//-------生成唯一随机串防CSRF攻击
$state md5(uniqid(rand(),TRUE));
$_SESSION[wx_state] $state; //存到SESSION
$callback urlencode($callback);
$wxurl https://open.weixin.qq.com/connect/qrconnect?appid.$AppID.redirect_uri{$callback}response_typecodescopesnsapi_loginstate{$state}#wechat_redirect;
header(Location: $wxurl);
?
回调文件callback.php
?php
//验证CSRF攻击
if($_GET[state]!$_SESSION[wx_state]){exit(5001);
}
$AppID wx33333333334d4;
$AppSecret d4624c363333330547af5443d;
$urlhttps://api.weixin.qq.com/sns/oauth2/access_token?appid.$AppID.secret.$AppSecret.code.$_GET[code].grant_typeauthorization_code;
$ch curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$json curl_exec($ch);
curl_close($ch);
$arrjson_decode($json,1);
//得到 access_token 与 openid
print_r($arr);
$urlhttps://api.weixin.qq.com/sns/userinfo?access_token.$arr[access_token].openid.$arr[openid].langzh_CN;
$ch curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$json curl_exec($ch);
curl_close($ch);
$arrjson_decode($json,1);
得到 用户资料
print_r($arr);
?
PC端最终效果如下 如有问题请咨询我的qq1290851757备注csdn博客问问题的