LARAVEL 消息模板推送

 

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,微信公众号的一些后台设置

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值