lock
This commit is contained in:
@@ -91,15 +91,18 @@ class SendWechatTemp implements Consumer
|
||||
Log::info('模版消息用户列表' . json_encode($user_list));
|
||||
if($user_list) {
|
||||
foreach ($user_list as $k => $user) {
|
||||
// 发送模版消息(公众号和小程序都发送)
|
||||
if(!empty($user['wechat_ac_open_id'])) {
|
||||
$config = [
|
||||
'app_id' => config('cons.app_id'),
|
||||
'secret' => config('cons.secret'),
|
||||
'response_type' => 'array',
|
||||
];
|
||||
$app = Factory::officialAccount($config);
|
||||
// 公众号存放 AccessToken
|
||||
$acc_token = Redis::get('wx:ac:AccessToken');
|
||||
if($acc_token) {
|
||||
// 公众号发送模版消息通知
|
||||
$app = Factory::officialAccount($config);
|
||||
if ($acc_token) {
|
||||
$app['access_token']->setToken($acc_token);
|
||||
}
|
||||
$wechat_res = $app->template_message->send([
|
||||
@@ -116,38 +119,71 @@ class SendWechatTemp implements Consumer
|
||||
'thing16' => $record['address'],
|
||||
],
|
||||
]);
|
||||
Log::info('公众号模版发送结果' . json_encode($wechat_res));
|
||||
}else {
|
||||
Log::info('用户' . $user['u_user_id'] . 'wechat_ac_open_id为空。不发送');
|
||||
}
|
||||
|
||||
if(!empty($user['wechat_open_id'])) {
|
||||
$mini_config = [
|
||||
'app_id' => config('cons.mini_app_id'),
|
||||
'secret' => config('cons.mini_secret'),
|
||||
'response_type' => 'array',
|
||||
];
|
||||
$mini_app = Factory::miniProgram($mini_config);
|
||||
// 小程序存放 AccessToken
|
||||
$mini_token = Redis::get('wx:mini:AccessToken');
|
||||
if($mini_token) {
|
||||
$mini_app['access_token']->setToken($acc_token);
|
||||
}
|
||||
// 小程序发送模版消息通知
|
||||
$mini_wechat_res = $mini_app->subscribe_message->send([
|
||||
'template_id' => 'JGPAGmqcPEgWB6mvAl0SC5cMqr5H5Qjcim8JCpHAZd0',
|
||||
'touser' => $user['wechat_open_id'],
|
||||
'page' => 'pages/index/index',
|
||||
'data' => [
|
||||
'thing1' => [
|
||||
'value' => $record['shop_name'],
|
||||
],
|
||||
'thing2' => [
|
||||
'value' => $record['activity_detail'],
|
||||
],
|
||||
'time3' => [
|
||||
'value' => $record['activity_time'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
Log::info('小程序订阅消息发送结果' . json_encode($mini_wechat_res));
|
||||
}else {
|
||||
Log::info('用户' . $user['u_user_id'] . 'wechat_open_id为空。不发送');
|
||||
}
|
||||
if(!empty($user['wechat_open_id']) || !empty($user['wechat_ac_open_id'])) {
|
||||
Db::table('ac_push_event')->where(['id' => $record['id']])->update([
|
||||
'status' => 1,
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
'send_time' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
Log::info('模版发送结果' . json_encode($wechat_res));
|
||||
if($wechat_res['errcode'] == 0 && $wechat_res['errmsg'] == 'ok') {
|
||||
Db::startTrans();
|
||||
Log::info('OKKKKK了');
|
||||
Db::table('sms_push_event_record')->insert([
|
||||
'type' => 'ac',
|
||||
'shop_id' => $record['shop_id'],
|
||||
'event_id' => $record['id'],
|
||||
'user_id' => $user['u_user_id'],
|
||||
'user_phone' => $user['phone'],
|
||||
'biz_id' => '',
|
||||
'send_time' => date('Y-m-d H:i:s'),
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'status' => 2,
|
||||
]);
|
||||
Db::table('ac_push_event')->where(['id' => $record['id']])->update([
|
||||
'status' => 2,
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
'send_time' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
Db::commit();
|
||||
}
|
||||
}else {
|
||||
Log::info('用户' . $user['u_user_id'] . 'open_id 为空。不发送');
|
||||
}
|
||||
sleep(1);
|
||||
if((isset($wechat_res) && $wechat_res['errcode'] == 0 && $wechat_res['errmsg'] == 'ok') || (isset($mini_wechat_res) && $mini_wechat_res['errcode'] == 0 && $mini_wechat_res['errmsg'] == 'ok')) {
|
||||
Db::startTrans();
|
||||
Db::table('sms_push_event_record')->insert([
|
||||
'type' => 'ac',
|
||||
'shop_id' => $record['shop_id'],
|
||||
'event_id' => $record['id'],
|
||||
'user_id' => $user['u_user_id'],
|
||||
'user_phone' => $user['phone'],
|
||||
'biz_id' => '',
|
||||
'send_time' => date('Y-m-d H:i:s'),
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'status' => 2,
|
||||
]);
|
||||
Db::table('ac_push_event')->where(['id' => $record['id']])->update([
|
||||
'status' => 2,
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
'send_time' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
Db::commit();
|
||||
}
|
||||
}
|
||||
}else {
|
||||
Log::info('【发送营销短信】无目标用户---》' . $record['user_id']);
|
||||
|
||||
Reference in New Issue
Block a user