MassCommand.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <?php
  2. namespace App\Console\Commands\Wechat;
  3. use Illuminate\Console\Command;
  4. class MassCommand extends Command
  5. {
  6. /**
  7. * The name and signature of the console command.
  8. *
  9. * @var string
  10. */
  11. protected $signature = 'wechat:mass';
  12. /**
  13. * The console command description.
  14. *
  15. * @var string
  16. */
  17. protected $description = '微信群发接口';
  18. /**
  19. * Create a new command instance.
  20. *
  21. * @return void
  22. */
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. }
  27. private $publicId;
  28. private $sex;
  29. private $url = "https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=";
  30. private $medias = [
  31. "gh_b598cb7474d8" => [
  32. "type" => "服务号",
  33. "media_id" => "kd_b598cb7474d8"
  34. ],
  35. "gh_43ba50c16fba" => [
  36. "type" => "服务号",
  37. "media_id" => "kd_fuwuhaoqunfa"
  38. ],
  39. "gh_6a208af55d22" => [
  40. "type" => "服务号",
  41. "media_id" => "kd_fuwuhaoqunfa"
  42. ],
  43. // "gh_c94c95866ca5"=>[
  44. // "type"=>"服务号",
  45. // "media_id"=>"kd_fuwuhaoqunfa"
  46. // ],
  47. // "gh_8ad154093fc4"=>[
  48. // "type"=>"订阅号",
  49. // "media_id"=>"kd_dingyuequnfa"
  50. // ],
  51. "gh_67bc8afa5ed9" => [
  52. "type" => "订阅号",
  53. "media_id" => "kd_dingyuequnfa"
  54. ],
  55. "gh_4167f0d2c89d" => [
  56. "type" => "订阅号",
  57. "media_id" => "kd_dingyuequnfa"
  58. ],
  59. "gh_04406cb77cf5" => [
  60. "type" => "订阅号",
  61. "media_id" => "kd_dingyuequnfa"
  62. ],
  63. "gh_dbbe2df61ccf" => [
  64. "type" => "订阅号",
  65. "media_id" => "kd_dingyuequnfa"
  66. ],
  67. ];
  68. private function getUrl()
  69. {
  70. return $this->url . $this->medias[$this->publicId]['media_id'];
  71. }
  72. private function getContent()
  73. {
  74. switch ($this->sex) {
  75. case "男":
  76. return "欢迎报名本期72小时恋爱活动☞【<a href='{$this->getUrl()}'>脱单合伙人</a>】☜
  77. 双十一除了是购物节还是脱单节,所以?在场的小哥哥有没有愿意和我一起脱单呀?
  78. <a href='{$this->getUrl()}'>【点此一起脱单】</a>
  79. <a href='{$this->getUrl()}'>【点此继续单身】</a>
  80. 点击下方蓝字查看本周活动优化
  81. ↓ ↓
  82. <a href='https://mp.weixin.qq.com/s/qimtN6gK1MRI-0HznQQOjA'>本周活动优化详情</a>";
  83. case "女":
  84. return "今日惊喜:101款小哥哥正在“预售”,赶快领取你的心动选手吧!
  85. <a href='{$this->getUrl()}'>【点此领取】</a>
  86. <a href='{$this->getUrl()}'>【残忍拒绝】</a>
  87. 点击下方蓝字查看本周活动优化
  88. ↓ ↓
  89. <a href='https://mp.weixin.qq.com/s/qimtN6gK1MRI-0HznQQOjA'>本周活动优化详情</a>";
  90. case "未知":
  91. return "欢迎报名本期72小时恋爱活动☞<a href='{$this->getUrl()}'>【脱单合伙人】</a>☜
  92. <a href='{$this->getUrl()}'>【点此领取小哥哥】</a>
  93. <a href='{$this->getUrl()}'>【点此领取小姐姐】</a>
  94. 点击下方蓝字查看本周活动优化
  95. ↓ ↓
  96. <a href='https://mp.weixin.qq.com/s/qimtN6gK1MRI-0HznQQOjA'>本周活动优化详情</a>";
  97. break;
  98. }
  99. }
  100. /**
  101. * Execute the console command.
  102. *
  103. * @return mixed
  104. */
  105. public function handle()
  106. {
  107. $option = $this->choice('请选择执行操作', [
  108. 'preview' => '预览',
  109. 'tag' => '男女标签发送',
  110. 'hebeikeda' => '河北科大的标签发送',
  111. 'batch' => '所有用户发送',
  112. 'all' => '全部公众号发送',
  113. ]);
  114. switch ($option) {
  115. case "preview":
  116. $this->publicId = $this->ask("公众号ID");
  117. $this->sex = $this->choice('请选择性别', [
  118. '1' => '男',
  119. '2' => '女',
  120. '0' => '未知',
  121. ]);
  122. $this->preview();
  123. break;
  124. case "tag":
  125. $this->publicId = $this->ask("公众号ID");
  126. $this->sex = $this->choice('请选择性别', [
  127. '1' => '男',
  128. '2' => '女',
  129. '0' => '未知',
  130. ]);
  131. $this->sendTag();
  132. break;
  133. case "hebeikeda":
  134. $this->publicId = "gh_b598cb7474d8";
  135. $this->sex = $this->choice('请选择标签', [
  136. '1' => '男',
  137. '2' => '女',
  138. '0' => '未知',
  139. ]);
  140. $this->sendHeBeiTag();
  141. break;
  142. case "batch":
  143. $this->publicId = $this->ask("公众号ID");
  144. $this->sex = $this->choice('请选择性别', [
  145. '1' => '男',
  146. '2' => '女',
  147. '0' => '未知',
  148. ]);
  149. $this->batch();
  150. break;
  151. case "all":
  152. if ($this->confirm('确认发送周二群发功能??????')) {
  153. $this->sendAll();
  154. }
  155. break;
  156. }
  157. }
  158. public function preview()
  159. {
  160. $result = \WeChat::Mass($this->publicId)->preview("CCAV---BOSS", "text", [
  161. 'content' => $this->getContent()
  162. ]);
  163. dd($result);
  164. }
  165. public function sendHeBeiTag()
  166. {
  167. switch ($this->sex) {
  168. case "男":
  169. $tagId = \WeChat::Tags($this->publicId)->get("河北科大-男");
  170. if (!$tagId) {
  171. dd("没有此标签");
  172. }
  173. dump($tagId);
  174. $result = \WeChat::Mass($this->publicId)->sendTag(
  175. $tagId,
  176. 'text',
  177. ['content' => $this->getContent()]
  178. );
  179. dump($result);
  180. break;
  181. case "女":
  182. $tagId = \WeChat::Tags($this->publicId)->get("河北科大-女");
  183. if (!$tagId) {
  184. dd("没有此标签");
  185. }
  186. dump($tagId);
  187. $result = \WeChat::Mass($this->publicId)->sendTag(
  188. $tagId,
  189. 'text',
  190. ['content' => $this->getContent()]
  191. );
  192. dump($result);
  193. break;
  194. case "未知":
  195. $tagId = \WeChat::Tags($this->publicId)->get("河北科大-无");
  196. if (!$tagId) {
  197. dd("没有此标签");
  198. }
  199. dump($tagId);
  200. $result = \WeChat::Mass($this->publicId)->sendTag(
  201. $tagId,
  202. 'text',
  203. ['content' => $this->getContent()]
  204. );
  205. dump($result);
  206. break;
  207. }
  208. }
  209. public function sendTag()
  210. {
  211. switch ($this->sex) {
  212. case "男":
  213. $tagId = \WeChat::Tags($this->publicId)->get("性别-男");
  214. if (!$tagId) {
  215. dd("没有此标签");
  216. }
  217. $result = \WeChat::Mass($this->publicId)->sendTag(
  218. $tagId,
  219. 'text',
  220. ['content' => $this->getContent()]
  221. );
  222. dump($tagId);
  223. dump($result);
  224. break;
  225. case "女":
  226. $tagId = \WeChat::Tags($this->publicId)->get("性别-女");
  227. if (!$tagId) {
  228. dd("没有此标签");
  229. }
  230. $result = \WeChat::Mass($this->publicId)->sendTag(
  231. $tagId,
  232. 'text',
  233. ['content' => $this->getContent()]
  234. );
  235. dump($tagId);
  236. dump($result);
  237. break;
  238. case "未知":
  239. $tagId = \WeChat::Tags($this->publicId)->get("性别-未知");
  240. if (!$tagId) {
  241. dd("没有此标签");
  242. }
  243. $result = \WeChat::Mass($this->publicId)->sendTag(
  244. $tagId,
  245. 'text',
  246. ['content' => $this->getContent()]
  247. );
  248. dump($tagId);
  249. dump($result);
  250. break;
  251. }
  252. }
  253. public function batch()
  254. {
  255. $result = \WeChat::Mass($this->publicId)
  256. ->sendAll(
  257. 'text',
  258. ['content' => $this->getContent()]
  259. );
  260. dump($result);
  261. }
  262. public function sendAll()
  263. {
  264. foreach ($this->medias as $publicId => $media) {
  265. $this->publicId = $publicId;
  266. switch ($media['type']) {
  267. case "服务号":
  268. $this->sex = "男";
  269. dump($this->publicId . "------------" . $this->sex);
  270. $this->sendTag();
  271. $this->sex = "女";
  272. dump($this->publicId . "------------" . $this->sex);
  273. $this->sendTag();
  274. $this->sex = "未知";
  275. dump($this->publicId . "------------" . $this->sex);
  276. $this->sendTag();
  277. break;
  278. case "订阅号":
  279. $this->sex = "未知";
  280. dump($this->publicId . "------------" . "all");
  281. $this->batch();
  282. break;
  283. }
  284. dump($this->publicId);
  285. dump("end");
  286. }
  287. }
  288. }