php 微信开放平台 获取授权公众号 easywechat

 

微信SDK地址: https://www.easywechat.com/

我们先看微信官方文档中的第一步 获取component_access_token 文档地址: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/component_verify_ticket.html

每10分钟 请求一次 授权事件接收URL 也就是 10分钟 修改一次缓存 我们不需要怎么麻烦使用 easywechat

easy文档地址: https://www.easywechat.com/docs/4.1/open-platform/server

useEasyWeChat\Factory;$config=['app_id'=>'开放平台第三方平台 APPID','secret'=>'开放平台第三方平台 Secret','token'=>'开放平台第三方平台 Token','aes_key'=>'开放平台第三方平台 AES Key'];$openPlatform= Factory::openPlatform($config);
$server = $openPlatform->server;

return $server->serve()
后面我们使用: (获取用户授权URL) 文档地址: https://www.easywechat.com/docs/4.1/open-platform/index $openPlatform->getPreAuthorizationUrl('https://easywechat.com/callback');// 传入回调URI即可
最后我们写个 控制器 class WxOpen {
private $config = [ 'app_id' => '开放平台第三方平台 APPID', 'secret' => '开放平台第三方平台 Secret', 'token' => '开放平台第三方平台 Token', 'aes_key' => '开放平台第三方平台 AES Key' ]; private $openPlatform = null; public function __construct() { $this->openPlatform = Factory::openPlatform($this->config); } public function Token() { // 缓存component_access_token $server = $this->openPlatform->server; return $server->serve(); } public function UserUrl() { $userUrl = $this->openPlatform->getPreAuthorizationUrl('https://easywechat.com/callback'); // 传入回调URI即可 // 注意不是让你直接跳转过去 是让用户点击过去 才可 return "<a href='{$userUrl}'></a>"; } }
参考:https://www.nekgod.cn/blog/a/weixinkaifangpingtaikaifa/weixinkaifangpingtaihuoqushouquanye
posted @ 2020-05-28 10:42  NEKGod  阅读(984)  评论(0)    收藏  举报