123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <?php
- namespace App\Console\Commands\Wechat;
- use Illuminate\Console\Command;
- class MassCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'wechat:mass';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '微信群发接口';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- private $publicId;
- private $sex;
- private $url = "https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=";
- private $medias = [
- "gh_b598cb7474d8" => [
- "type" => "服务号",
- "media_id" => "kd_b598cb7474d8"
- ],
- "gh_43ba50c16fba" => [
- "type" => "服务号",
- "media_id" => "kd_fuwuhaoqunfa"
- ],
- "gh_6a208af55d22" => [
- "type" => "服务号",
- "media_id" => "kd_fuwuhaoqunfa"
- ],
- // "gh_c94c95866ca5"=>[
- // "type"=>"服务号",
- // "media_id"=>"kd_fuwuhaoqunfa"
- // ],
- // "gh_8ad154093fc4"=>[
- // "type"=>"订阅号",
- // "media_id"=>"kd_dingyuequnfa"
- // ],
- "gh_67bc8afa5ed9" => [
- "type" => "订阅号",
- "media_id" => "kd_dingyuequnfa"
- ],
- "gh_4167f0d2c89d" => [
- "type" => "订阅号",
- "media_id" => "kd_dingyuequnfa"
- ],
- "gh_04406cb77cf5" => [
- "type" => "订阅号",
- "media_id" => "kd_dingyuequnfa"
- ],
- "gh_dbbe2df61ccf" => [
- "type" => "订阅号",
- "media_id" => "kd_dingyuequnfa"
- ],
- ];
- private function getUrl()
- {
- return $this->url . $this->medias[$this->publicId]['media_id'];
- }
- private function getContent()
- {
- switch ($this->sex) {
- case "男":
- return "欢迎报名本期72小时恋爱活动☞【<a href='{$this->getUrl()}'>脱单合伙人</a>】☜
- 双十一除了是购物节还是脱单节,所以?在场的小哥哥有没有愿意和我一起脱单呀?
- <a href='{$this->getUrl()}'>【点此一起脱单】</a>
- <a href='{$this->getUrl()}'>【点此继续单身】</a>
- 点击下方蓝字查看本周活动优化
- ↓ ↓
- <a href='https://mp.weixin.qq.com/s/qimtN6gK1MRI-0HznQQOjA'>本周活动优化详情</a>";
- case "女":
- return "今日惊喜:101款小哥哥正在“预售”,赶快领取你的心动选手吧!
- <a href='{$this->getUrl()}'>【点此领取】</a>
- <a href='{$this->getUrl()}'>【残忍拒绝】</a>
- 点击下方蓝字查看本周活动优化
- ↓ ↓
- <a href='https://mp.weixin.qq.com/s/qimtN6gK1MRI-0HznQQOjA'>本周活动优化详情</a>";
- case "未知":
- return "欢迎报名本期72小时恋爱活动☞<a href='{$this->getUrl()}'>【脱单合伙人】</a>☜
- <a href='{$this->getUrl()}'>【点此领取小哥哥】</a>
- <a href='{$this->getUrl()}'>【点此领取小姐姐】</a>
- 点击下方蓝字查看本周活动优化
- ↓ ↓
- <a href='https://mp.weixin.qq.com/s/qimtN6gK1MRI-0HznQQOjA'>本周活动优化详情</a>";
- break;
- }
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $option = $this->choice('请选择执行操作', [
- 'preview' => '预览',
- 'tag' => '男女标签发送',
- 'hebeikeda' => '河北科大的标签发送',
- 'batch' => '所有用户发送',
- 'all' => '全部公众号发送',
- ]);
- switch ($option) {
- case "preview":
- $this->publicId = $this->ask("公众号ID");
- $this->sex = $this->choice('请选择性别', [
- '1' => '男',
- '2' => '女',
- '0' => '未知',
- ]);
- $this->preview();
- break;
- case "tag":
- $this->publicId = $this->ask("公众号ID");
- $this->sex = $this->choice('请选择性别', [
- '1' => '男',
- '2' => '女',
- '0' => '未知',
- ]);
- $this->sendTag();
- break;
- case "hebeikeda":
- $this->publicId = "gh_b598cb7474d8";
- $this->sex = $this->choice('请选择标签', [
- '1' => '男',
- '2' => '女',
- '0' => '未知',
- ]);
- $this->sendHeBeiTag();
- break;
- case "batch":
- $this->publicId = $this->ask("公众号ID");
- $this->sex = $this->choice('请选择性别', [
- '1' => '男',
- '2' => '女',
- '0' => '未知',
- ]);
- $this->batch();
- break;
- case "all":
- if ($this->confirm('确认发送周二群发功能??????')) {
- $this->sendAll();
- }
- break;
- }
- }
- public function preview()
- {
- $result = \WeChat::Mass($this->publicId)->preview("CCAV---BOSS", "text", [
- 'content' => $this->getContent()
- ]);
- dd($result);
- }
- public function sendHeBeiTag()
- {
- switch ($this->sex) {
- case "男":
- $tagId = \WeChat::Tags($this->publicId)->get("河北科大-男");
- if (!$tagId) {
- dd("没有此标签");
- }
- dump($tagId);
- $result = \WeChat::Mass($this->publicId)->sendTag(
- $tagId,
- 'text',
- ['content' => $this->getContent()]
- );
- dump($result);
- break;
- case "女":
- $tagId = \WeChat::Tags($this->publicId)->get("河北科大-女");
- if (!$tagId) {
- dd("没有此标签");
- }
- dump($tagId);
- $result = \WeChat::Mass($this->publicId)->sendTag(
- $tagId,
- 'text',
- ['content' => $this->getContent()]
- );
- dump($result);
- break;
- case "未知":
- $tagId = \WeChat::Tags($this->publicId)->get("河北科大-无");
- if (!$tagId) {
- dd("没有此标签");
- }
- dump($tagId);
- $result = \WeChat::Mass($this->publicId)->sendTag(
- $tagId,
- 'text',
- ['content' => $this->getContent()]
- );
- dump($result);
- break;
- }
- }
- public function sendTag()
- {
- switch ($this->sex) {
- case "男":
- $tagId = \WeChat::Tags($this->publicId)->get("性别-男");
- if (!$tagId) {
- dd("没有此标签");
- }
- $result = \WeChat::Mass($this->publicId)->sendTag(
- $tagId,
- 'text',
- ['content' => $this->getContent()]
- );
- dump($tagId);
- dump($result);
- break;
- case "女":
- $tagId = \WeChat::Tags($this->publicId)->get("性别-女");
- if (!$tagId) {
- dd("没有此标签");
- }
- $result = \WeChat::Mass($this->publicId)->sendTag(
- $tagId,
- 'text',
- ['content' => $this->getContent()]
- );
- dump($tagId);
- dump($result);
- break;
- case "未知":
- $tagId = \WeChat::Tags($this->publicId)->get("性别-未知");
- if (!$tagId) {
- dd("没有此标签");
- }
- $result = \WeChat::Mass($this->publicId)->sendTag(
- $tagId,
- 'text',
- ['content' => $this->getContent()]
- );
- dump($tagId);
- dump($result);
- break;
- }
- }
- public function batch()
- {
- $result = \WeChat::Mass($this->publicId)
- ->sendAll(
- 'text',
- ['content' => $this->getContent()]
- );
- dump($result);
- }
- public function sendAll()
- {
- foreach ($this->medias as $publicId => $media) {
- $this->publicId = $publicId;
- switch ($media['type']) {
- case "服务号":
- $this->sex = "男";
- dump($this->publicId . "------------" . $this->sex);
- $this->sendTag();
- $this->sex = "女";
- dump($this->publicId . "------------" . $this->sex);
- $this->sendTag();
- $this->sex = "未知";
- dump($this->publicId . "------------" . $this->sex);
- $this->sendTag();
- break;
- case "订阅号":
- $this->sex = "未知";
- dump($this->publicId . "------------" . "all");
- $this->batch();
- break;
- }
- dump($this->publicId);
- dump("end");
- }
- }
- }
|