小程序用户授权可以获取用户的信息
Posted 酸suan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小程序用户授权可以获取用户的信息相关的知识,希望对你有一定的参考价值。
wxml页面
<button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo></button>
js页面
bindGetUserInfo:function(e){
console.log(e)
wx.login({
success:res=>{
}
})
}
wxapp.php
// 用户授权
//获取用户信息
public function doPageTyMember() {
global $_GPC, $_W;
$uniacid = $_W[‘uniacid‘];
$openid = $_REQUEST[‘openid‘];
$item[‘u_name‘] = $_GPC[‘u_name‘];
$item[‘u_thumb‘] = $_GPC[‘u_thumb‘];
$item[‘uniacid‘] = $uniacid;
if ($openid) {
$res = pdo_update(‘hyb_ylxc_userinfo‘, $item, array(‘openid‘ => $openid));
}
if (!$res[‘u_id‘]) {
$res = pdo_fetch(‘SELECT `u_id` FROM ‘ . tablename(‘hyb_ylxc_userinfo‘) . " where `openid`=‘{$openid}‘");
}
$message = ‘success‘;
$errno = 0;
return $this->result($errno, $message, $item);
}
public function doPageGetUid() {
global $_GPC, $_W;
$uniacid = $_W[‘uniacid‘];
$result = pdo_fetch(‘SELECT * FROM ‘ . tablename(‘hyb_ylxc_key‘) . " where `uniacid`=‘{$uniacid}‘");
$APPID = "wxbcf230862644aa93";
// $APPID = $result[‘appid‘];
// $SECRET = $result[‘appsecret‘];
$SECRET = "1ad4414c9da569ca333d216cc6d0f643";
$optionid = "oiw7_0FlOxmb4SmYHwT7K0rBdCnY";
$code = trim($_GPC[‘code‘]);
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$APPID}&secret={$SECRET}&js_code={$code}&grant_type=authorization_code";
$data[‘userinfo‘] = json_decode($this->httpGet($url));
$openid = $data[‘userinfo‘]->openid;
$item[‘openid‘] = $openid;
if ($openid) {
$res = pdo_fetch(‘SELECT `u_id` FROM ‘ . tablename(‘hyb_ylxc_userinfo‘) . " where `openid`=‘{$openid}‘");
if (!$res[‘u_id‘]) {
$res = pdo_insert(‘hyb_ylxc_userinfo‘, $item);
}
}
$data[‘openid‘] = $openid;
$message = ‘success‘;
$errno = 0;
return $this->result($errno, $message, $data);
}
以上是关于小程序用户授权可以获取用户的信息的主要内容,如果未能解决你的问题,请参考以下文章