作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

合并分支 'heshupeng' 到 'master'

模板消息测试



查看合并请求 !311
... ... @@ -159,6 +159,16 @@ class Store extends Backend
}
}
}
// 发送模板消息
$send_data = array(
"first" => '恭喜您,商户申请审核通过!',
"keyword1" => $row->store_name,
"keyword2" => date('Y-m-s',time()),
"remark" => '点击进入商户后台',
);
$openid = Db::name('third')->where('user_id',$row->user_id)->value('openid');
$url = 'http://community.t.brotop.cn/admininfo.php';
(new \app\common\controller\Api)->wxsendmessage($openid,$send_data,config('option.template')['store_pass'],$url);
}
if($params['status'] == 4) {
// 审核不通过,执行退款操作
... ...
... ... @@ -122,6 +122,19 @@ class StoreInform extends Backend
Db::startTrans();
try {
$result = $row->save();
$apiController = new \app\common\controller\Api();
$openid = Db::name('third')->where('user_id',$row->user_id)->value('openid');
$url = config('option.vue_url') . '/releasedetal?id='.$row->id;
if($params['status'] == 2) {
// 发送模板消息
$send_data = array(
"first" => '您的广告投放已出结果。',
"keyword1" => $row->content,
"keyword2" => '审核通过',
"remark" => '点击查看详情!',
);
$apiController->wxsendmessage($openid,$send_data,config('option.template')['ad_pass'],$url);
}
if($params['status'] == 4) {
$user_model = new \app\admin\model\User();
$user = $user_model->where('id', $row->user_id)->find();
... ... @@ -138,6 +151,16 @@ class StoreInform extends Backend
$result_log = Db::name('user_score_log')->insertGetId($log);
// 返还用户余额
$result_user = $user_model->where('id', $user['id'])->setInc('score', $row->score);
// 发送模板消息
$nickname = Db::name('user')->where('id',$row->user_id)->value('nickname');
$send_data = array(
"first" => '抱歉!您的广告 审核失败。',
"keyword1" => $row->content,
"keyword2" => $nickname,
"keyword3" => '您的广告未通过',
"remark" => '您的广告未通过审核, 请您重新申请。',
);
$apiController->wxsendmessage($openid,$send_data,config('option.template')['ad_fail'],$url);
}
Db::commit();
} catch (ValidateException $e) {
... ...
... ... @@ -119,6 +119,18 @@ class UserHouse extends Backend
// 新增社区用户数
if ($params['status'] == 2) {
Db::name('house')->where('id',$row->house_id)->setInc('bindnum');
// 发送模板消息
$send_data = array(
"first" => '尊敬的业主,您已成功认证为实名房间业主身份,认证信息如下:',
"keyword1" => $row->name,
"keyword2" => $row->phone,
"remark" => '请仔细核对以上信息,如有不符,请与相关物业人员反馈,谢谢!',
);
$openid = Db::name('third')->where('user_id',$row->user_id)->value('openid');
// 把用户的当前社区改为审核成功的小区
Db::name('user')->where('id',$row->user_id)->setField('house_id',$row->house_id);
$url = config('option.vue_url') . '/affiche';
(new \app\common\controller\Api)->wxsendmessage($openid,$send_data,config('option.template')['license'],$url);
}
$result = $row->save();
Db::commit();
... ...
... ... @@ -527,6 +527,17 @@ class House extends Api
$this->error('申请失败');
}else{
Db::name('user')->where('id',$param['user_id'])->update(['mobile'=>$param['phone']]);
// 发送模板消息
$user = $this->auth->getUser();
$send_data = array(
"first" => '您好,您有一个未处理的申请!',
"keyword1" => $user['nickname'],
"keyword2" => $user['mobile'],
"keyword3" => date('Y年m月s日 H:i',time()),
"remark" => '请尽快处理!',
);
$url = 'http://community.t.brotop.cn/admininfo.php';
(new \app\common\controller\Api)->wxsendmessage('otlkQ0l4L3wsmz8dhDIbHJQVJnI8',$send_data,config('option.template')['examine'],$url);
$this->success('成功');
}
}else{
... ...
... ... @@ -430,17 +430,18 @@ class HouseAdmin extends Api
if(!empty($user_id_arr)){
$house_name = House::where('id',$post['house_id'])->value('name');
$send_data = array(
"first" => '您绑定的社区【'.$house_name.'】发布了一条公告',
'keyword1' => $post['title'],
"first" => $post['title'],
"keyword1" => $post['title'],
"keyword2" => date('Y-m-s H:i:s',time()),
"remark" => '',
"keyword3" => $post['content'],
"remark" => $post['content'],
);
foreach ($user_id_arr as $user_id) {
$openid = Db::name('third')->where('user_id',$user_id)->value('openid');
// 把用户的当前社区改为发送公告的小区
Db::name('user')->where('id',$user_id)->setField('house_id',$post['house_id']);
$url = config('option.vue_url') . '/affiche';
$this->wxsendmessage($openid,$send_data,config('option.template')['msg'],$url);
$this->wxsendmessage($openid,$send_data,config('option.template')['house_notice'],$url);
}
}
Db::commit();
... ...
... ... @@ -362,6 +362,17 @@ class Store extends Api
$param['user_id'] = $this->auth->id;
$model = new StoreApply();
$result = $model->add($param);
// 发送模板消息
$user = $this->auth->getUser();
$send_data = array(
"first" => '您好,您有一个未处理的申请!',
"keyword1" => $user['nickname'],
"keyword2" => $user['mobile'],
"keyword3" => date('Y年m月s日 H:i',time()),
"remark" => '请尽快处理!',
);
$url = 'http://community.t.brotop.cn/admininfo.php';
(new \app\common\controller\Api)->wxsendmessage('otlkQ0l4L3wsmz8dhDIbHJQVJnI8',$send_data,config('option.template')['examine'],$url);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
... ... @@ -759,6 +770,17 @@ class Store extends Api
);
$res_log = Db::name('user_score_log')->insert($insert_data);
}
// 发送模板消息
$user = $this->auth->getUser();
$send_data = array(
"first" => '您好,您有一个未处理的申请!',
"keyword1" => $user['nickname'],
"keyword2" => $user['mobile'],
"keyword3" => date('Y年m月s日 H:i',time()),
"remark" => '请尽快处理!',
);
$url = 'http://community.t.brotop.cn/admininfo.php';
(new \app\common\controller\Api)->wxsendmessage('otlkQ0l4L3wsmz8dhDIbHJQVJnI8',$send_data,config('option.template')['examine'],$url);
if(!$result || !$res_user || !$res_log) {
Db::rollback();
} else {
... ...
... ... @@ -333,18 +333,18 @@ class Api
*/
public function wxsendmessage($open_id, $data, $templateId,$url)
{
// if (empty($open_id) || empty($data) || empty($templateId)) {
// return false;
// }
// $app = new Application(ConfigService::load());
// $notice = $app->notice;
// $userId = $open_id;
// $userService = $app->user;
// $user = $userService->get($open_id);
// // 判断是否关注公众号
// if($user->subscribe == 1) {
// $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
// }
if (empty($open_id) || empty($data) || empty($templateId)) {
return false;
}
$app = new Application(ConfigService::load());
$notice = $app->notice;
$userId = $open_id;
$userService = $app->user;
$user = $userService->get($open_id);
// 判断是否关注公众号
if($user->subscribe == 1) {
$notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
}
return true;
}
}
... ...