微信公众号小程序授权登录

8 篇文章 0 订阅

PHP 公众号授权登录

/**
 * PHP 公众号授权登录
 */
function myfun1()
{
    $appid = "wx************";
    $redirect_uri = urlencode('http://www.example.com/redirect.php'); // 回调地址
    $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
    header("Location: $url");
}

PHP 扫码关注公众号授权登录

/**
 * PHP 扫码关注公众号授权登录
 */
function myfun2()
{
    $appid = "wx************";
    $redirect_uri = urlencode('http://www.example.com/redirect.php'); // 回调地址
    $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
    header("Location: $url");
}

PHP 微信小程序授权登录

/**
 * PHP 微信小程序授权登录
 */
function getOpenid($code)
{
    $appid = "wx************";
    $secret = "************";
    $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $secret . "&js_code=" . $code . "&grant_type=authorization_code";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $output = curl_exec($ch);
    curl_close($ch);
    $jsoninfo = json_decode($output, true);
    $array = get_object_vars($jsoninfo);
    return $array;
}

PHP 微信授权登录返回401错误

/**
 * PHP 微信授权登录返回401错误
 */
function getAccessToken($code)
{
    $appid = "wx************";
    $secret = "************";
    $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code";
    $res = file_get_contents($url);
    $res = json_decode($res, true);
    return $res;
}

PHP 微信小程序授权登录记住小程序的登录状态

/**
 * PHP 微微信小程序授权登录记住小程序的登录状态
 */
function wxlogin($code)
{
    $appid = 'wx************';
    $secret = '************';
    $url = "https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$secret&js_code=$code&grant_type=authorization_code";
    $res = file_get_contents($url);
    $res = json_decode($res, true);
    return $res;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

withoutfear

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值