延续上一篇「12步」制做 Laravel 插件 (一),今天咱们就来完成后续的步骤:写好的插件部署到「Packagist」上。php
具体只须要如下「3」个步骤:android
What is Packagist? Packagist is the default Composer package repository. It lets you find packages and lets Composer know where to get the code from. You can use Composer to manage your project or libraries' dependencies.laravel
You can find the packagist.org source on GitHub.git
摘录:https://packagist.org/aboutgithub
因为插件代码选择托管到 Github 上,因此建议直接使用 Github 帐号登陆。bootstrap
注册成功后,就能够拿到用户名和 API Token,用于关联 Github 插件代码。bash
新建 Github 项目,最好与插件同名: 微信
在 Laravel 项目同级路径下 packages 放着就是咱们的插件代码「fanly/msgrobot」markdown
提交代码:app
提交代码后,在 Github 项目 setting 中增长「Packagist」服务
这里就是填入「Packagist」的用户名和 API Token。
只要在 Github 项目中关联了Packagist 服务,就能够在 Packagist 后台「submit」该插件
输入插件 git 地址,就能够提交了;
此时,若是没对代码进行 tag 控制,获得插件是「dev-master」版本的。因此须要对插件进行版本设置。
在「git push」代码后,继续
这样咱们就发布了0.0.1版本的插件了。
有了插件,咱们天然须要测试,看看运行效果了。
咱们选择利用 Lumen 项目试试,安装插件
在 bootstrap/app.php 引入注册插件 ServiceProvider:
$app->register(Fanly\Msgrobot\FanlyMsgrobotServiceProvider::class);
复制代码
咱们写一个 test,试试效果,先建立独立跳转 ActionCard 类型消息,而后给已建立的机器人对应的「access_token」钉钉群推送此消息
// text
$text = new Text('hello fanly/msgrobot package');
Msgrobot::accessToken('cb36a3c3cab1242b94516d026a02d909f1611ec048d89c93cb3e1132f08b4e')
->message($text)
->send();
// link
$link = new Link([
'text' => 'link text',
'title' => 'link title',
'picUrl' => 'http://f.hiphotos.baidu.com/image/pic/item/503d269759ee3d6db032f61b48166d224e4ade6e.jpg',
'messageUrl' => 'http://f.hiphotos.baidu.com/image/pic/item/503d269759ee3d6db032f61b48166d224e4ade6e.jpg'
]);
Msgrobot::accessToken('cb36a3c3cab1242b94516d026a02d909f1611ec048d89c93cb3e1132f08b4e')
->message($link)
->send();
// markdown
$md = new Markdown([
'title' => 'link text',
'text' => "#### 杭州天气 @156xxxx8827\n > 9度,西北风1级,空气良89,相对温度73%\n\n> \n> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n"
]);
Msgrobot::accessToken('cb36a3c3cab1242b94516d026a02d909f1611ec048d89c93cb3e1132f08b4e')
->message($md)
->send();
// Single ActionCard
$sac = new SingleActionCard([
'title' => 'link title',
'text' => ' ### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实能够追溯到 20 年前苹果一个创建咖啡馆的计划',
'hideAvatar' => 0,
'btnOrientation' => 0,
'singleTitle' => '阅读原文',
'singleURL' => 'http://f.hiphotos.baidu.com/image/pic/item/503d269759ee3d6db032f61b48166d224e4ade6e.jpg'
]);
Msgrobot::accessToken('cb36a3c3cab1242b94516d026a02d909f1611ec048d89c93cb3e1132f08b4e')
->message($sac)
->send();
// More ActionCard
$btns = [
new ActionCardBtn([
'title' => '内容不错',
'actionURL' => 'http://f.hiphotos.baidu.com/image/pic/item/503d269759ee3d6db032f61b48166d224e4ade6e.jpg'
]),
new ActionCardBtn([
'title' => '不感兴趣',
'actionURL' => 'http://f.hiphotos.baidu.com/image/pic/item/503d269759ee3d6db032f61b48166d224e4ade6e.jpg'
])
];
$mac = new MoreActionCard([
'title' => 'link title',
'text' => ' ### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实能够追溯到 20 年前苹果一个创建咖啡馆的计划',
'hideAvatar' => 0,
'btnOrientation' => 0,
'btns' => $btns
]);
Msgrobot::accessToken('cb36a3c3cab1242b94516d026a02d909f1611ec048d89c93cb3e1132f08b4e')
->message($mac)
->send();
// FeedCard
$links = [
new FeedCardLink([
'title' => "时代的火车向前开",
"messageURL" => "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI",
"picURL" => "http://f.hiphotos.baidu.com/image/pic/item/503d269759ee3d6db032f61b48166d224e4ade6e.jpg"
]),
new FeedCardLink([
'title' => "时代的火车向前开",
"messageURL" => "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI",
"picURL" => "http://f.hiphotos.baidu.com/image/pic/item/503d269759ee3d6db032f61b48166d224e4ade6e.jpg"
])
];
$fc = new FeedCard($links);
Msgrobot::accessToken('cb36a3c3cab1242b94516d026a02d909f1611ec048d89c93cb3e1132f08b4e')
->message($fc)
->send();
复制代码
经过对这两篇文章的梳理和学习,相信咱们本身对如何制做 Laravel 插件有了比较直观的了解了,至于插件代码的质量和 Laravel 技术的理解的深度,有赖于继续专研。
--此插件--更多做为学习使用
最后,今天是大年初六,祝你们今年六六六!!!
1. 微信 SDK for Laravel, 基于 overtrue/wechat:https://github.com/overtrue/laravel-wechat
2. 本文章插件地址:https://packagist.org/packages/fanly/msgrobot
3. 本文章插件源代码:https://github.com/fanly/msgrobot