1.首先用compose安装
composer require overtrue/wechat
/**
* 发送模板消息
* @param $event
*/
public function MessagePush(Request $request)
{
$request->only(['sMessageInfo', 'sIphone']);
$content=$request['sMessageInfo'];
$str=$request['sIphone'];
$phone = explode(',',$str);
// $this->token = session('token');
// APPid
$appId = 'wxa3b2eff77af0d6eb';
// 密钥
$secret = 'f3dcdeffdee708e6e873e1a9f2e4c46a';
$notice = new Notice($appId, $secret);
// 模板ID
$templateId = 'Q4Pv0c3LNHhpAfZWytrrXXkxbCBtVR4asiaxD7Z14n4';
// 跳转链接
$url = 'http://' . $_SERVER['HTTP_HOST'].'/home/report' ;
// 字体颜色
$color = '#FF0000';
// 推送时间
$d_time = date('Y-m-d ', time()) . ' ' . '10:00:00';
// 推送内容
$data = array(
"time" => $d_time,
"cost" => "医云康",
"dispalyCount" =>'医云康2' ,
"clickCount" => "$content",
);
// 将推送消息保存导数据库推送到页面内
foreach ($phone as $ke=>$val){
$res=UserModel::where('sPhone',$val)->get()->toarray();
foreach ($res as $k=>$v){
// 用户的openID
$userId=$v['openid'];
$da['openid']=$userId;
$da['content']=$content;
$da['phone']=$val;
$da['time']=date("Y-m-d",time());
BiaoModel::create($da);
// 进行推送
$notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
}
}
// $userId=$openid ;
}
2,微信公众号的一些后台设置