用微信打开地址(红色的为需要替换的内容)
https://open.weixin.qq.com/connect/oauth2/authorize?appid=
appid&redirect_uri=
http://www.回调网址.com/xx.php&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect
xx.php源码
<?php $code = $_GET['code'];//获取code $weixin = file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx97842c91eebd5446&secret=4127fc2a585b86c14399e4fb22f8675f&code=".$code."&grant_type=authorization_code");//通过code换取网页授权access_token $jsondecode = json_decode($weixin);//对JSON格式的字符串进行编码 $arr = get_object_vars($jsondecode);//转换成数组 $openid = $arr['openid'];//输出openid echo $openid; ?>