orq / wxpn
The PHP library to make WeiXin Public Number Development easier
dev-master
2019-06-05 05:42 UTC
Requires (Dev)
- phpunit/phpunit: ^8.2@dev
This package is auto-updated.
Last update: 2025-04-05 18:48:00 UTC
README
微信公众号开发PHP库
wxpn
微信公众号开发PHP库
安装
composer require orq/wxpn
- 下载本仓库的代码,使用示例如下:
include_once ROOT.'/wxpn/wxpn_autoloader.php'; $wQrCode = new Orq\Wxpn\QrCode(WX_APPID, WX_APPSECRET);
手册
Oauth2 (网页授权)
- 根据文档完成配置
- 代码调用示例:
// 第一步 $wAuth = new Orq\Wxpn\Auth($appid, $secret); $redirect_url = 'http://my.com/path_for_wxlogin'; $jumpurl = $wAuth->oauth2AuthorizeUrl($redirect_url, "snsapi_userinfo", "123"); header("Location: $jumpurl"); // 第二步 (http://my.com/path_for_wxlogin所在的页面) $code = $_GET['code']; $access_token_oauth2 = $wAuth->oauth2AccessToken($code); // 如果scope是snsapi_base则流程到此结束 // 第三步 $userinfo = $this->wAuth-> oauth2GetUserInfo($access_token_oauth2['access_token']
自定义菜单
- 开发文档
- 代码示例
$wMenu = new Orq\Wxpn\Menu($appid, $secret); $button = [ [ 'name' => '享睡雅兰', 'sub_button' => [ [ 'type' => "view", 'name' => "关于我们", 'url' => "http://www.my_domain.com/about_us" ], [ 'type' => 'click', 'name' => '客服电话', 'key' => '40088223344' ] ] ] ]; $wMenu->create($button);
生成渠道二维码海报
- 文档
- 示例代码
$wQrCode = new Orq\Wxpn\QrCode($appid, $secret); $sceneId = 33; $qrPath = './path_to_store/'.$sceneId.'.jpg' $wQrCode->getQrCode($type, $sceneId, $qrPath); $wQrCode->makePoster($qrPath, $bgFilePath, $targetPath);
- 海报文件存储在$targetPath
- 用户扫描海报时会发送
订阅
事件,文档 - 代码调用示例
// 首先需要实现接口 class RegisterService implements Orq\Wxpn\QrcodeJoinSubstriberInterface { /** * $userInfo 为新用户的信息 * $sceneId 为场景(渠道)值 */ public function notify(array $userInfo, string $sceneId):void { } } $registerService = new RegisterService(); $wMessage = new Orq\Wxpn\Message($appid, $secret); $wMessage->subscribeQrcodeJoin($regiseterService);