php trying to get,php 做微信认证登陆 返回错误 Trying to get property of non-object

php 做微信认证登陆 返回错误 Trying to get property of non-object 已经添加了白名单和 网页授权,不知道是不是我代码问题,求解答。附上错误代码:

public function getOpenId(){

$openid=cookie('openid');

if($openid){

return $openid;

}else{

if (in_wechat()) {

$redirect_uri = request()->url(true);

$AccessCode = $this->getAccessCode($redirect_uri, "snsapi_base");

if ($AccessCode !== FALSE) {

// 获取accesstoken和openid

$Result = $this->getAccessToken($AccessCode);

$openid = $Result->openid;

$AccessToken = $Result->access_token;

cookie('openid',$openid);

return $openid;

}

} else {

return false;

}

}

}

private function getAccessToken($code){

$RequestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->config['appid']."&secret=".$this->config['appsecret']."&code=" . $code . "&grant_type=authorization_code";

$Result = json_decode(Curl::get($RequestUrl), true);

if(isset($Result['errcode'])){

return 'get access token fail';

}

$_return = new \stdClass();

echo $_return->access_token = $Result['access_token'];

$_return->openid = $Result['openid'];

return $_return;

}

private function getAccessCode($redirect_uri, $scope) {

$get=input('param.');

$request_access_token_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->config['appid']."&redirect_uri=http%3a%2f%2fjfshop.gxwdbg.com%2fmobile&response_type=code&scope=snsapi_userinfo#wechat_redirect";

if (empty($get['code'])) {

// 未授权而且是拒绝

if (!empty($get['state'])) {

return FALSE;

} else {

// 未授权

$redirect_uri = urlencode($redirect_uri);

$RequestUrl = str_replace("[REDIRECT_URI]", $redirect_uri, $request_access_token_url);

$RequestUrl = str_replace("[SCOPE]", $scope, $RequestUrl);

// 获取授权

header("location:" . $RequestUrl);

exit(0);

}

} else {

// 授权成功 返回 access_token 票据

return $get['code'];

}

}

bV1y7w?w=680&h=801

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值