Laravel 使用 EasyWechat 管理多公众号
第一次写专栏文章,如代码规范有错误或者不周全的地方,请社区朋友们指正。如果有更好的方法,请留言给我,谢谢各位大神。
这篇文章旨在Laravel使用EasyWechat扩展进行多公众号管理,具体步骤如下:
- 创建公众号参数表
- 创建微信控制器
- 创建辅助函数
- 配置路由
- 设置路由忽略
首先我们新建一个Laravel项目,配置好数据库参数,引入Easywechat扩展(在此感谢安正超)
然后创建数据表:
php artisan make:model Wechat -m
来在生成的wechats的migration文件里写入微信相关数据字段:
public function up()
{
Schema::create('wechats', function (Blueprint $table) {
$table->increments('id');
$table->string('aid')->nullable();
$table->string('wechat_app_id')->nullable(); //微信公众号设置参数
$table->string('wechat_secret')->nullable();
$table->string('wechat_token')->nullable();
$table->string('wechat_aes_key')->nullable();
$table->string('pay_mch_id')->nullable(); //微信支付设置参数
$table->string('pay_api_key')->nullable();
$table->string('pay_cert_path')->nullable();
$table->string('pay_key_path')->nullable();
$table->string('op_app_id')->nullable(); //微信开放平台设置参数
$table->string('op_secret')->nullable();
$table->string('op_token')->nullable();
$table->string('op_aes_key')->nullable();
$table->string('work_corp_id')->nullable(); //微信企业号设置参数
$table->string('work_agent_id')->nullable();
$table->string('work_secret')->nullable();
$table->timestamps();
