angel-project / wechat
WeChat plugin.
v0.0.2
2018-10-17 16:52 UTC
This package is not auto-updated.
Last update: 2025-03-13 19:51:31 UTC
README
中文档案
Angel微信 是基于Angel框架的公众号开发框架
安装
请先使用Composer安装Angel框架:
composer create-project angel-project/framework .
然后安装微信拓展:
composer require angel-project/wechat
公众号开发
一个基本的监听/反馈模板:
build::post('your/url',function(){ $wx = new angel\wechat($appid,$secret,$token); //初始化微信object $wx->listen('text','hi',function($input,$wx){ $wx->return('text',[ 'to' => $input->FromUserName, 'content' => 'hello!' ]); }); //当用户输入hi时,返回字符串hello! $wx->listen('event','subscribe',function($input,$wx){ $wx->return('news',[ 'to' => $input->FromUserName, 'articles' => [[ 'title' => 'hi!', 'description' => 'long time no see', 'picurl' => 'yoururl.com/img.jpg', 'url' => 'yoururl.com' ]] ]); //返回主题 }); //当用户关注时触发,返回图文消息 $wx->run(); //执行监听 });
listen()方法有三个输入:
- 监听方法:目前支持text(文字输入)、event(事件触发)
- 触发事件:文字支持字符串和正则表达式匹配,事件支持SCAN(扫码)、subscribe(关注)、CLICK(点击)触发。当用户输入不满足任何规则时,当触发事件为'empty'。
- 触发后执行的代码:该function输入两个值:用户输入和微信object。你可以通过用户输入来获取所有用户传送至服务器的指令;微信object让你在function继续自由使用微信方法。
创建菜单
$wx = new angel\wechat($appid,$secret,$token); //初始化微信object $menu = [[ 'type' => 'click', 'name' => '欢迎光临', 'key' => 'welcome' ]]; //生成一个click时间菜单,具体创建菜单指令请参考微信开发者档案 $at = $wx->access_token(); //获取access token $wx->menu($at,$menu); //生成菜单
English Doc
Angel WeChat is a WeChat plugin based on Angel Framework
Installation
First, install Angel Framework with Composer using the following command:
composer create-project angel-project/framework .
Then, install Angel WeChat package:
composer require angel-project/wechat