PHP Laravel框架 微信模板消息发送

编程入门 行业动态 更新时间:2024-10-26 04:22:25

PHP Laravel<a href=https://www.elefans.com/category/jswz/34/1770644.html style=框架 微信模板消息发送"/>

PHP Laravel框架 微信模板消息发送

laravel框架 微信模板消息发送

    /*** 发送模板消息*/public function add(Request $request,$id){$house_data = House::find($id);$phone = $request->input('phone','');$template=array('touser'=>'', //接收消息模版用户的openid'template_id'=>"", //在公众号下配置的模板id'url'=>"", //点击模板消息会跳转的链接'topcolor'=>"#7B68EE",'data'=>array(//'first'=>array('value'=>urlencode("微信模版消息发送测试"),'color'=>"#FF0000"),'keyword1'=>array('value'=>$house_data->title,'color'=>'#FF0000'), //keyword需要与配置的模板消息对应'keyword2'=>array('value'=>$request->btn,'color'=>'#FF0000'),'keyword3'=>array('value'=>$house_data->site,'color'=>'#FF0000')));$token = session("access_token_mp");if($token){return $token;}$url = "=client_credential&appid=你的aphid&secret=公众号的secret";$res = $this->curl_post($url);$td = json_decode($res, true);if($td['access_token']){$access_token = session("access_token_mp", $td['access_token'], $td['expires_in'] - 120);//获取微信公众平台tokensession(['weixin_token'=>$access_token]);$json_template=json_encode($template);$url="=".$access_token;$res=$this->curl_post($url,urldecode($json_template));//   dd($res);echo '<script>alert("微信模版消息发送成功");location="'.$_SERVER['HTTP_REFERER'].'"</script>';
//                    return $td['access_token'];}else{return false;}exit;}

下面展示一些 内联代码片

    /*** @param $url* @param array $data* @return mixed* curl请求*/function curl_post($url , $data=array()){$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);// POST数据curl_setopt($ch, CURLOPT_POST, 1);// 把post的变量加上curl_setopt($ch, CURLOPT_POSTFIELDS, $data);$output = curl_exec($ch);curl_close($ch);return $output;}

更多推荐

PHP Laravel框架 微信模板消息发送

本文发布于:2023-07-28 17:14:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1260052.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框架   模板   消息   PHP   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!