微信公众号三方平台开发【生成授权页】

之前我们讲过,在获取到预授权码之后,我们需要在自己的网站中设置授权页入口(如下图),从而引导微信公众号管理员进入到授权页,对第三方平台进行微信公众号的托管授权。
授权页引导页

对于微信授权页,简单的说就是一个带有规定参数的URL,其中包括第三方平台的appid、预授权码以及回调URL,通过访问这个URL,各个参数正确无误,就会进入到授权页,如:
授权页

生成授权页URL,首先我们需要获取得到“预授权码”:
$pre_auth_code = $this->get_pre_auth_code ();
if ($pre_auth_code == false) {
$res ['msg'] = '获取pre_auth_code失败!';
return $res;
}

其次还需要封装好“回调URL”,其中“BASE_URL”为网站域名:
$callback = BASE_URL.U('Wechat/Wechat/after_auth');

然后,组装授权页URL:
$jumpURL = 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=第三方平台appid&pre_auth_code='.$pre_auth_code.'&redirect_uri='.$callback;

这里,我们对授权页的生成创建一个可供调用的方法,在需要生成的授权页URL的页面进行调用,如:
$tips = A('Wechat/Wechat')
$res = $tips->tips();
if (! $res ['status']) {
$this->error ( $res ['msg'] );
exit ();
}
$this->assign ( 'jumpURL', $res ['jumpURL'] );

完整代码:
1)授权引导页调用

Public function index(){
$tips = A('Wechat/Wechat')
$res = $tips->tips();
if (! $res ['status']) {
$this->error ( $res ['msg'] );
exit ();
}
$this->assign ( 'jumpURL', $res ['jumpURL'] );
$this->display():
}

2)授权页URL生成方法

public function tips(){
$res ['status'] = false;
$pre_auth_code = $this->get_pre_auth_code ();
if ($pre_auth_code == false) {
$res ['msg'] = '获取pre_auth_code失败!';
return $res;
}
$callback = BASE_URL.U('Wechat/Wechat/after_auth');
$jumpURL = 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=第三方平台appid&pre_auth_code='.$pre_auth_code.'&redirect_uri='.$callback;
$res ['status'] = true;
$res ['jumpURL'] = $jumpURL;
return $res;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

袁威

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

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

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

打赏作者

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

抵扣说明:

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

余额充值