微信内置浏览器打开的网页,获取微信用户openid

移动开发 码拜 8年前 (2016-04-10) 1431次浏览
本人已开通300元的开发者账号。
需求如下:
现有一wap网页,用户使用微信内置浏览器打开(通过微信朋友圈/朋友分享,微信扫网页二维码等方式进入,与公众号无关),该网页怎么样获取用户的微信openid呢?
按照官方的微信登录帮助,是可以实现扫码登录,但是针对PC版的–微信扫码,电脑端登录。而本人的情况是当前网页是在手机微信打开的,还怎么扫码呢?
本人见有些网站是可以实现的,会弹出授权提示框,但不知是怎么样实现的?谢谢了!
解决方案

20

开发文档-用户管理-网页授权获取用户基本信息 这里面写的很详细了

10

http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html

10

function getOpenid($step,$type=”base”,$backurl=null,$minwen=1,$app_id,$app_secret){
if(!is_weixin()) return false;
$cfg = array(“appid”=>$app_id,”secret”=>$app_secret);
switch ($step) {
case “2”:
$s = json_decode(getRemoteContent(“https://api.weixin.qq.com/sns/oauth2/access_token?appid=”.$cfg[“appid”].”&secret=”.$cfg[“secret”].”&code=”.$_GET[“code”].”&grant_type=authorization_code”),true);
cookie(md5(“share_openid”),$s[“openid”]);
$u = json_decode(getRemoteContent(“https://api.weixin.qq.com/sns/userinfo?access_token=”.$s[“access_token”].”&openid=”.$s[“openid”].”&lang=zh_CN”),true);
if($u[“errcode”]){
$s[“w_id”] = $w_id;
//处理手机的用户信息,没有昵称头像…..
}else{
$u[“w_id”] = $w_id;
//处理手机的用户信息,带昵称头像…..
}

break;

default:
$url  = “https://open.weixin.qq.com/connect/oauth2/authorize?appid=”.$cfg[“appid”].”&redirect_uri=”.urlencode($backurl).”&response_type=code&scope=snsapi_”.$type.”&state=1#wechat_redirect”;
if($minwen){
$html = “<!doctype html><html><head></head><body>”;
$html .= “<div style=”font-size:2em;margin-top:40%;text-align:center;”>页面加载中,请稍候…</div><script>location.href=””.$url.””</script>”;
$html .= “</body></html>”;
die($html);
}else{
@header(“location:”.$url);
}
}

}

10

$r_url = “http://”.$_SERVER[“HTTP_HOST”].$_SERVER[“REQUEST_URI”];
if(!$this->_get(“code”)){
getOfficialOpenId(1,”base”,$r_url);
}else{
getOfficialOpenId(2);

}


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明微信内置浏览器打开的网页,获取微信用户openid
喜欢 (0)
[1034331897@qq.com]
分享 (0)