MCPcopy Create free account
hub / github.com/CoderOpen/waimai / ChiHe

Class ChiHe

app/Console/Commands/ChiHe.php:10–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class ChiHe extends Command
11{
12 /**
13 * 控制台命令 signature 的名称。
14 * $signature = 'swoole:send {user}'
15 * @var string
16 */
17 protected $signature = 'chihe:send-msg';
18 /**
19 * 控制台命令说明。
20 *
21 * @var string
22 */
23 protected $description = 'send email to sale something';
24
25 public function __construct()
26 {
27 parent::__construct();
28 }
29
30 /**
31 * 执行控制台命令。
32 *
33 * @return mixed
34 */
35 public function handle()
36 {
37 if (date('H:i:') === '19:36:') {
38 $msg = Subscribe::where('is_send', 2)->get()->toArray();
39 if ($msg) {
40 //保证每个人每天只发一次
41 $hasSendUserIds = [];
42 foreach ($msg as $k => $v) {
43 $userId = $v['user_id'];
44 if (in_array($userId, $hasSendUserIds)) {
45 continue;
46 }
47 $user = User::where('id', $userId)->first();
48 $templateId = $v['template_id'];
49 $data = [
50 'template_id' => $templateId, // 所需下发的订阅模板id
51 'touser' => $user->open_id, // 接收者(用户)的 openid
52 'page' => '/pages/index/index', // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
53 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
54 'thing4' => [
55 'value' => '又到了吃饭时刻,快来领吃喝炒鸡优惠券啦!',
56 ],
57 'thing8' => [
58 'value' => '红包天天领,天天能提醒,叫外卖省省省',
59 ],
60 ],
61 ];
62 $config = 'chi_he';
63 $app = \EasyWeChat::miniProgram($config); // 小程序
64 $res = $app->subscribe_message->send($data);
65
66 $subscribe = Subscribe::where('id', $v['id'])->first();
67 $subscribe->is_send = 1;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected